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_RTTHREAD_H__ 15 #define __JFFS2_OS_RTTHREAD_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 "os_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 #define CYGPKG_FILEIO_DIRENT_DTYPE 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[NAME_MAX+1]; 57 }; 58 59 #include <string.h> 60 61 #include <cyg/fileio/fileio.h> //prife 62 63 //#include <cyg/hal/drv_api.h> 64 //#include <cyg/infra/diag.h> 65 66 //#include <cyg/io/flash.h> 67 68 #include <linux/types.h> 69 #include <linux/list.h> 70 #include <asm/bug.h> 71 72 //#define printf diag_printf //prife 73 74 struct _inode; 75 struct super_block; 76 77 struct iovec { 78 void *iov_base; 79 ssize_t iov_len; 80 }; 81 82 static inline unsigned int full_name_hash(const unsigned char * name, unsigned int len) { 83 84 unsigned hash = 0; 85 while (len--) { 86 hash = (hash << 4) | (hash >> 28); 87 hash ^= *(name++); 88 } 89 return hash; 90 } 91 92 #ifdef CYGOPT_FS_JFFS2_WRITE 93 #define jffs2_is_readonly(c) (0) 94 #else 95 #define jffs2_is_readonly(c) (1) 96 #endif 97 98 /* NAND flash not currently supported on eCos */ 99 #define jffs2_can_mark_obsolete(c) (1) 100 101 #define JFFS2_INODE_INFO(i) (&(i)->jffs2_i) 102 #define OFNI_EDONI_2SFFJ(f) ((struct _inode *) ( ((char *)f) - ((char *)(&((struct _inode *)NULL)->jffs2_i)) ) ) 103 104 #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size) 105 #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode) 106 #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid) 107 #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid) 108 #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime) 109 #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime) 110 #define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime) 111 112 /* FIXME: eCos doesn't hav a concept of device major/minor numbers */ 113 #define JFFS2_F_I_RDEV_MIN(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)&0xff) 114 #define JFFS2_F_I_RDEV_MAJ(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)>>8) 115 116 #define get_seconds jffs2_get_timestamp 117 118 struct _inode { 119 cyg_uint32 i_ino; 120 121 int i_count; 122 mode_t i_mode; 123 nlink_t i_nlink; // Could we dispense with this? 124 uid_t i_uid; 125 gid_t i_gid; 126 time_t i_atime; 127 time_t i_mtime; 128 time_t i_ctime; 129 // union { 130 unsigned short i_rdev; // For devices only 131 struct _inode * i_parent; // For directories only 132 off_t i_size; // For files only 133 // }; 134 struct super_block * i_sb; 135 136 struct jffs2_inode_info jffs2_i; 137 138 struct _inode * i_cache_prev; // We need doubly-linked? 139 struct _inode * i_cache_next; 140 }; 141 142 #define JFFS2_SB_INFO(sb) (&(sb)->jffs2_sb) 143 #define OFNI_BS_2SFFJ(c) ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->jffs2_sb)) ) ) 144 145 struct super_block { 146 struct jffs2_sb_info jffs2_sb; 147 struct _inode * s_root; 148 unsigned long s_mount_count; 149 cyg_io_handle_t s_dev; 150 151 //#ifdef CYGOPT_FS_JFFS2_GCTHREAD 152 // cyg_mutex_t s_lock; // Lock the inode cache 153 // cyg_flag_t s_gc_thread_flags; // Communication with the gcthread 154 // cyg_handle_t s_gc_thread_handle; 155 // cyg_thread s_gc_thread; 156 //#if (CYGNUM_JFFS2_GC_THREAD_STACK_SIZE >= CYGNUM_HAL_STACK_SIZE_MINIMUM) 157 // char s_gc_thread_stack[CYGNUM_JFFS2_GC_THREAD_STACK_SIZE]; 158 //#else 159 // char s_gc_thread_stack[CYGNUM_HAL_STACK_SIZE_MINIMUM]; 160 //#endif 161 // cyg_mtab_entry *mte; 162 //#endif 163 164 #ifdef CYGOPT_FS_JFFS2_GCTHREAD 165 struct rt_mutex s_lock; // Lock the inode cache 166 struct rt_event s_gc_thread_flags; // Communication with the gcthread 167 //void (*s_gc_thread_handle)(void *parameter); 168 struct rt_thread s_gc_thread; 169 //#if (CYGNUM_JFFS2_GC_THREAD_STACK_SIZE >= CYGNUM_HAL_STACK_SIZE_MINIMUM) 170 // char s_gc_thread_stack[CYGNUM_JFFS2_GC_THREAD_STACK_SIZE]; 171 //#else 172 // char s_gc_thread_stack[CYGNUM_HAL_STACK_SIZE_MINIMUM]; 173 //#endif 174 #define CYGNUM_JFFS2_GC_THREAD_STACK_SIZE (1024*4) 175 char s_gc_thread_stack[CYGNUM_JFFS2_GC_THREAD_STACK_SIZE]; 176 177 cyg_mtab_entry *mte; 178 #endif 179 180 }; 181 182 #define sleep_on_spinunlock(wq, sl) spin_unlock(sl) 183 #define EBADFD 32767 184 185 /* background.c */ 186 #ifdef CYGOPT_FS_JFFS2_GCTHREAD 187 void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c); 188 void jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c); 189 void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c); 190 #else 191 static inline void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c) 192 { 193 /* We don't have a GC thread in eCos (yet) */ 194 } 195 #endif 196 197 /* fs-ecos.c */ 198 struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct jffs2_raw_inode *ri); 199 struct _inode *jffs2_iget(struct super_block *sb, cyg_uint32 ino); 200 void jffs2_iput(struct _inode * i); 201 void jffs2_gc_release_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f); 202 struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, int inum, int nlink); 203 unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 204 unsigned long offset, unsigned long *priv); 205 void jffs2_gc_release_page(struct jffs2_sb_info *c, unsigned char *pg, unsigned long *priv); 206 207 /* Avoid polluting eCos namespace with names not starting in jffs2_ */ 208 #define os_to_jffs2_mode(x) jffs2_from_os_mode(x) 209 uint32_t jffs2_from_os_mode(uint32_t osmode); 210 uint32_t jffs2_to_os_mode (uint32_t jmode); 211 212 213 /* flashio.c */ 214 int jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset, 215 const size_t size, size_t * return_size, unsigned char * write_buffer); 216 int jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset, 217 const size_t size, size_t * return_size, unsigned char * read_buffer); 218 int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs, 219 unsigned long count, loff_t to, size_t *retlen); 220 int jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 221 222 // dir-ecos.c 223 struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *name, int namelen); 224 int jffs2_create(struct _inode *dir_i, const unsigned char *d_name, int mode, struct _inode **new_i); 225 int jffs2_mkdir (struct _inode *dir_i, const unsigned char *d_name, int mode); 226 int jffs2_link (struct _inode *old_d_inode, struct _inode *dir_i, const unsigned char *d_name); 227 int jffs2_unlink(struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name); 228 int jffs2_rmdir (struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name); 229 int jffs2_rename (struct _inode *old_dir_i, struct _inode *d_inode, const unsigned char *old_d_name, 230 struct _inode *new_dir_i, const unsigned char *new_d_name); 231 232 /* erase.c */ 233 static inline void jffs2_erase_pending_trigger(struct jffs2_sb_info *c) 234 { } 235 236 #ifndef CONFIG_JFFS2_FS_WRITEBUFFER 237 #define SECTOR_ADDR(x) ( ((unsigned long)(x) & ~(c->sector_size-1)) ) 238 #define jffs2_can_mark_obsolete(c) (1) 239 #define jffs2_cleanmarker_oob(c) (0) 240 #define jffs2_write_nand_cleanmarker(c,jeb) (-EIO) 241 242 #define jffs2_flush_wbuf_pad(c) (c=c) 243 #define jffs2_flush_wbuf_gc(c, i) ({ (void)(c), (void) i, 0; }) 244 #define jffs2_nand_read_failcnt(c,jeb) do { ; } while(0) 245 #define jffs2_write_nand_badblock(c,jeb,p) (0) 246 #define jffs2_flash_setup(c) (0) 247 #define jffs2_nand_flash_cleanup(c) do {} while(0) 248 #define jffs2_wbuf_dirty(c) (0) 249 #define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e) 250 #define jffs2_wbuf_timeout NULL 251 #define jffs2_wbuf_process NULL 252 #define jffs2_nor_ecc(c) (0) 253 #else 254 #error no nand yet 255 #endif 256 257 #ifndef BUG_ON 258 #define BUG_ON(x) do { if (unlikely(x)) BUG(); } while(0) 259 #endif 260 261 #define __init 262 263 #endif /* __JFFS2_OS_ECOS_H__ */ 264