os-rtthread.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 <dwmw2@cambridge.redhat.com>
  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. #ifndef __JFFS2_OS_RTTHREAD_H__
  14. #define __JFFS2_OS_RTTHREAD_H__
  15. #include "jffs2_config.h"
  16. #include <rtthread.h>
  17. #define printf rt_kprintf
  18. //#include <pkgconf/fs_jffs2.h>
  19. //#include <cyg/io/io.h>
  20. //#include <sys/types.h>
  21. #include <asm/atomic.h>
  22. #include <linux/stat.h>
  23. #include <linux/compiler.h>
  24. //#include <pkgconf/system.h>
  25. //#include <pkgconf/hal.h>
  26. //#include <pkgconf/io_fileio.h>
  27. //#include <cyg/infra/cyg_trac.h> // tracing macros
  28. //#include <cyg/infra/cyg_ass.h> // assertion macros
  29. //#if defined (__GNUC__)
  30. //#include <unistd.h>
  31. //#elif defined (MSVC)
  32. //#else
  33. //#endif
  34. #include "os_sys_stat.h"//#include <sys/types.h>
  35. //#include <fcntl.h>
  36. //#include <sys/stat.h>
  37. //#include <errno.h> //fixme
  38. //#include <dirent.h>
  39. #define CYGPKG_FILEIO_DIRENT_DTYPE
  40. struct dirent
  41. {
  42. #ifdef CYGPKG_FILEIO_DIRENT_DTYPE
  43. mode_t d_type; // Only supported with FATFS, RAMFS, ROMFS,
  44. // and JFFS2.
  45. // d_type is not part of POSIX so
  46. // should be used with caution.
  47. #endif
  48. char d_name[NAME_MAX+1];
  49. };
  50. #include <string.h>
  51. #include <cyg/fileio/fileio.h> //prife
  52. //#include <cyg/hal/drv_api.h>
  53. //#include <cyg/infra/diag.h>
  54. //#include <cyg/io/flash.h>
  55. #include <linux/types.h>
  56. #include <linux/list.h>
  57. #include <asm/bug.h>
  58. //#define printf diag_printf //prife
  59. struct _inode;
  60. struct super_block;
  61. struct iovec {
  62. void *iov_base;
  63. ssize_t iov_len;
  64. };
  65. static inline unsigned int full_name_hash(const unsigned char * name, unsigned int len) {
  66. unsigned hash = 0;
  67. while (len--) {
  68. hash = (hash << 4) | (hash >> 28);
  69. hash ^= *(name++);
  70. }
  71. return hash;
  72. }
  73. #ifdef CYGOPT_FS_JFFS2_WRITE
  74. #define jffs2_is_readonly(c) (0)
  75. #else
  76. #define jffs2_is_readonly(c) (1)
  77. #endif
  78. /* NAND flash not currently supported on eCos */
  79. #define jffs2_can_mark_obsolete(c) (1)
  80. #define JFFS2_INODE_INFO(i) (&(i)->jffs2_i)
  81. #define OFNI_EDONI_2SFFJ(f) ((struct _inode *) ( ((char *)f) - ((char *)(&((struct _inode *)NULL)->jffs2_i)) ) )
  82. #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size)
  83. #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
  84. #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid)
  85. #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid)
  86. #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime)
  87. #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime)
  88. #define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime)
  89. /* FIXME: eCos doesn't hav a concept of device major/minor numbers */
  90. #define JFFS2_F_I_RDEV_MIN(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)&0xff)
  91. #define JFFS2_F_I_RDEV_MAJ(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)>>8)
  92. #define get_seconds jffs2_get_timestamp
  93. struct _inode {
  94. cyg_uint32 i_ino;
  95. int i_count;
  96. mode_t i_mode;
  97. nlink_t i_nlink; // Could we dispense with this?
  98. uid_t i_uid;
  99. gid_t i_gid;
  100. time_t i_atime;
  101. time_t i_mtime;
  102. time_t i_ctime;
  103. // union {
  104. unsigned short i_rdev; // For devices only
  105. struct _inode * i_parent; // For directories only
  106. off_t i_size; // For files only
  107. // };
  108. struct super_block * i_sb;
  109. struct jffs2_inode_info jffs2_i;
  110. struct _inode * i_cache_prev; // We need doubly-linked?
  111. struct _inode * i_cache_next;
  112. };
  113. #define JFFS2_SB_INFO(sb) (&(sb)->jffs2_sb)
  114. #define OFNI_BS_2SFFJ(c) ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->jffs2_sb)) ) )
  115. struct super_block {
  116. struct jffs2_sb_info jffs2_sb;
  117. struct _inode * s_root;
  118. unsigned long s_mount_count;
  119. cyg_io_handle_t s_dev;
  120. //#ifdef CYGOPT_FS_JFFS2_GCTHREAD
  121. // cyg_mutex_t s_lock; // Lock the inode cache
  122. // cyg_flag_t s_gc_thread_flags; // Communication with the gcthread
  123. // cyg_handle_t s_gc_thread_handle;
  124. // cyg_thread s_gc_thread;
  125. //#if (CYGNUM_JFFS2_GC_THREAD_STACK_SIZE >= CYGNUM_HAL_STACK_SIZE_MINIMUM)
  126. // char s_gc_thread_stack[CYGNUM_JFFS2_GC_THREAD_STACK_SIZE];
  127. //#else
  128. // char s_gc_thread_stack[CYGNUM_HAL_STACK_SIZE_MINIMUM];
  129. //#endif
  130. // cyg_mtab_entry *mte;
  131. //#endif
  132. #ifdef CYGOPT_FS_JFFS2_GCTHREAD
  133. struct rt_mutex s_lock; // Lock the inode cache
  134. struct rt_event s_gc_thread_flags; // Communication with the gcthread
  135. //void (*s_gc_thread_handle)(void *parameter);
  136. struct rt_thread s_gc_thread;
  137. //#if (CYGNUM_JFFS2_GC_THREAD_STACK_SIZE >= CYGNUM_HAL_STACK_SIZE_MINIMUM)
  138. // char s_gc_thread_stack[CYGNUM_JFFS2_GC_THREAD_STACK_SIZE];
  139. //#else
  140. // char s_gc_thread_stack[CYGNUM_HAL_STACK_SIZE_MINIMUM];
  141. //#endif
  142. #define CYGNUM_JFFS2_GC_THREAD_STACK_SIZE (1024*4)
  143. char s_gc_thread_stack[CYGNUM_JFFS2_GC_THREAD_STACK_SIZE];
  144. cyg_mtab_entry *mte;
  145. #endif
  146. };
  147. #define sleep_on_spinunlock(wq, sl) spin_unlock(sl)
  148. #define EBADFD 32767
  149. /* background.c */
  150. #ifdef CYGOPT_FS_JFFS2_GCTHREAD
  151. void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c);
  152. void jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
  153. void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);
  154. #else
  155. static inline void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c)
  156. {
  157. /* We don't have a GC thread in eCos (yet) */
  158. }
  159. #endif
  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. /* Avoid polluting eCos namespace with names not starting in jffs2_ */
  170. #define os_to_jffs2_mode(x) jffs2_from_os_mode(x)
  171. uint32_t jffs2_from_os_mode(uint32_t osmode);
  172. uint32_t jffs2_to_os_mode (uint32_t jmode);
  173. /* flashio.c */
  174. int jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset,
  175. const size_t size, size_t * return_size, unsigned char * write_buffer);
  176. int jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset,
  177. const size_t size, size_t * return_size, unsigned char * read_buffer);
  178. int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs,
  179. unsigned long count, loff_t to, size_t *retlen);
  180. int jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
  181. // dir-ecos.c
  182. struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *name, int namelen);
  183. int jffs2_create(struct _inode *dir_i, const unsigned char *d_name, int mode, struct _inode **new_i);
  184. int jffs2_mkdir (struct _inode *dir_i, const unsigned char *d_name, int mode);
  185. int jffs2_link (struct _inode *old_d_inode, struct _inode *dir_i, const unsigned char *d_name);
  186. int jffs2_unlink(struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name);
  187. int jffs2_rmdir (struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name);
  188. int jffs2_rename (struct _inode *old_dir_i, struct _inode *d_inode, const unsigned char *old_d_name,
  189. struct _inode *new_dir_i, const unsigned char *new_d_name);
  190. /* erase.c */
  191. static inline void jffs2_erase_pending_trigger(struct jffs2_sb_info *c)
  192. { }
  193. #ifndef CONFIG_JFFS2_FS_WRITEBUFFER
  194. #define SECTOR_ADDR(x) ( ((unsigned long)(x) & ~(c->sector_size-1)) )
  195. #define jffs2_can_mark_obsolete(c) (1)
  196. #define jffs2_cleanmarker_oob(c) (0)
  197. #define jffs2_write_nand_cleanmarker(c,jeb) (-EIO)
  198. #define jffs2_flush_wbuf_pad(c) (c=c)
  199. #define jffs2_flush_wbuf_gc(c, i) ({ (void)(c), (void) i, 0; })
  200. #define jffs2_nand_read_failcnt(c,jeb) do { ; } while(0)
  201. #define jffs2_write_nand_badblock(c,jeb,p) (0)
  202. #define jffs2_flash_setup(c) (0)
  203. #define jffs2_nand_flash_cleanup(c) do {} while(0)
  204. #define jffs2_wbuf_dirty(c) (0)
  205. #define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e)
  206. #define jffs2_wbuf_timeout NULL
  207. #define jffs2_wbuf_process NULL
  208. #define jffs2_nor_ecc(c) (0)
  209. #else
  210. #error no nand yet
  211. #endif
  212. #ifndef BUG_ON
  213. #define BUG_ON(x) do { if (unlikely(x)) BUG(); } while(0)
  214. #endif
  215. #define __init
  216. #endif /* __JFFS2_OS_ECOS_H__ */