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