1 /* 2 * JFFS2 -- Journalling Flash File System, Version 2. 3 * 4 * Copyright © 2001-2007 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 */ 11 12 #ifndef __JFFS2_OS_LINUX_H__ 13 #define __JFFS2_OS_LINUX_H__ 14 15 #include <dirent.h> 16 #include "fs/fs.h" 17 #include "jffs2.h" 18 #include "jffs2_fs_sb.h" 19 20 21 /* jffs2 debug output opion */ 22 #define CONFIG_JFFS2_FS_DEBUG 0 /* 1 or 2 */ 23 24 /* jffs2 gc thread section */ 25 #define JFFS2_GC_THREAD_PRIORITY 10 /* GC thread's priority */ 26 27 /* zlib section*/ 28 #define CONFIG_JFFS2_ZLIB 29 #define CONFIG_JFFS2_RTIME 30 #define CONFIG_JFFS2_RUBIN 31 32 /* JFFS2 uses Linux mode bits natively -- no need for conversion */ 33 #define os_to_jffs2_mode(x) (x) 34 #define jffs2_to_os_mode(x) (x) 35 36 #ifndef BUG_ON 37 #define BUG_ON(x) do {if (unlikely(x)) BUG();} while (0) 38 #endif 39 40 struct kstatfs; 41 struct kvec; 42 43 44 #define JFFS2_INODE_INFO(i) (&(i)->jffs2_i) 45 #define OFNI_EDONI_2SFFJ(f) \ 46 ((struct jffs2_inode *) (((char *)f) - ((char *)(&((struct jffs2_inode *)NULL)->jffs2_i)))) 47 48 #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size) 49 #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode) 50 #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid) 51 #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid) 52 #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime) 53 #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime) 54 #define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime) 55 56 #define ITIME(sec) ((struct timespec){sec, 0}) 57 #define I_SEC(tv) ((tv).tv_sec) 58 59 #define sleep_on_spinunlock(wq, sl) do {spin_unlock(sl); msleep(100);} while (0) 60 61 #define jffs2_is_readonly(c) (0) 62 63 #define SECTOR_ADDR(x) ( (((unsigned long)(x) / c->sector_size) * c->sector_size) ) 64 65 #ifndef CONFIG_JFFS2_FS_WRITEBUFFER 66 67 #ifdef CONFIG_JFFS2_SUMMARY 68 #define jffs2_can_mark_obsolete(c) (0) 69 #else 70 #define jffs2_can_mark_obsolete(c) (1) 71 #endif 72 73 #define jffs2_is_writebuffered(c) (0) 74 #define jffs2_cleanmarker_oob(c) (0) 75 #define jffs2_write_nand_cleanmarker(c,jeb) (-EIO) 76 77 #define jffs2_flash_write(c, ofs, len, retlen, buf) jffs2_flash_direct_write(c, ofs, len, retlen, buf) 78 #define jffs2_flash_read(c, ofs, len, retlen, buf) jffs2_flash_direct_read(c, ofs, len, retlen, buf) 79 #define jffs2_flush_wbuf_pad(c) (c=c) 80 #define jffs2_flush_wbuf_gc(c, i) ({ do{} while(0); (void)(c), (void) i, 0; }) 81 #define jffs2_write_nand_badblock(c,jeb,p) (0) 82 #define jffs2_nand_flash_setup(c) (0) 83 #define jffs2_nand_flash_cleanup(c) do {} while(0) 84 #define jffs2_wbuf_dirty(c) (0) 85 #define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e) 86 #define jffs2_wbuf_timeout NULL 87 #define jffs2_wbuf_process NULL 88 #define jffs2_dataflash(c) (0) 89 #define jffs2_dataflash_setup(c) (0) 90 #define jffs2_dataflash_cleanup(c) do {} while (0) 91 #define jffs2_nor_wbuf_flash(c) (0) 92 #define jffs2_nor_wbuf_flash_setup(c) (0) 93 #define jffs2_nor_wbuf_flash_cleanup(c) do {} while (0) 94 #define jffs2_ubivol(c) (0) 95 #define jffs2_ubivol_setup(c) (0) 96 #define jffs2_ubivol_cleanup(c) do {} while (0) 97 #define jffs2_dirty_trigger(c) do {} while (0) 98 99 #else /* NAND and/or ECC'd NOR support present */ 100 101 /* current not support */ 102 #define jffs2_is_writebuffered(c) (0) 103 104 #ifdef CONFIG_JFFS2_SUMMARY 105 #define jffs2_can_mark_obsolete(c) (0) 106 #else 107 #define jffs2_can_mark_obsolete(c) (c->mtd->flags & (MTD_BIT_WRITEABLE)) 108 #endif 109 110 #define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH) 111 112 #define jffs2_wbuf_dirty(c) (!!(c)->wbuf_len) 113 114 /* wbuf.c */ 115 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); 116 int jffs2_flash_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, const u_char *buf); 117 int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, u_char *buf); 118 int jffs2_check_oob_empty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,int mode); 119 int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 120 int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 121 int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset); 122 void jffs2_wbuf_timeout(unsigned long data); 123 void jffs2_wbuf_process(void *data); 124 int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino); 125 int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c); 126 int jffs2_nand_flash_setup(struct jffs2_sb_info *c); 127 void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c); 128 129 #define jffs2_dataflash(c) (c->mtd->type == MTD_DATAFLASH) 130 int jffs2_dataflash_setup(struct jffs2_sb_info *c); 131 void jffs2_dataflash_cleanup(struct jffs2_sb_info *c); 132 #define jffs2_ubivol(c) (c->mtd->type == MTD_UBIVOLUME) 133 int jffs2_ubivol_setup(struct jffs2_sb_info *c); 134 void jffs2_ubivol_cleanup(struct jffs2_sb_info *c); 135 136 #define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && ! (c->mtd->flags & MTD_BIT_WRITEABLE)) 137 int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c); 138 void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c); 139 void jffs2_dirty_trigger(struct jffs2_sb_info *c); 140 141 #endif /* WRITEBUFFER */ 142 143 /* background.c */ 144 void jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c); 145 void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c); 146 void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c); 147 148 /* dir.c */ 149 struct jffs2_inode *jffs2_lookup(struct jffs2_inode *dir_i, const unsigned char *name, int namelen); 150 int jffs2_create(struct jffs2_inode *dir_i, const unsigned char *d_name, int mode, struct jffs2_inode **new_i); 151 int jffs2_mkdir (struct jffs2_inode *dir_i, const unsigned char *d_name, int mode, struct jffs2_inode **new_i); 152 int jffs2_link (struct jffs2_inode *old_d_inode, struct jffs2_inode *dir_i, const unsigned char *d_name); 153 int jffs2_symlink(struct jffs2_inode *dir_i, struct jffs2_inode **d_inode, const unsigned char *d_name, const char *target); 154 int jffs2_unlink(struct jffs2_inode *dir_i, struct jffs2_inode *d_inode, const unsigned char *d_name); 155 int jffs2_rmdir (struct jffs2_inode *dir_i, struct jffs2_inode *d_inode, const unsigned char *d_name); 156 int jffs2_rename (struct jffs2_inode *old_dir_i, struct jffs2_inode *d_inode, const unsigned char *old_d_name, 157 struct jffs2_inode *new_dir_i, const unsigned char *new_d_name); 158 int jffs2_readdir(struct jffs2_inode *inode, off_t *offset, off_t *int_off, struct dirent *ent); 159 160 /* fs.c */ 161 int jffs2_setattr (struct jffs2_inode *inode, struct IATTR *attr); 162 struct jffs2_inode *jffs2_iget(struct super_block *sb, uint32_t ino); 163 int jffs2_iput(struct jffs2_inode * i); 164 struct jffs2_inode *jffs2_new_inode (struct jffs2_inode *dir_i, int mode, struct jffs2_raw_inode *ri); 165 166 void jffs2_gc_release_inode(struct jffs2_sb_info *c, 167 struct jffs2_inode_info *f); 168 struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, 169 int inum, int unlinked); 170 171 unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, 172 struct jffs2_inode_info *f, 173 unsigned long offset, 174 unsigned long *priv); 175 void jffs2_gc_release_page(struct jffs2_sb_info *c, 176 unsigned char *pg, 177 unsigned long *priv); 178 void jffs2_flash_cleanup(struct jffs2_sb_info *c); 179 180 int calculate_inocache_hashsize(uint32_t flash_size); 181 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 int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, 186 size_t *retlen, const u_char *buf); 187 int jffs2_flash_direct_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, 188 size_t *retlen, const char *buf); 189 190 /* super.c */ 191 int jffs2_fill_super(struct super_block *sb); 192 int jffs2_mount(int part_no, struct jffs2_inode **root_node, unsigned long mountflags); 193 int jffs2_umount(struct jffs2_inode *root_node); 194 195 #endif /* __JFFS2_OS_LINUX_H__ */ 196 197