162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * JFFS2 -- Journalling Flash File System, Version 2.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright © 2001-2007 Red Hat, Inc.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Created by David Woodhouse <dwmw2@infradead.org>
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * For licensing information, see the file 'LICENCE' in this directory.
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#ifndef __JFFS2_OS_LINUX_H__
1362306a36Sopenharmony_ci#define __JFFS2_OS_LINUX_H__
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/* JFFS2 uses Linux mode bits natively -- no need for conversion */
1662306a36Sopenharmony_ci#define os_to_jffs2_mode(x) (x)
1762306a36Sopenharmony_ci#define jffs2_to_os_mode(x) (x)
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistruct kstatfs;
2062306a36Sopenharmony_cistruct kvec;
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define JFFS2_INODE_INFO(i) (container_of(i, struct jffs2_inode_info, vfs_inode))
2362306a36Sopenharmony_ci#define OFNI_EDONI_2SFFJ(f)  (&(f)->vfs_inode)
2462306a36Sopenharmony_ci#define JFFS2_SB_INFO(sb) (sb->s_fs_info)
2562306a36Sopenharmony_ci#define OFNI_BS_2SFFJ(c)  ((struct super_block *)c->os_priv)
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size)
2962306a36Sopenharmony_ci#define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
3062306a36Sopenharmony_ci#define JFFS2_F_I_UID(f) (i_uid_read(OFNI_EDONI_2SFFJ(f)))
3162306a36Sopenharmony_ci#define JFFS2_F_I_GID(f) (i_gid_read(OFNI_EDONI_2SFFJ(f)))
3262306a36Sopenharmony_ci#define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev)
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define JFFS2_CLAMP_TIME(t) ((uint32_t)clamp_t(time64_t, (t), 0, U32_MAX))
3562306a36Sopenharmony_ci#define ITIME(sec) ((struct timespec64){sec, 0})
3662306a36Sopenharmony_ci#define JFFS2_NOW() JFFS2_CLAMP_TIME(ktime_get_real_seconds())
3762306a36Sopenharmony_ci#define I_SEC(tv) JFFS2_CLAMP_TIME((tv).tv_sec)
3862306a36Sopenharmony_ci#define JFFS2_F_I_CTIME(f) I_SEC(inode_get_ctime(OFNI_EDONI_2SFFJ(f)))
3962306a36Sopenharmony_ci#define JFFS2_F_I_MTIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_mtime)
4062306a36Sopenharmony_ci#define JFFS2_F_I_ATIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_atime)
4162306a36Sopenharmony_ci#define sleep_on_spinunlock(wq, s)				\
4262306a36Sopenharmony_ci	do {							\
4362306a36Sopenharmony_ci		DECLARE_WAITQUEUE(__wait, current);		\
4462306a36Sopenharmony_ci		add_wait_queue((wq), &__wait);			\
4562306a36Sopenharmony_ci		set_current_state(TASK_UNINTERRUPTIBLE);	\
4662306a36Sopenharmony_ci		spin_unlock(s);					\
4762306a36Sopenharmony_ci		schedule();					\
4862306a36Sopenharmony_ci		remove_wait_queue((wq), &__wait);		\
4962306a36Sopenharmony_ci	} while(0)
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cistatic inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
5262306a36Sopenharmony_ci{
5362306a36Sopenharmony_ci	f->highest_version = 0;
5462306a36Sopenharmony_ci	f->fragtree = RB_ROOT;
5562306a36Sopenharmony_ci	f->metadata = NULL;
5662306a36Sopenharmony_ci	f->dents = NULL;
5762306a36Sopenharmony_ci	f->target = NULL;
5862306a36Sopenharmony_ci	f->flags = 0;
5962306a36Sopenharmony_ci	f->usercompr = 0;
6062306a36Sopenharmony_ci}
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define jffs2_is_readonly(c) (OFNI_BS_2SFFJ(c)->s_flags & SB_RDONLY)
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define SECTOR_ADDR(x) ( (((unsigned long)(x) / c->sector_size) * c->sector_size) )
6662306a36Sopenharmony_ci#ifndef CONFIG_JFFS2_FS_WRITEBUFFER
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#ifdef CONFIG_JFFS2_SUMMARY
7062306a36Sopenharmony_ci#define jffs2_can_mark_obsolete(c) (0)
7162306a36Sopenharmony_ci#else
7262306a36Sopenharmony_ci#define jffs2_can_mark_obsolete(c) (1)
7362306a36Sopenharmony_ci#endif
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define jffs2_is_writebuffered(c) (0)
7662306a36Sopenharmony_ci#define jffs2_cleanmarker_oob(c) (0)
7762306a36Sopenharmony_ci#define jffs2_write_nand_cleanmarker(c,jeb) (-EIO)
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci#define jffs2_flash_write(c, ofs, len, retlen, buf) jffs2_flash_direct_write(c, ofs, len, retlen, buf)
8062306a36Sopenharmony_ci#define jffs2_flash_read(c, ofs, len, retlen, buf) (mtd_read((c)->mtd, ofs, len, retlen, buf))
8162306a36Sopenharmony_ci#define jffs2_flush_wbuf_pad(c) ({ do{} while(0); (void)(c), 0; })
8262306a36Sopenharmony_ci#define jffs2_flush_wbuf_gc(c, i) ({ do{} while(0); (void)(c), (void) i, 0; })
8362306a36Sopenharmony_ci#define jffs2_write_nand_badblock(c,jeb,bad_offset) (1)
8462306a36Sopenharmony_ci#define jffs2_nand_flash_setup(c) (0)
8562306a36Sopenharmony_ci#define jffs2_nand_flash_cleanup(c) do {} while(0)
8662306a36Sopenharmony_ci#define jffs2_wbuf_dirty(c) (0)
8762306a36Sopenharmony_ci#define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e)
8862306a36Sopenharmony_ci#define jffs2_wbuf_timeout NULL
8962306a36Sopenharmony_ci#define jffs2_wbuf_process NULL
9062306a36Sopenharmony_ci#define jffs2_dataflash(c) (0)
9162306a36Sopenharmony_ci#define jffs2_dataflash_setup(c) (0)
9262306a36Sopenharmony_ci#define jffs2_dataflash_cleanup(c) do {} while (0)
9362306a36Sopenharmony_ci#define jffs2_nor_wbuf_flash(c) (0)
9462306a36Sopenharmony_ci#define jffs2_nor_wbuf_flash_setup(c) (0)
9562306a36Sopenharmony_ci#define jffs2_nor_wbuf_flash_cleanup(c) do {} while (0)
9662306a36Sopenharmony_ci#define jffs2_ubivol(c) (0)
9762306a36Sopenharmony_ci#define jffs2_ubivol_setup(c) (0)
9862306a36Sopenharmony_ci#define jffs2_ubivol_cleanup(c) do {} while (0)
9962306a36Sopenharmony_ci#define jffs2_dirty_trigger(c) do {} while (0)
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#else /* NAND and/or ECC'd NOR support present */
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci#define jffs2_is_writebuffered(c) (c->wbuf != NULL)
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci#ifdef CONFIG_JFFS2_SUMMARY
10662306a36Sopenharmony_ci#define jffs2_can_mark_obsolete(c) (0)
10762306a36Sopenharmony_ci#else
10862306a36Sopenharmony_ci#define jffs2_can_mark_obsolete(c) (c->mtd->flags & (MTD_BIT_WRITEABLE))
10962306a36Sopenharmony_ci#endif
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci#define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH)
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci#define jffs2_wbuf_dirty(c) (!!(c)->wbuf_len)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci/* wbuf.c */
11662306a36Sopenharmony_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);
11762306a36Sopenharmony_ciint jffs2_flash_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, const u_char *buf);
11862306a36Sopenharmony_ciint jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, u_char *buf);
11962306a36Sopenharmony_ciint jffs2_check_oob_empty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,int mode);
12062306a36Sopenharmony_ciint jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
12162306a36Sopenharmony_ciint jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
12262306a36Sopenharmony_ciint jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset);
12362306a36Sopenharmony_civoid jffs2_wbuf_timeout(unsigned long data);
12462306a36Sopenharmony_civoid jffs2_wbuf_process(void *data);
12562306a36Sopenharmony_ciint jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino);
12662306a36Sopenharmony_ciint jffs2_flush_wbuf_pad(struct jffs2_sb_info *c);
12762306a36Sopenharmony_ciint jffs2_nand_flash_setup(struct jffs2_sb_info *c);
12862306a36Sopenharmony_civoid jffs2_nand_flash_cleanup(struct jffs2_sb_info *c);
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#define jffs2_dataflash(c) (c->mtd->type == MTD_DATAFLASH)
13162306a36Sopenharmony_ciint jffs2_dataflash_setup(struct jffs2_sb_info *c);
13262306a36Sopenharmony_civoid jffs2_dataflash_cleanup(struct jffs2_sb_info *c);
13362306a36Sopenharmony_ci#define jffs2_ubivol(c) (c->mtd->type == MTD_UBIVOLUME)
13462306a36Sopenharmony_ciint jffs2_ubivol_setup(struct jffs2_sb_info *c);
13562306a36Sopenharmony_civoid jffs2_ubivol_cleanup(struct jffs2_sb_info *c);
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci#define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && ! (c->mtd->flags & MTD_BIT_WRITEABLE))
13862306a36Sopenharmony_ciint jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c);
13962306a36Sopenharmony_civoid jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c);
14062306a36Sopenharmony_civoid jffs2_dirty_trigger(struct jffs2_sb_info *c);
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci#endif /* WRITEBUFFER */
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/* background.c */
14562306a36Sopenharmony_ciint jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
14662306a36Sopenharmony_civoid jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);
14762306a36Sopenharmony_civoid jffs2_garbage_collect_trigger(struct jffs2_sb_info *c);
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci/* dir.c */
15062306a36Sopenharmony_ciextern const struct file_operations jffs2_dir_operations;
15162306a36Sopenharmony_ciextern const struct inode_operations jffs2_dir_inode_operations;
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci/* file.c */
15462306a36Sopenharmony_ciextern const struct file_operations jffs2_file_operations;
15562306a36Sopenharmony_ciextern const struct inode_operations jffs2_file_inode_operations;
15662306a36Sopenharmony_ciextern const struct address_space_operations jffs2_file_address_operations;
15762306a36Sopenharmony_ciint jffs2_fsync(struct file *, loff_t, loff_t, int);
15862306a36Sopenharmony_ciint __jffs2_read_folio(struct file *file, struct folio *folio);
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci/* ioctl.c */
16162306a36Sopenharmony_cilong jffs2_ioctl(struct file *, unsigned int, unsigned long);
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci/* symlink.c */
16462306a36Sopenharmony_ciextern const struct inode_operations jffs2_symlink_inode_operations;
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci/* fs.c */
16762306a36Sopenharmony_ciint jffs2_setattr (struct mnt_idmap *, struct dentry *, struct iattr *);
16862306a36Sopenharmony_ciint jffs2_do_setattr (struct inode *, struct iattr *);
16962306a36Sopenharmony_cistruct inode *jffs2_iget(struct super_block *, unsigned long);
17062306a36Sopenharmony_civoid jffs2_evict_inode (struct inode *);
17162306a36Sopenharmony_civoid jffs2_dirty_inode(struct inode *inode, int flags);
17262306a36Sopenharmony_cistruct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode,
17362306a36Sopenharmony_ci			       struct jffs2_raw_inode *ri);
17462306a36Sopenharmony_ciint jffs2_statfs (struct dentry *, struct kstatfs *);
17562306a36Sopenharmony_ciint jffs2_do_remount_fs(struct super_block *sb, struct fs_context *fc);
17662306a36Sopenharmony_ciint jffs2_do_fill_super(struct super_block *sb, struct fs_context *fc);
17762306a36Sopenharmony_civoid jffs2_gc_release_inode(struct jffs2_sb_info *c,
17862306a36Sopenharmony_ci			    struct jffs2_inode_info *f);
17962306a36Sopenharmony_cistruct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
18062306a36Sopenharmony_ci					      int inum, int unlinked);
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ciunsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c,
18362306a36Sopenharmony_ci				   struct jffs2_inode_info *f,
18462306a36Sopenharmony_ci				   unsigned long offset,
18562306a36Sopenharmony_ci				   unsigned long *priv);
18662306a36Sopenharmony_civoid jffs2_flash_cleanup(struct jffs2_sb_info *c);
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci/* writev.c */
19062306a36Sopenharmony_ciint jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
19162306a36Sopenharmony_ci		       unsigned long count, loff_t to, size_t *retlen);
19262306a36Sopenharmony_ciint jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
19362306a36Sopenharmony_ci			size_t *retlen, const u_char *buf);
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci#endif /* __JFFS2_OS_LINUX_H__ */
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci
198