os-linux.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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@infradead.org>
  7. *
  8. * For licensing information, see the file 'LICENCE' in this directory.
  9. *
  10. * $Id: os-linux.h,v 1.51 2004/11/16 20:36:11 dwmw2 Exp $
  11. *
  12. */
  13. #ifndef __JFFS2_OS_LINUX_H__
  14. #define __JFFS2_OS_LINUX_H__
  15. #include <linux/version.h>
  16. /* JFFS2 uses Linux mode bits natively -- no need for conversion */
  17. #define os_to_jffs2_mode(x) (x)
  18. #define jffs2_to_os_mode(x) (x)
  19. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,73)
  20. #define kstatfs statfs
  21. #endif
  22. struct kstatfs;
  23. struct kvec;
  24. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,2)
  25. #define JFFS2_INODE_INFO(i) (list_entry(i, struct jffs2_inode_info, vfs_inode))
  26. #define OFNI_EDONI_2SFFJ(f) (&(f)->vfs_inode)
  27. #define JFFS2_SB_INFO(sb) (sb->s_fs_info)
  28. #define OFNI_BS_2SFFJ(c) ((struct super_block *)c->os_priv)
  29. #elif defined(JFFS2_OUT_OF_KERNEL)
  30. #define JFFS2_INODE_INFO(i) ((struct jffs2_inode_info *) &(i)->u)
  31. #define OFNI_EDONI_2SFFJ(f) ((struct inode *) ( ((char *)f) - ((char *)(&((struct inode *)NULL)->u)) ) )
  32. #define JFFS2_SB_INFO(sb) ((struct jffs2_sb_info *) &(sb)->u)
  33. #define OFNI_BS_2SFFJ(c) ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->u)) ) )
  34. #else
  35. #define JFFS2_INODE_INFO(i) (&i->u.jffs2_i)
  36. #define OFNI_EDONI_2SFFJ(f) ((struct inode *) ( ((char *)f) - ((char *)(&((struct inode *)NULL)->u)) ) )
  37. #define JFFS2_SB_INFO(sb) (&sb->u.jffs2_sb)
  38. #define OFNI_BS_2SFFJ(c) ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->u)) ) )
  39. #endif
  40. #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size)
  41. #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
  42. #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid)
  43. #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid)
  44. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,1)
  45. #define JFFS2_F_I_RDEV_MIN(f) (iminor(OFNI_EDONI_2SFFJ(f)))
  46. #define JFFS2_F_I_RDEV_MAJ(f) (imajor(OFNI_EDONI_2SFFJ(f)))
  47. #else
  48. #define JFFS2_F_I_RDEV_MIN(f) (MINOR(to_kdev_t(OFNI_EDONI_2SFFJ(f)->i_rdev)))
  49. #define JFFS2_F_I_RDEV_MAJ(f) (MAJOR(to_kdev_t(OFNI_EDONI_2SFFJ(f)->i_rdev)))
  50. #endif
  51. /* Urgh. The things we do to keep the 2.4 build working */
  52. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,47)
  53. #define ITIME(sec) ((struct timespec){sec, 0})
  54. #define I_SEC(tv) ((tv).tv_sec)
  55. #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime.tv_sec)
  56. #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime.tv_sec)
  57. #define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime.tv_sec)
  58. #else
  59. #define ITIME(x) (x)
  60. #define I_SEC(x) (x)
  61. #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime)
  62. #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime)
  63. #define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime)
  64. #endif
  65. #define sleep_on_spinunlock(wq, s) \
  66. do { \
  67. DECLARE_WAITQUEUE(__wait, current); \
  68. add_wait_queue((wq), &__wait); \
  69. set_current_state(TASK_UNINTERRUPTIBLE); \
  70. spin_unlock(s); \
  71. schedule(); \
  72. remove_wait_queue((wq), &__wait); \
  73. } while(0)
  74. static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
  75. {
  76. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,2)
  77. f->highest_version = 0;
  78. f->fragtree = RB_ROOT;
  79. f->metadata = NULL;
  80. f->dents = NULL;
  81. f->flags = 0;
  82. f->usercompr = 0;
  83. #else
  84. memset(f, 0, sizeof(*f));
  85. init_MUTEX_LOCKED(&f->sem);
  86. #endif
  87. }
  88. #define jffs2_is_readonly(c) (OFNI_BS_2SFFJ(c)->s_flags & MS_RDONLY)
  89. #if (!defined CONFIG_JFFS2_FS_NAND && !defined CONFIG_JFFS2_FS_NOR_ECC)
  90. #define jffs2_can_mark_obsolete(c) (1)
  91. #define jffs2_cleanmarker_oob(c) (0)
  92. #define jffs2_write_nand_cleanmarker(c,jeb) (-EIO)
  93. #define jffs2_flash_write(c, ofs, len, retlen, buf) ((c)->mtd->write((c)->mtd, ofs, len, retlen, buf))
  94. #define jffs2_flash_read(c, ofs, len, retlen, buf) ((c)->mtd->read((c)->mtd, ofs, len, retlen, buf))
  95. #define jffs2_flush_wbuf_pad(c) ({ (void)(c), 0; })
  96. #define jffs2_flush_wbuf_gc(c, i) ({ (void)(c), (void) i, 0; })
  97. #define jffs2_write_nand_badblock(c,jeb,bad_offset) (1)
  98. #define jffs2_nand_flash_setup(c) (0)
  99. #define jffs2_nand_flash_cleanup(c) do {} while(0)
  100. #define jffs2_wbuf_dirty(c) (0)
  101. #define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e)
  102. #define jffs2_wbuf_timeout NULL
  103. #define jffs2_wbuf_process NULL
  104. #define jffs2_nor_ecc(c) (0)
  105. #define jffs2_nor_ecc_flash_setup(c) (0)
  106. #define jffs2_nor_ecc_flash_cleanup(c) do {} while (0)
  107. #else /* NAND and/or ECC'd NOR support present */
  108. #define jffs2_can_mark_obsolete(c) ((c->mtd->type == MTD_NORFLASH && !(c->mtd->flags & MTD_ECC)) || c->mtd->type == MTD_RAM)
  109. #define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH)
  110. #define jffs2_flash_write_oob(c, ofs, len, retlen, buf) ((c)->mtd->write_oob((c)->mtd, ofs, len, retlen, buf))
  111. #define jffs2_flash_read_oob(c, ofs, len, retlen, buf) ((c)->mtd->read_oob((c)->mtd, ofs, len, retlen, buf))
  112. #define jffs2_wbuf_dirty(c) (!!(c)->wbuf_len)
  113. /* wbuf.c */
  114. int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino);
  115. int jffs2_flash_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, const u_char *buf);
  116. int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, u_char *buf);
  117. int jffs2_check_oob_empty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,int mode);
  118. int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
  119. int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
  120. int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset);
  121. void jffs2_wbuf_timeout(unsigned long data);
  122. void jffs2_wbuf_process(void *data);
  123. int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino);
  124. int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c);
  125. int jffs2_nand_flash_setup(struct jffs2_sb_info *c);
  126. void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c);
  127. #ifdef CONFIG_JFFS2_FS_NOR_ECC
  128. #define jffs2_nor_ecc(c) (c->mtd->type == MTD_NORFLASH && (c->mtd->flags & MTD_ECC))
  129. int jffs2_nor_ecc_flash_setup(struct jffs2_sb_info *c);
  130. void jffs2_nor_ecc_flash_cleanup(struct jffs2_sb_info *c);
  131. #else
  132. #define jffs2_nor_ecc(c) (0)
  133. #define jffs2_nor_ecc_flash_setup(c) (0)
  134. #define jffs2_nor_ecc_flash_cleanup(c) do {} while (0)
  135. #endif /* NOR ECC */
  136. #endif /* NAND */
  137. /* erase.c */
  138. static inline void jffs2_erase_pending_trigger(struct jffs2_sb_info *c)
  139. {
  140. OFNI_BS_2SFFJ(c)->s_dirt = 1;
  141. }
  142. /* background.c */
  143. int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
  144. void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);
  145. void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c);
  146. /* dir.c */
  147. extern struct file_operations jffs2_dir_operations;
  148. extern struct inode_operations jffs2_dir_inode_operations;
  149. /* file.c */
  150. extern struct file_operations jffs2_file_operations;
  151. extern struct inode_operations jffs2_file_inode_operations;
  152. extern struct address_space_operations jffs2_file_address_operations;
  153. int jffs2_fsync(struct file *, struct dentry *, int);
  154. int jffs2_do_readpage_unlock (struct inode *inode, struct page *pg);
  155. /* ioctl.c */
  156. int jffs2_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
  157. /* symlink.c */
  158. extern struct inode_operations jffs2_symlink_inode_operations;
  159. /* fs.c */
  160. int jffs2_setattr (struct dentry *, struct iattr *);
  161. void jffs2_read_inode (struct inode *);
  162. void jffs2_clear_inode (struct inode *);
  163. void jffs2_dirty_inode(struct inode *inode);
  164. struct inode *jffs2_new_inode (struct inode *dir_i, int mode,
  165. struct jffs2_raw_inode *ri);
  166. int jffs2_statfs (struct super_block *, struct kstatfs *);
  167. void jffs2_write_super (struct super_block *);
  168. int jffs2_remount_fs (struct super_block *, int *, char *);
  169. int jffs2_do_fill_super(struct super_block *sb, void *data, int silent);
  170. void jffs2_gc_release_inode(struct jffs2_sb_info *c,
  171. struct jffs2_inode_info *f);
  172. struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
  173. int inum, int nlink);
  174. unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c,
  175. struct jffs2_inode_info *f,
  176. unsigned long offset,
  177. unsigned long *priv);
  178. void jffs2_gc_release_page(struct jffs2_sb_info *c,
  179. unsigned char *pg,
  180. unsigned long *priv);
  181. void jffs2_flash_cleanup(struct jffs2_sb_info *c);
  182. /* writev.c */
  183. int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
  184. unsigned long count, loff_t to, size_t *retlen);
  185. #endif /* __JFFS2_OS_LINUX_H__ */