]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/fs/jffs2/v2_0/src/os-ecos.h
Initial revision
[karo-tx-redboot.git] / packages / fs / jffs2 / v2_0 / src / os-ecos.h
1 /*
2  * JFFS2 -- Journalling Flash File System, Version 2.
3  *
4  * Copyright (C) 2002-2003 Red Hat, Inc.
5  *
6  * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
7  *
8  * For licensing information, see the file 'LICENCE' in this directory.
9  *
10  * $Id$
11  *
12  */
13
14 #ifndef __JFFS2_OS_ECOS_H__
15 #define __JFFS2_OS_ECOS_H__
16
17 #include <pkgconf/fs_jffs2.h>
18 #include <cyg/io/io.h>
19 #include <sys/types.h>
20 #include <asm/atomic.h>
21 #include <linux/stat.h>
22 #include <linux/compiler.h>
23
24 #include <pkgconf/system.h>
25 #include <pkgconf/hal.h>
26 #include <pkgconf/io_fileio.h>
27
28 #include <cyg/infra/cyg_trac.h>        // tracing macros
29 #include <cyg/infra/cyg_ass.h>         // assertion macros
30
31 #include <unistd.h>
32 #include <sys/types.h>
33 #include <fcntl.h>
34 #include <sys/stat.h>
35 #include <errno.h>
36 #include <dirent.h>
37
38 #include <stdlib.h>
39 #include <string.h>
40
41 #include <cyg/fileio/fileio.h>
42
43 #include <cyg/hal/drv_api.h>
44 #include <cyg/infra/diag.h>
45
46 #include <cyg/io/flash.h>
47
48 #include <linux/types.h>
49 #include <linux/list.h>
50 #include <asm/bug.h>
51
52 #define printf diag_printf
53
54 struct _inode;
55 struct super_block;
56
57 struct iovec {
58         void *iov_base;
59         ssize_t iov_len; 
60 };
61
62 static inline unsigned int full_name_hash(const unsigned char * name, unsigned int len) {
63
64         unsigned hash = 0;
65         while (len--) {
66                 hash = (hash << 4) | (hash >> 28);
67                 hash ^= *(name++);
68         }
69         return hash;
70 }
71
72 #ifdef CYGOPT_FS_JFFS2_WRITE
73 #define jffs2_is_readonly(c) (0)
74 #else
75 #define jffs2_is_readonly(c) (1)
76 #endif
77
78 /* NAND flash not currently supported on eCos */
79 #define jffs2_can_mark_obsolete(c) (1)
80
81 #define JFFS2_INODE_INFO(i) (&(i)->jffs2_i)
82 #define OFNI_EDONI_2SFFJ(f)  ((struct _inode *) ( ((char *)f) - ((char *)(&((struct _inode *)NULL)->jffs2_i)) ) )
83  
84 #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size)
85 #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
86 #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid)
87 #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid)
88 #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime)
89 #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime)
90 #define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime)
91
92 /* FIXME: eCos doesn't hav a concept of device major/minor numbers */
93 #define JFFS2_F_I_RDEV_MIN(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)&0xff)
94 #define JFFS2_F_I_RDEV_MAJ(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)>>8)
95
96 #define get_seconds cyg_timestamp
97
98 struct _inode {
99         cyg_uint32              i_ino;
100
101         int                     i_count;
102         mode_t                  i_mode;
103         nlink_t                 i_nlink; // Could we dispense with this?
104         uid_t                   i_uid;
105         gid_t                   i_gid;
106         time_t                  i_atime;
107         time_t                  i_mtime;
108         time_t                  i_ctime;
109 //      union {
110                 unsigned short  i_rdev; // For devices only
111                 struct _inode * i_parent; // For directories only
112                 off_t           i_size; // For files only
113 //      };
114         struct super_block *    i_sb;
115
116         struct jffs2_inode_info jffs2_i;
117
118         struct _inode *         i_cache_prev; // We need doubly-linked?
119         struct _inode *         i_cache_next;
120 };
121
122 #define JFFS2_SB_INFO(sb) (&(sb)->jffs2_sb)
123 #define OFNI_BS_2SFFJ(c)  ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->jffs2_sb)) ) )
124
125 struct super_block {
126         struct jffs2_sb_info    jffs2_sb;
127         struct _inode *         s_root;
128         unsigned long           s_mount_count;
129         cyg_io_handle_t         s_dev;
130
131 #ifdef CYGOPT_FS_JFFS2_GCTHREAD
132         cyg_mutex_t s_lock;             // Lock the inode cache
133         cyg_flag_t  s_gc_thread_flags;  // Communication with the gcthread
134         cyg_handle_t s_gc_thread_handle; 
135         cyg_thread s_gc_thread;
136 #if (CYGNUM_JFFS2_GC_THREAD_STACK_SIZE >= CYGNUM_HAL_STACK_SIZE_MINIMUM)
137         char s_gc_thread_stack[CYGNUM_JFFS2_GC_THREAD_STACK_SIZE];
138 #else
139         char s_gc_thread_stack[CYGNUM_HAL_STACK_SIZE_MINIMUM];
140 #endif
141        cyg_mtab_entry *mte;
142 #endif
143 };
144
145 #define sleep_on_spinunlock(wq, sl) spin_unlock(sl)
146 #define EBADFD 32767
147
148 /* background.c */
149 #ifdef CYGOPT_FS_JFFS2_GCTHREAD
150 void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c);
151 void jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
152 void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);
153 #else
154 static inline void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c)
155 {
156         /* We don't have a GC thread in eCos (yet) */
157 }
158 #endif
159
160 /* fs-ecos.c */
161 struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct jffs2_raw_inode *ri);
162 struct _inode *jffs2_iget(struct super_block *sb, cyg_uint32 ino);
163 void jffs2_iput(struct _inode * i);
164 void jffs2_gc_release_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f);
165 struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, int inum, int nlink);
166 unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 
167                                    unsigned long offset, unsigned long *priv);
168 void jffs2_gc_release_page(struct jffs2_sb_info *c, unsigned char *pg, unsigned long *priv);
169
170 /* Avoid polluting eCos namespace with names not starting in jffs2_ */
171 #define os_to_jffs2_mode(x) jffs2_from_os_mode(x)
172 uint32_t jffs2_from_os_mode(uint32_t osmode);
173 uint32_t jffs2_to_os_mode (uint32_t jmode);
174
175
176 /* flashio.c */
177 cyg_bool jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset,
178                           const size_t size, size_t * return_size, unsigned char * write_buffer);
179 cyg_bool jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset,
180                            const size_t size, size_t * return_size, unsigned char * read_buffer);
181 int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs,
182                               unsigned long count, loff_t to, size_t *retlen);
183 cyg_bool jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
184
185 // dir-ecos.c
186 struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *name, int namelen);
187 int jffs2_create(struct _inode *dir_i, const unsigned char *d_name, int mode, struct _inode **new_i);
188 int jffs2_mkdir (struct _inode *dir_i, const unsigned char *d_name, int mode);
189 int jffs2_link (struct _inode *old_d_inode, struct _inode *dir_i, const unsigned char *d_name);
190 int jffs2_unlink(struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name);
191 int jffs2_rmdir (struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name);
192 int jffs2_rename (struct _inode *old_dir_i, struct _inode *d_inode, const unsigned char *old_d_name,
193                   struct _inode *new_dir_i, const unsigned char *new_d_name);
194
195 /* erase.c */
196 static inline void jffs2_erase_pending_trigger(struct jffs2_sb_info *c)
197 { }
198
199 #ifndef CONFIG_JFFS2_FS_WRITEBUFFER
200 #define SECTOR_ADDR(x) ( ((unsigned long)(x) & ~(c->sector_size-1)) )
201 #define jffs2_can_mark_obsolete(c) (1)
202 #define jffs2_cleanmarker_oob(c) (0)
203 #define jffs2_write_nand_cleanmarker(c,jeb) (-EIO)
204
205 #define jffs2_flush_wbuf_pad(c) (c=c)
206 #define jffs2_flush_wbuf_gc(c, i) ({ (void)(c), (void) i, 0; })
207 #define jffs2_nand_read_failcnt(c,jeb) do { ; } while(0)
208 #define jffs2_write_nand_badblock(c,jeb,p) (0)
209 #define jffs2_flash_setup(c) (0)
210 #define jffs2_nand_flash_cleanup(c) do {} while(0)
211 #define jffs2_wbuf_dirty(c) (0)
212 #define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e)
213 #define jffs2_wbuf_timeout NULL
214 #define jffs2_wbuf_process NULL
215 #define jffs2_nor_ecc(c) (0)
216 #else
217 #error no nand yet
218 #endif
219
220 #ifndef BUG_ON
221 #define BUG_ON(x) do { if (unlikely(x)) BUG(); } while(0)
222 #endif
223
224 #define __init
225
226 #endif /* __JFFS2_OS_ECOS_H__ */