18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * JFFS2 -- Journalling Flash File System, Version 2. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright © 2001-2007 Red Hat, Inc. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Created by David Woodhouse <dwmw2@infradead.org> 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * For licensing information, see the file 'LICENCE' in this directory. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef __JFFS2_OS_LINUX_H__ 138c2ecf20Sopenharmony_ci#define __JFFS2_OS_LINUX_H__ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* JFFS2 uses Linux mode bits natively -- no need for conversion */ 168c2ecf20Sopenharmony_ci#define os_to_jffs2_mode(x) (x) 178c2ecf20Sopenharmony_ci#define jffs2_to_os_mode(x) (x) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistruct kstatfs; 208c2ecf20Sopenharmony_cistruct kvec; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define JFFS2_INODE_INFO(i) (container_of(i, struct jffs2_inode_info, vfs_inode)) 238c2ecf20Sopenharmony_ci#define OFNI_EDONI_2SFFJ(f) (&(f)->vfs_inode) 248c2ecf20Sopenharmony_ci#define JFFS2_SB_INFO(sb) (sb->s_fs_info) 258c2ecf20Sopenharmony_ci#define OFNI_BS_2SFFJ(c) ((struct super_block *)c->os_priv) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size) 298c2ecf20Sopenharmony_ci#define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode) 308c2ecf20Sopenharmony_ci#define JFFS2_F_I_UID(f) (i_uid_read(OFNI_EDONI_2SFFJ(f))) 318c2ecf20Sopenharmony_ci#define JFFS2_F_I_GID(f) (i_gid_read(OFNI_EDONI_2SFFJ(f))) 328c2ecf20Sopenharmony_ci#define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define JFFS2_CLAMP_TIME(t) ((uint32_t)clamp_t(time64_t, (t), 0, U32_MAX)) 358c2ecf20Sopenharmony_ci#define ITIME(sec) ((struct timespec64){sec, 0}) 368c2ecf20Sopenharmony_ci#define JFFS2_NOW() JFFS2_CLAMP_TIME(ktime_get_real_seconds()) 378c2ecf20Sopenharmony_ci#define I_SEC(tv) JFFS2_CLAMP_TIME((tv).tv_sec) 388c2ecf20Sopenharmony_ci#define JFFS2_F_I_CTIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_ctime) 398c2ecf20Sopenharmony_ci#define JFFS2_F_I_MTIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_mtime) 408c2ecf20Sopenharmony_ci#define JFFS2_F_I_ATIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_atime) 418c2ecf20Sopenharmony_ci#define sleep_on_spinunlock(wq, s) \ 428c2ecf20Sopenharmony_ci do { \ 438c2ecf20Sopenharmony_ci DECLARE_WAITQUEUE(__wait, current); \ 448c2ecf20Sopenharmony_ci add_wait_queue((wq), &__wait); \ 458c2ecf20Sopenharmony_ci set_current_state(TASK_UNINTERRUPTIBLE); \ 468c2ecf20Sopenharmony_ci spin_unlock(s); \ 478c2ecf20Sopenharmony_ci schedule(); \ 488c2ecf20Sopenharmony_ci remove_wait_queue((wq), &__wait); \ 498c2ecf20Sopenharmony_ci } while(0) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic inline void jffs2_init_inode_info(struct jffs2_inode_info *f) 528c2ecf20Sopenharmony_ci{ 538c2ecf20Sopenharmony_ci f->highest_version = 0; 548c2ecf20Sopenharmony_ci f->fragtree = RB_ROOT; 558c2ecf20Sopenharmony_ci f->metadata = NULL; 568c2ecf20Sopenharmony_ci f->dents = NULL; 578c2ecf20Sopenharmony_ci f->target = NULL; 588c2ecf20Sopenharmony_ci f->flags = 0; 598c2ecf20Sopenharmony_ci f->usercompr = 0; 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define jffs2_is_readonly(c) (OFNI_BS_2SFFJ(c)->s_flags & SB_RDONLY) 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#define SECTOR_ADDR(x) ( (((unsigned long)(x) / c->sector_size) * c->sector_size) ) 668c2ecf20Sopenharmony_ci#ifndef CONFIG_JFFS2_FS_WRITEBUFFER 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#ifdef CONFIG_JFFS2_SUMMARY 708c2ecf20Sopenharmony_ci#define jffs2_can_mark_obsolete(c) (0) 718c2ecf20Sopenharmony_ci#else 728c2ecf20Sopenharmony_ci#define jffs2_can_mark_obsolete(c) (1) 738c2ecf20Sopenharmony_ci#endif 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#define jffs2_is_writebuffered(c) (0) 768c2ecf20Sopenharmony_ci#define jffs2_cleanmarker_oob(c) (0) 778c2ecf20Sopenharmony_ci#define jffs2_write_nand_cleanmarker(c,jeb) (-EIO) 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#define jffs2_flash_write(c, ofs, len, retlen, buf) jffs2_flash_direct_write(c, ofs, len, retlen, buf) 808c2ecf20Sopenharmony_ci#define jffs2_flash_read(c, ofs, len, retlen, buf) (mtd_read((c)->mtd, ofs, len, retlen, buf)) 818c2ecf20Sopenharmony_ci#define jffs2_flush_wbuf_pad(c) ({ do{} while(0); (void)(c), 0; }) 828c2ecf20Sopenharmony_ci#define jffs2_flush_wbuf_gc(c, i) ({ do{} while(0); (void)(c), (void) i, 0; }) 838c2ecf20Sopenharmony_ci#define jffs2_write_nand_badblock(c,jeb,bad_offset) (1) 848c2ecf20Sopenharmony_ci#define jffs2_nand_flash_setup(c) (0) 858c2ecf20Sopenharmony_ci#define jffs2_nand_flash_cleanup(c) do {} while(0) 868c2ecf20Sopenharmony_ci#define jffs2_wbuf_dirty(c) (0) 878c2ecf20Sopenharmony_ci#define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e) 888c2ecf20Sopenharmony_ci#define jffs2_wbuf_timeout NULL 898c2ecf20Sopenharmony_ci#define jffs2_wbuf_process NULL 908c2ecf20Sopenharmony_ci#define jffs2_dataflash(c) (0) 918c2ecf20Sopenharmony_ci#define jffs2_dataflash_setup(c) (0) 928c2ecf20Sopenharmony_ci#define jffs2_dataflash_cleanup(c) do {} while (0) 938c2ecf20Sopenharmony_ci#define jffs2_nor_wbuf_flash(c) (0) 948c2ecf20Sopenharmony_ci#define jffs2_nor_wbuf_flash_setup(c) (0) 958c2ecf20Sopenharmony_ci#define jffs2_nor_wbuf_flash_cleanup(c) do {} while (0) 968c2ecf20Sopenharmony_ci#define jffs2_ubivol(c) (0) 978c2ecf20Sopenharmony_ci#define jffs2_ubivol_setup(c) (0) 988c2ecf20Sopenharmony_ci#define jffs2_ubivol_cleanup(c) do {} while (0) 998c2ecf20Sopenharmony_ci#define jffs2_dirty_trigger(c) do {} while (0) 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci#else /* NAND and/or ECC'd NOR support present */ 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#define jffs2_is_writebuffered(c) (c->wbuf != NULL) 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#ifdef CONFIG_JFFS2_SUMMARY 1068c2ecf20Sopenharmony_ci#define jffs2_can_mark_obsolete(c) (0) 1078c2ecf20Sopenharmony_ci#else 1088c2ecf20Sopenharmony_ci#define jffs2_can_mark_obsolete(c) (c->mtd->flags & (MTD_BIT_WRITEABLE)) 1098c2ecf20Sopenharmony_ci#endif 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#define jffs2_wbuf_dirty(c) (!!(c)->wbuf_len) 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* wbuf.c */ 1168c2ecf20Sopenharmony_ciint jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino); 1178c2ecf20Sopenharmony_ciint jffs2_flash_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, const u_char *buf); 1188c2ecf20Sopenharmony_ciint jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, u_char *buf); 1198c2ecf20Sopenharmony_ciint jffs2_check_oob_empty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,int mode); 1208c2ecf20Sopenharmony_ciint jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 1218c2ecf20Sopenharmony_ciint jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 1228c2ecf20Sopenharmony_ciint jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset); 1238c2ecf20Sopenharmony_civoid jffs2_wbuf_timeout(unsigned long data); 1248c2ecf20Sopenharmony_civoid jffs2_wbuf_process(void *data); 1258c2ecf20Sopenharmony_ciint jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino); 1268c2ecf20Sopenharmony_ciint jffs2_flush_wbuf_pad(struct jffs2_sb_info *c); 1278c2ecf20Sopenharmony_ciint jffs2_nand_flash_setup(struct jffs2_sb_info *c); 1288c2ecf20Sopenharmony_civoid jffs2_nand_flash_cleanup(struct jffs2_sb_info *c); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define jffs2_dataflash(c) (c->mtd->type == MTD_DATAFLASH) 1318c2ecf20Sopenharmony_ciint jffs2_dataflash_setup(struct jffs2_sb_info *c); 1328c2ecf20Sopenharmony_civoid jffs2_dataflash_cleanup(struct jffs2_sb_info *c); 1338c2ecf20Sopenharmony_ci#define jffs2_ubivol(c) (c->mtd->type == MTD_UBIVOLUME) 1348c2ecf20Sopenharmony_ciint jffs2_ubivol_setup(struct jffs2_sb_info *c); 1358c2ecf20Sopenharmony_civoid jffs2_ubivol_cleanup(struct jffs2_sb_info *c); 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci#define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && ! (c->mtd->flags & MTD_BIT_WRITEABLE)) 1388c2ecf20Sopenharmony_ciint jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c); 1398c2ecf20Sopenharmony_civoid jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c); 1408c2ecf20Sopenharmony_civoid jffs2_dirty_trigger(struct jffs2_sb_info *c); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci#endif /* WRITEBUFFER */ 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci/* background.c */ 1458c2ecf20Sopenharmony_ciint jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c); 1468c2ecf20Sopenharmony_civoid jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c); 1478c2ecf20Sopenharmony_civoid jffs2_garbage_collect_trigger(struct jffs2_sb_info *c); 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* dir.c */ 1508c2ecf20Sopenharmony_ciextern const struct file_operations jffs2_dir_operations; 1518c2ecf20Sopenharmony_ciextern const struct inode_operations jffs2_dir_inode_operations; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci/* file.c */ 1548c2ecf20Sopenharmony_ciextern const struct file_operations jffs2_file_operations; 1558c2ecf20Sopenharmony_ciextern const struct inode_operations jffs2_file_inode_operations; 1568c2ecf20Sopenharmony_ciextern const struct address_space_operations jffs2_file_address_operations; 1578c2ecf20Sopenharmony_ciint jffs2_fsync(struct file *, loff_t, loff_t, int); 1588c2ecf20Sopenharmony_ciint jffs2_do_readpage_unlock(void *data, struct page *pg); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci/* ioctl.c */ 1618c2ecf20Sopenharmony_cilong jffs2_ioctl(struct file *, unsigned int, unsigned long); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci/* symlink.c */ 1648c2ecf20Sopenharmony_ciextern const struct inode_operations jffs2_symlink_inode_operations; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci/* fs.c */ 1678c2ecf20Sopenharmony_ciint jffs2_setattr (struct dentry *, struct iattr *); 1688c2ecf20Sopenharmony_ciint jffs2_do_setattr (struct inode *, struct iattr *); 1698c2ecf20Sopenharmony_cistruct inode *jffs2_iget(struct super_block *, unsigned long); 1708c2ecf20Sopenharmony_civoid jffs2_evict_inode (struct inode *); 1718c2ecf20Sopenharmony_civoid jffs2_dirty_inode(struct inode *inode, int flags); 1728c2ecf20Sopenharmony_cistruct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode, 1738c2ecf20Sopenharmony_ci struct jffs2_raw_inode *ri); 1748c2ecf20Sopenharmony_ciint jffs2_statfs (struct dentry *, struct kstatfs *); 1758c2ecf20Sopenharmony_ciint jffs2_do_remount_fs(struct super_block *sb, struct fs_context *fc); 1768c2ecf20Sopenharmony_ciint jffs2_do_fill_super(struct super_block *sb, struct fs_context *fc); 1778c2ecf20Sopenharmony_civoid jffs2_gc_release_inode(struct jffs2_sb_info *c, 1788c2ecf20Sopenharmony_ci struct jffs2_inode_info *f); 1798c2ecf20Sopenharmony_cistruct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, 1808c2ecf20Sopenharmony_ci int inum, int unlinked); 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ciunsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, 1838c2ecf20Sopenharmony_ci struct jffs2_inode_info *f, 1848c2ecf20Sopenharmony_ci unsigned long offset, 1858c2ecf20Sopenharmony_ci unsigned long *priv); 1868c2ecf20Sopenharmony_civoid jffs2_flash_cleanup(struct jffs2_sb_info *c); 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/* writev.c */ 1908c2ecf20Sopenharmony_ciint jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs, 1918c2ecf20Sopenharmony_ci unsigned long count, loff_t to, size_t *retlen); 1928c2ecf20Sopenharmony_ciint jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, 1938c2ecf20Sopenharmony_ci size_t *retlen, const u_char *buf); 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci#endif /* __JFFS2_OS_LINUX_H__ */ 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci 198