Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * JFFS2 -- Journalling Flash File System, Version 2.
0003  *
0004  * Copyright © 2001-2007 Red Hat, Inc.
0005  *
0006  * Created by David Woodhouse <dwmw2@infradead.org>
0007  *
0008  * For licensing information, see the file 'LICENCE' in this directory.
0009  *
0010  */
0011 
0012 #ifndef __JFFS2_OS_LINUX_H__
0013 #define __JFFS2_OS_LINUX_H__
0014 
0015 /* JFFS2 uses Linux mode bits natively -- no need for conversion */
0016 #define os_to_jffs2_mode(x) (x)
0017 #define jffs2_to_os_mode(x) (x)
0018 
0019 struct kstatfs;
0020 struct kvec;
0021 
0022 #define JFFS2_INODE_INFO(i) (container_of(i, struct jffs2_inode_info, vfs_inode))
0023 #define OFNI_EDONI_2SFFJ(f)  (&(f)->vfs_inode)
0024 #define JFFS2_SB_INFO(sb) (sb->s_fs_info)
0025 #define OFNI_BS_2SFFJ(c)  ((struct super_block *)c->os_priv)
0026 
0027 
0028 #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size)
0029 #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
0030 #define JFFS2_F_I_UID(f) (i_uid_read(OFNI_EDONI_2SFFJ(f)))
0031 #define JFFS2_F_I_GID(f) (i_gid_read(OFNI_EDONI_2SFFJ(f)))
0032 #define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev)
0033 
0034 #define JFFS2_CLAMP_TIME(t) ((uint32_t)clamp_t(time64_t, (t), 0, U32_MAX))
0035 #define ITIME(sec) ((struct timespec64){sec, 0})
0036 #define JFFS2_NOW() JFFS2_CLAMP_TIME(ktime_get_real_seconds())
0037 #define I_SEC(tv) JFFS2_CLAMP_TIME((tv).tv_sec)
0038 #define JFFS2_F_I_CTIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_ctime)
0039 #define JFFS2_F_I_MTIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_mtime)
0040 #define JFFS2_F_I_ATIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_atime)
0041 #define sleep_on_spinunlock(wq, s)              \
0042     do {                            \
0043         DECLARE_WAITQUEUE(__wait, current);     \
0044         add_wait_queue((wq), &__wait);          \
0045         set_current_state(TASK_UNINTERRUPTIBLE);    \
0046         spin_unlock(s);                 \
0047         schedule();                 \
0048         remove_wait_queue((wq), &__wait);       \
0049     } while(0)
0050 
0051 static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
0052 {
0053     f->highest_version = 0;
0054     f->fragtree = RB_ROOT;
0055     f->metadata = NULL;
0056     f->dents = NULL;
0057     f->target = NULL;
0058     f->flags = 0;
0059     f->usercompr = 0;
0060 }
0061 
0062 
0063 #define jffs2_is_readonly(c) (OFNI_BS_2SFFJ(c)->s_flags & SB_RDONLY)
0064 
0065 #define SECTOR_ADDR(x) ( (((unsigned long)(x) / c->sector_size) * c->sector_size) )
0066 #ifndef CONFIG_JFFS2_FS_WRITEBUFFER
0067 
0068 
0069 #ifdef CONFIG_JFFS2_SUMMARY
0070 #define jffs2_can_mark_obsolete(c) (0)
0071 #else
0072 #define jffs2_can_mark_obsolete(c) (1)
0073 #endif
0074 
0075 #define jffs2_is_writebuffered(c) (0)
0076 #define jffs2_cleanmarker_oob(c) (0)
0077 #define jffs2_write_nand_cleanmarker(c,jeb) (-EIO)
0078 
0079 #define jffs2_flash_write(c, ofs, len, retlen, buf) jffs2_flash_direct_write(c, ofs, len, retlen, buf)
0080 #define jffs2_flash_read(c, ofs, len, retlen, buf) (mtd_read((c)->mtd, ofs, len, retlen, buf))
0081 #define jffs2_flush_wbuf_pad(c) ({ do{} while(0); (void)(c), 0; })
0082 #define jffs2_flush_wbuf_gc(c, i) ({ do{} while(0); (void)(c), (void) i, 0; })
0083 #define jffs2_write_nand_badblock(c,jeb,bad_offset) (1)
0084 #define jffs2_nand_flash_setup(c) (0)
0085 #define jffs2_nand_flash_cleanup(c) do {} while(0)
0086 #define jffs2_wbuf_dirty(c) (0)
0087 #define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e)
0088 #define jffs2_wbuf_timeout NULL
0089 #define jffs2_wbuf_process NULL
0090 #define jffs2_dataflash(c) (0)
0091 #define jffs2_dataflash_setup(c) (0)
0092 #define jffs2_dataflash_cleanup(c) do {} while (0)
0093 #define jffs2_nor_wbuf_flash(c) (0)
0094 #define jffs2_nor_wbuf_flash_setup(c) (0)
0095 #define jffs2_nor_wbuf_flash_cleanup(c) do {} while (0)
0096 #define jffs2_ubivol(c) (0)
0097 #define jffs2_ubivol_setup(c) (0)
0098 #define jffs2_ubivol_cleanup(c) do {} while (0)
0099 #define jffs2_dirty_trigger(c) do {} while (0)
0100 
0101 #else /* NAND and/or ECC'd NOR support present */
0102 
0103 #define jffs2_is_writebuffered(c) (c->wbuf != NULL)
0104 
0105 #ifdef CONFIG_JFFS2_SUMMARY
0106 #define jffs2_can_mark_obsolete(c) (0)
0107 #else
0108 #define jffs2_can_mark_obsolete(c) (c->mtd->flags & (MTD_BIT_WRITEABLE))
0109 #endif
0110 
0111 #define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH)
0112 
0113 #define jffs2_wbuf_dirty(c) (!!(c)->wbuf_len)
0114 
0115 /* wbuf.c */
0116 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);
0117 int jffs2_flash_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, const u_char *buf);
0118 int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, u_char *buf);
0119 int jffs2_check_oob_empty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,int mode);
0120 int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
0121 int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
0122 int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset);
0123 void jffs2_wbuf_timeout(unsigned long data);
0124 void jffs2_wbuf_process(void *data);
0125 int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino);
0126 int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c);
0127 int jffs2_nand_flash_setup(struct jffs2_sb_info *c);
0128 void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c);
0129 
0130 #define jffs2_dataflash(c) (c->mtd->type == MTD_DATAFLASH)
0131 int jffs2_dataflash_setup(struct jffs2_sb_info *c);
0132 void jffs2_dataflash_cleanup(struct jffs2_sb_info *c);
0133 #define jffs2_ubivol(c) (c->mtd->type == MTD_UBIVOLUME)
0134 int jffs2_ubivol_setup(struct jffs2_sb_info *c);
0135 void jffs2_ubivol_cleanup(struct jffs2_sb_info *c);
0136 
0137 #define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && ! (c->mtd->flags & MTD_BIT_WRITEABLE))
0138 int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c);
0139 void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c);
0140 void jffs2_dirty_trigger(struct jffs2_sb_info *c);
0141 
0142 #endif /* WRITEBUFFER */
0143 
0144 /* background.c */
0145 int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
0146 void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);
0147 void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c);
0148 
0149 /* dir.c */
0150 extern const struct file_operations jffs2_dir_operations;
0151 extern const struct inode_operations jffs2_dir_inode_operations;
0152 
0153 /* file.c */
0154 extern const struct file_operations jffs2_file_operations;
0155 extern const struct inode_operations jffs2_file_inode_operations;
0156 extern const struct address_space_operations jffs2_file_address_operations;
0157 int jffs2_fsync(struct file *, loff_t, loff_t, int);
0158 int __jffs2_read_folio(struct file *file, struct folio *folio);
0159 
0160 /* ioctl.c */
0161 long jffs2_ioctl(struct file *, unsigned int, unsigned long);
0162 
0163 /* symlink.c */
0164 extern const struct inode_operations jffs2_symlink_inode_operations;
0165 
0166 /* fs.c */
0167 int jffs2_setattr (struct user_namespace *, struct dentry *, struct iattr *);
0168 int jffs2_do_setattr (struct inode *, struct iattr *);
0169 struct inode *jffs2_iget(struct super_block *, unsigned long);
0170 void jffs2_evict_inode (struct inode *);
0171 void jffs2_dirty_inode(struct inode *inode, int flags);
0172 struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode,
0173                    struct jffs2_raw_inode *ri);
0174 int jffs2_statfs (struct dentry *, struct kstatfs *);
0175 int jffs2_do_remount_fs(struct super_block *sb, struct fs_context *fc);
0176 int jffs2_do_fill_super(struct super_block *sb, struct fs_context *fc);
0177 void jffs2_gc_release_inode(struct jffs2_sb_info *c,
0178                 struct jffs2_inode_info *f);
0179 struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
0180                           int inum, int unlinked);
0181 
0182 unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c,
0183                    struct jffs2_inode_info *f,
0184                    unsigned long offset,
0185                    unsigned long *priv);
0186 void jffs2_flash_cleanup(struct jffs2_sb_info *c);
0187 
0188 
0189 /* writev.c */
0190 int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
0191                unsigned long count, loff_t to, size_t *retlen);
0192 int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
0193             size_t *retlen, const u_char *buf);
0194 
0195 #endif /* __JFFS2_OS_LINUX_H__ */
0196 
0197