xref: /openbmc/linux/fs/erofs/internal.h (revision c5aa903a)
147e4937aSGao Xiang /* SPDX-License-Identifier: GPL-2.0-only */
247e4937aSGao Xiang /*
347e4937aSGao Xiang  * Copyright (C) 2017-2018 HUAWEI, Inc.
4592e7cd0SAlexander A. Klimov  *             https://www.huawei.com/
5*c5aa903aSGao Xiang  * Copyright (C) 2021, Alibaba Cloud
647e4937aSGao Xiang  */
747e4937aSGao Xiang #ifndef __EROFS_INTERNAL_H
847e4937aSGao Xiang #define __EROFS_INTERNAL_H
947e4937aSGao Xiang 
1047e4937aSGao Xiang #include <linux/fs.h>
1147e4937aSGao Xiang #include <linux/dcache.h>
1247e4937aSGao Xiang #include <linux/mm.h>
1347e4937aSGao Xiang #include <linux/pagemap.h>
1447e4937aSGao Xiang #include <linux/bio.h>
1547e4937aSGao Xiang #include <linux/buffer_head.h>
1647e4937aSGao Xiang #include <linux/magic.h>
1747e4937aSGao Xiang #include <linux/slab.h>
1847e4937aSGao Xiang #include <linux/vmalloc.h>
19eadcd6b5SGao Xiang #include <linux/iomap.h>
2047e4937aSGao Xiang #include "erofs_fs.h"
2147e4937aSGao Xiang 
2247e4937aSGao Xiang /* redefine pr_fmt "erofs: " */
2347e4937aSGao Xiang #undef pr_fmt
2447e4937aSGao Xiang #define pr_fmt(fmt) "erofs: " fmt
2547e4937aSGao Xiang 
264f761fa2SGao Xiang __printf(3, 4) void _erofs_err(struct super_block *sb,
274f761fa2SGao Xiang 			       const char *function, const char *fmt, ...);
284f761fa2SGao Xiang #define erofs_err(sb, fmt, ...)	\
294f761fa2SGao Xiang 	_erofs_err(sb, __func__, fmt "\n", ##__VA_ARGS__)
304f761fa2SGao Xiang __printf(3, 4) void _erofs_info(struct super_block *sb,
314f761fa2SGao Xiang 			       const char *function, const char *fmt, ...);
324f761fa2SGao Xiang #define erofs_info(sb, fmt, ...) \
334f761fa2SGao Xiang 	_erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__)
3447e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_DEBUG
354f761fa2SGao Xiang #define erofs_dbg(x, ...)       pr_debug(x "\n", ##__VA_ARGS__)
3647e4937aSGao Xiang #define DBG_BUGON               BUG_ON
3747e4937aSGao Xiang #else
384f761fa2SGao Xiang #define erofs_dbg(x, ...)       ((void)0)
3947e4937aSGao Xiang #define DBG_BUGON(x)            ((void)(x))
4047e4937aSGao Xiang #endif	/* !CONFIG_EROFS_FS_DEBUG */
4147e4937aSGao Xiang 
4247e4937aSGao Xiang /* EROFS_SUPER_MAGIC_V1 to represent the whole file system */
4347e4937aSGao Xiang #define EROFS_SUPER_MAGIC   EROFS_SUPER_MAGIC_V1
4447e4937aSGao Xiang 
4547e4937aSGao Xiang typedef u64 erofs_nid_t;
4647e4937aSGao Xiang typedef u64 erofs_off_t;
4747e4937aSGao Xiang /* data type for filesystem-wide blocks number */
4847e4937aSGao Xiang typedef u32 erofs_blk_t;
4947e4937aSGao Xiang 
50f57a3fe4SChao Yu struct erofs_fs_context {
51f57a3fe4SChao Yu #ifdef CONFIG_EROFS_FS_ZIP
52f57a3fe4SChao Yu 	/* current strategy of how to use managed cache */
53f57a3fe4SChao Yu 	unsigned char cache_strategy;
5430048cdaSHuang Jianan 	/* strategy of sync decompression (false - auto, true - force on) */
5530048cdaSHuang Jianan 	bool readahead_sync_decompress;
56f57a3fe4SChao Yu 
57f57a3fe4SChao Yu 	/* threshold for decompression synchronously */
58f57a3fe4SChao Yu 	unsigned int max_sync_decompress_pages;
59f57a3fe4SChao Yu #endif
60f57a3fe4SChao Yu 	unsigned int mount_opt;
61f57a3fe4SChao Yu };
62f57a3fe4SChao Yu 
635d50538fSHuang Jianan /* all filesystem-wide lz4 configurations */
645d50538fSHuang Jianan struct erofs_sb_lz4_info {
655d50538fSHuang Jianan 	/* # of pages needed for EROFS lz4 rolling decompression */
665d50538fSHuang Jianan 	u16 max_distance_pages;
674fea63f7SGao Xiang 	/* maximum possible blocks for pclusters in the filesystem */
684fea63f7SGao Xiang 	u16 max_pclusterblks;
695d50538fSHuang Jianan };
705d50538fSHuang Jianan 
7147e4937aSGao Xiang struct erofs_sb_info {
7247e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_ZIP
7347e4937aSGao Xiang 	/* list for all registered superblocks, mainly for shrinker */
7447e4937aSGao Xiang 	struct list_head list;
7547e4937aSGao Xiang 	struct mutex umount_mutex;
7647e4937aSGao Xiang 
7764094a04SGao Xiang 	/* managed XArray arranged in physical block number */
7864094a04SGao Xiang 	struct xarray managed_pslots;
7947e4937aSGao Xiang 
8047e4937aSGao Xiang 	unsigned int shrinker_run_no;
8114373711SGao Xiang 	u16 available_compr_algs;
8247e4937aSGao Xiang 
8347e4937aSGao Xiang 	/* pseudo inode to manage cached pages */
8447e4937aSGao Xiang 	struct inode *managed_cache;
855d50538fSHuang Jianan 
865d50538fSHuang Jianan 	struct erofs_sb_lz4_info lz4;
8747e4937aSGao Xiang #endif	/* CONFIG_EROFS_FS_ZIP */
8806252e9cSGao Xiang 	struct dax_device *dax_dev;
8947e4937aSGao Xiang 	u32 blocks;
9047e4937aSGao Xiang 	u32 meta_blkaddr;
9147e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_XATTR
9247e4937aSGao Xiang 	u32 xattr_blkaddr;
9347e4937aSGao Xiang #endif
9447e4937aSGao Xiang 
9547e4937aSGao Xiang 	/* inode slot unit size in bit shift */
9647e4937aSGao Xiang 	unsigned char islotbits;
9747e4937aSGao Xiang 
9814373711SGao Xiang 	u32 sb_size;			/* total superblock size */
9947e4937aSGao Xiang 	u32 build_time_nsec;
10047e4937aSGao Xiang 	u64 build_time;
10147e4937aSGao Xiang 
10247e4937aSGao Xiang 	/* what we really care is nid, rather than ino.. */
10347e4937aSGao Xiang 	erofs_nid_t root_nid;
10447e4937aSGao Xiang 	/* used for statfs, f_files - f_favail */
10547e4937aSGao Xiang 	u64 inos;
10647e4937aSGao Xiang 
10747e4937aSGao Xiang 	u8 uuid[16];                    /* 128-bit uuid for volume */
10847e4937aSGao Xiang 	u8 volume_name[16];             /* volume name */
109b858a484SPratik Shinde 	u32 feature_compat;
110426a9308SGao Xiang 	u32 feature_incompat;
11147e4937aSGao Xiang 
112f57a3fe4SChao Yu 	struct erofs_fs_context ctx;	/* options */
11347e4937aSGao Xiang };
11447e4937aSGao Xiang 
11547e4937aSGao Xiang #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
11647e4937aSGao Xiang #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
11747e4937aSGao Xiang 
11847e4937aSGao Xiang /* Mount flags set via mount options or defaults */
11947e4937aSGao Xiang #define EROFS_MOUNT_XATTR_USER		0x00000010
12047e4937aSGao Xiang #define EROFS_MOUNT_POSIX_ACL		0x00000020
12106252e9cSGao Xiang #define EROFS_MOUNT_DAX_ALWAYS		0x00000040
12206252e9cSGao Xiang #define EROFS_MOUNT_DAX_NEVER		0x00000080
12347e4937aSGao Xiang 
124f57a3fe4SChao Yu #define clear_opt(ctx, option)	((ctx)->mount_opt &= ~EROFS_MOUNT_##option)
125f57a3fe4SChao Yu #define set_opt(ctx, option)	((ctx)->mount_opt |= EROFS_MOUNT_##option)
126f57a3fe4SChao Yu #define test_opt(ctx, option)	((ctx)->mount_opt & EROFS_MOUNT_##option)
12747e4937aSGao Xiang 
12847e4937aSGao Xiang enum {
12947e4937aSGao Xiang 	EROFS_ZIP_CACHE_DISABLED,
13047e4937aSGao Xiang 	EROFS_ZIP_CACHE_READAHEAD,
13147e4937aSGao Xiang 	EROFS_ZIP_CACHE_READAROUND
13247e4937aSGao Xiang };
13347e4937aSGao Xiang 
134f57a3fe4SChao Yu #ifdef CONFIG_EROFS_FS_ZIP
13547e4937aSGao Xiang #define EROFS_LOCKED_MAGIC     (INT_MIN | 0xE0F510CCL)
13647e4937aSGao Xiang 
13747e4937aSGao Xiang /* basic unit of the workstation of a super_block */
13847e4937aSGao Xiang struct erofs_workgroup {
13947e4937aSGao Xiang 	/* the workgroup index in the workstation */
14047e4937aSGao Xiang 	pgoff_t index;
14147e4937aSGao Xiang 
14247e4937aSGao Xiang 	/* overall workgroup reference count */
14347e4937aSGao Xiang 	atomic_t refcount;
14447e4937aSGao Xiang };
14547e4937aSGao Xiang 
14647e4937aSGao Xiang #if defined(CONFIG_SMP)
14747e4937aSGao Xiang static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
14847e4937aSGao Xiang 						 int val)
14947e4937aSGao Xiang {
15047e4937aSGao Xiang 	preempt_disable();
15147e4937aSGao Xiang 	if (val != atomic_cmpxchg(&grp->refcount, val, EROFS_LOCKED_MAGIC)) {
15247e4937aSGao Xiang 		preempt_enable();
15347e4937aSGao Xiang 		return false;
15447e4937aSGao Xiang 	}
15547e4937aSGao Xiang 	return true;
15647e4937aSGao Xiang }
15747e4937aSGao Xiang 
15847e4937aSGao Xiang static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
15947e4937aSGao Xiang 					    int orig_val)
16047e4937aSGao Xiang {
16147e4937aSGao Xiang 	/*
16247e4937aSGao Xiang 	 * other observers should notice all modifications
16347e4937aSGao Xiang 	 * in the freezing period.
16447e4937aSGao Xiang 	 */
16547e4937aSGao Xiang 	smp_mb();
16647e4937aSGao Xiang 	atomic_set(&grp->refcount, orig_val);
16747e4937aSGao Xiang 	preempt_enable();
16847e4937aSGao Xiang }
16947e4937aSGao Xiang 
17047e4937aSGao Xiang static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
17147e4937aSGao Xiang {
17247e4937aSGao Xiang 	return atomic_cond_read_relaxed(&grp->refcount,
17347e4937aSGao Xiang 					VAL != EROFS_LOCKED_MAGIC);
17447e4937aSGao Xiang }
17547e4937aSGao Xiang #else
17647e4937aSGao Xiang static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
17747e4937aSGao Xiang 						 int val)
17847e4937aSGao Xiang {
17947e4937aSGao Xiang 	preempt_disable();
18047e4937aSGao Xiang 	/* no need to spin on UP platforms, let's just disable preemption. */
18147e4937aSGao Xiang 	if (val != atomic_read(&grp->refcount)) {
18247e4937aSGao Xiang 		preempt_enable();
18347e4937aSGao Xiang 		return false;
18447e4937aSGao Xiang 	}
18547e4937aSGao Xiang 	return true;
18647e4937aSGao Xiang }
18747e4937aSGao Xiang 
18847e4937aSGao Xiang static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
18947e4937aSGao Xiang 					    int orig_val)
19047e4937aSGao Xiang {
19147e4937aSGao Xiang 	preempt_enable();
19247e4937aSGao Xiang }
19347e4937aSGao Xiang 
19447e4937aSGao Xiang static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
19547e4937aSGao Xiang {
19647e4937aSGao Xiang 	int v = atomic_read(&grp->refcount);
19747e4937aSGao Xiang 
19847e4937aSGao Xiang 	/* workgroup is never freezed on uniprocessor systems */
19947e4937aSGao Xiang 	DBG_BUGON(v == EROFS_LOCKED_MAGIC);
20047e4937aSGao Xiang 	return v;
20147e4937aSGao Xiang }
20247e4937aSGao Xiang #endif	/* !CONFIG_SMP */
20347e4937aSGao Xiang #endif	/* !CONFIG_EROFS_FS_ZIP */
20447e4937aSGao Xiang 
20547e4937aSGao Xiang /* we strictly follow PAGE_SIZE and no buffer head yet */
20647e4937aSGao Xiang #define LOG_BLOCK_SIZE		PAGE_SHIFT
20747e4937aSGao Xiang 
20847e4937aSGao Xiang #undef LOG_SECTORS_PER_BLOCK
20947e4937aSGao Xiang #define LOG_SECTORS_PER_BLOCK	(PAGE_SHIFT - 9)
21047e4937aSGao Xiang 
21147e4937aSGao Xiang #undef SECTORS_PER_BLOCK
21247e4937aSGao Xiang #define SECTORS_PER_BLOCK	(1 << SECTORS_PER_BLOCK)
21347e4937aSGao Xiang 
21447e4937aSGao Xiang #define EROFS_BLKSIZ		(1 << LOG_BLOCK_SIZE)
21547e4937aSGao Xiang 
21647e4937aSGao Xiang #if (EROFS_BLKSIZ % 4096 || !EROFS_BLKSIZ)
21747e4937aSGao Xiang #error erofs cannot be used in this platform
21847e4937aSGao Xiang #endif
21947e4937aSGao Xiang 
22047e4937aSGao Xiang #define ROOT_NID(sb)		((sb)->root_nid)
22147e4937aSGao Xiang 
22247e4937aSGao Xiang #define erofs_blknr(addr)       ((addr) / EROFS_BLKSIZ)
22347e4937aSGao Xiang #define erofs_blkoff(addr)      ((addr) % EROFS_BLKSIZ)
22447e4937aSGao Xiang #define blknr_to_addr(nr)       ((erofs_off_t)(nr) * EROFS_BLKSIZ)
22547e4937aSGao Xiang 
22647e4937aSGao Xiang static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
22747e4937aSGao Xiang {
22847e4937aSGao Xiang 	return blknr_to_addr(sbi->meta_blkaddr) + (nid << sbi->islotbits);
22947e4937aSGao Xiang }
23047e4937aSGao Xiang 
231de06a6a3SGao Xiang #define EROFS_FEATURE_FUNCS(name, compat, feature) \
232de06a6a3SGao Xiang static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \
233de06a6a3SGao Xiang { \
234de06a6a3SGao Xiang 	return sbi->feature_##compat & EROFS_FEATURE_##feature; \
235de06a6a3SGao Xiang }
236de06a6a3SGao Xiang 
237de06a6a3SGao Xiang EROFS_FEATURE_FUNCS(lz4_0padding, incompat, INCOMPAT_LZ4_0PADDING)
23814373711SGao Xiang EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS)
2395404c330SGao Xiang EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER)
240de06a6a3SGao Xiang EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
241de06a6a3SGao Xiang 
24247e4937aSGao Xiang /* atomic flag definitions */
243a5876e24SGao Xiang #define EROFS_I_EA_INITED_BIT	0
244a5876e24SGao Xiang #define EROFS_I_Z_INITED_BIT	1
24547e4937aSGao Xiang 
24647e4937aSGao Xiang /* bitlock definitions (arranged in reverse order) */
247a5876e24SGao Xiang #define EROFS_I_BL_XATTR_BIT	(BITS_PER_LONG - 1)
248a5876e24SGao Xiang #define EROFS_I_BL_Z_BIT	(BITS_PER_LONG - 2)
24947e4937aSGao Xiang 
250a5876e24SGao Xiang struct erofs_inode {
25147e4937aSGao Xiang 	erofs_nid_t nid;
25247e4937aSGao Xiang 
25347e4937aSGao Xiang 	/* atomic flags (including bitlocks) */
25447e4937aSGao Xiang 	unsigned long flags;
25547e4937aSGao Xiang 
2568a765682SGao Xiang 	unsigned char datalayout;
25747e4937aSGao Xiang 	unsigned char inode_isize;
25847e4937aSGao Xiang 	unsigned short xattr_isize;
25947e4937aSGao Xiang 
26047e4937aSGao Xiang 	unsigned int xattr_shared_count;
26147e4937aSGao Xiang 	unsigned int *xattr_shared_xattrs;
26247e4937aSGao Xiang 
26347e4937aSGao Xiang 	union {
26447e4937aSGao Xiang 		erofs_blk_t raw_blkaddr;
265*c5aa903aSGao Xiang 		struct {
266*c5aa903aSGao Xiang 			unsigned short	chunkformat;
267*c5aa903aSGao Xiang 			unsigned char	chunkbits;
268*c5aa903aSGao Xiang 		};
26947e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_ZIP
27047e4937aSGao Xiang 		struct {
27147e4937aSGao Xiang 			unsigned short z_advise;
27247e4937aSGao Xiang 			unsigned char  z_algorithmtype[2];
27347e4937aSGao Xiang 			unsigned char  z_logical_clusterbits;
27447e4937aSGao Xiang 		};
27547e4937aSGao Xiang #endif	/* CONFIG_EROFS_FS_ZIP */
27647e4937aSGao Xiang 	};
27747e4937aSGao Xiang 	/* the corresponding vfs inode */
27847e4937aSGao Xiang 	struct inode vfs_inode;
27947e4937aSGao Xiang };
28047e4937aSGao Xiang 
281a5876e24SGao Xiang #define EROFS_I(ptr)	\
282a5876e24SGao Xiang 	container_of(ptr, struct erofs_inode, vfs_inode)
28347e4937aSGao Xiang 
28499634bf3SGao Xiang static inline unsigned long erofs_inode_datablocks(struct inode *inode)
28547e4937aSGao Xiang {
28647e4937aSGao Xiang 	/* since i_size cannot be changed */
28747e4937aSGao Xiang 	return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
28847e4937aSGao Xiang }
28947e4937aSGao Xiang 
2908a765682SGao Xiang static inline unsigned int erofs_bitrange(unsigned int value, unsigned int bit,
2918a765682SGao Xiang 					  unsigned int bits)
29247e4937aSGao Xiang {
2938a765682SGao Xiang 
2948a765682SGao Xiang 	return (value >> bit) & ((1 << bits) - 1);
29547e4937aSGao Xiang }
29647e4937aSGao Xiang 
2978a765682SGao Xiang 
2988a765682SGao Xiang static inline unsigned int erofs_inode_version(unsigned int value)
29947e4937aSGao Xiang {
3008a765682SGao Xiang 	return erofs_bitrange(value, EROFS_I_VERSION_BIT,
3018a765682SGao Xiang 			      EROFS_I_VERSION_BITS);
3028a765682SGao Xiang }
3038a765682SGao Xiang 
3048a765682SGao Xiang static inline unsigned int erofs_inode_datalayout(unsigned int value)
3058a765682SGao Xiang {
3068a765682SGao Xiang 	return erofs_bitrange(value, EROFS_I_DATALAYOUT_BIT,
3078a765682SGao Xiang 			      EROFS_I_DATALAYOUT_BITS);
30847e4937aSGao Xiang }
30947e4937aSGao Xiang 
31047e4937aSGao Xiang extern const struct super_operations erofs_sops;
31147e4937aSGao Xiang 
31247e4937aSGao Xiang extern const struct address_space_operations erofs_raw_access_aops;
3130c638f70SGao Xiang extern const struct address_space_operations z_erofs_aops;
31447e4937aSGao Xiang 
31547e4937aSGao Xiang /*
3168137824eSYue Hu  * Logical to physical block mapping
31747e4937aSGao Xiang  *
31847e4937aSGao Xiang  * Different with other file systems, it is used for 2 access modes:
31947e4937aSGao Xiang  *
32047e4937aSGao Xiang  * 1) RAW access mode:
32147e4937aSGao Xiang  *
32247e4937aSGao Xiang  * Users pass a valid (m_lblk, m_lofs -- usually 0) pair,
32347e4937aSGao Xiang  * and get the valid m_pblk, m_pofs and the longest m_len(in bytes).
32447e4937aSGao Xiang  *
32547e4937aSGao Xiang  * Note that m_lblk in the RAW access mode refers to the number of
32647e4937aSGao Xiang  * the compressed ondisk block rather than the uncompressed
32747e4937aSGao Xiang  * in-memory block for the compressed file.
32847e4937aSGao Xiang  *
32947e4937aSGao Xiang  * m_pofs equals to m_lofs except for the inline data page.
33047e4937aSGao Xiang  *
33147e4937aSGao Xiang  * 2) Normal access mode:
33247e4937aSGao Xiang  *
33347e4937aSGao Xiang  * If the inode is not compressed, it has no difference with
33447e4937aSGao Xiang  * the RAW access mode. However, if the inode is compressed,
33547e4937aSGao Xiang  * users should pass a valid (m_lblk, m_lofs) pair, and get
33647e4937aSGao Xiang  * the needed m_pblk, m_pofs, m_len to get the compressed data
33747e4937aSGao Xiang  * and the updated m_lblk, m_lofs which indicates the start
33847e4937aSGao Xiang  * of the corresponding uncompressed data in the file.
33947e4937aSGao Xiang  */
34047e4937aSGao Xiang enum {
34147e4937aSGao Xiang 	BH_Zipped = BH_PrivateStart,
34247e4937aSGao Xiang 	BH_FullMapped,
34347e4937aSGao Xiang };
34447e4937aSGao Xiang 
34547e4937aSGao Xiang /* Has a disk mapping */
34647e4937aSGao Xiang #define EROFS_MAP_MAPPED	(1 << BH_Mapped)
34747e4937aSGao Xiang /* Located in metadata (could be copied from bd_inode) */
34847e4937aSGao Xiang #define EROFS_MAP_META		(1 << BH_Meta)
34947e4937aSGao Xiang /* The extent has been compressed */
35047e4937aSGao Xiang #define EROFS_MAP_ZIPPED	(1 << BH_Zipped)
35147e4937aSGao Xiang /* The length of extent is full */
35247e4937aSGao Xiang #define EROFS_MAP_FULL_MAPPED	(1 << BH_FullMapped)
35347e4937aSGao Xiang 
35447e4937aSGao Xiang struct erofs_map_blocks {
35547e4937aSGao Xiang 	erofs_off_t m_pa, m_la;
35647e4937aSGao Xiang 	u64 m_plen, m_llen;
35747e4937aSGao Xiang 
35847e4937aSGao Xiang 	unsigned int m_flags;
35947e4937aSGao Xiang 
36047e4937aSGao Xiang 	struct page *mpage;
36147e4937aSGao Xiang };
36247e4937aSGao Xiang 
3638137824eSYue Hu /* Flags used by erofs_map_blocks_flatmode() */
36447e4937aSGao Xiang #define EROFS_GET_BLOCKS_RAW    0x0001
365d95ae5e2SGao Xiang /*
366d95ae5e2SGao Xiang  * Used to get the exact decompressed length, e.g. fiemap (consider lookback
367d95ae5e2SGao Xiang  * approach instead if possible since it's more metadata lightweight.)
368d95ae5e2SGao Xiang  */
369d95ae5e2SGao Xiang #define EROFS_GET_BLOCKS_FIEMAP	0x0002
37047e4937aSGao Xiang 
37147e4937aSGao Xiang /* zmap.c */
372eadcd6b5SGao Xiang extern const struct iomap_ops z_erofs_iomap_report_ops;
373eadcd6b5SGao Xiang 
37447e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_ZIP
37547e4937aSGao Xiang int z_erofs_fill_inode(struct inode *inode);
37647e4937aSGao Xiang int z_erofs_map_blocks_iter(struct inode *inode,
37747e4937aSGao Xiang 			    struct erofs_map_blocks *map,
37847e4937aSGao Xiang 			    int flags);
37947e4937aSGao Xiang #else
38047e4937aSGao Xiang static inline int z_erofs_fill_inode(struct inode *inode) { return -EOPNOTSUPP; }
38147e4937aSGao Xiang static inline int z_erofs_map_blocks_iter(struct inode *inode,
38247e4937aSGao Xiang 					  struct erofs_map_blocks *map,
38347e4937aSGao Xiang 					  int flags)
38447e4937aSGao Xiang {
38547e4937aSGao Xiang 	return -EOPNOTSUPP;
38647e4937aSGao Xiang }
38747e4937aSGao Xiang #endif	/* !CONFIG_EROFS_FS_ZIP */
38847e4937aSGao Xiang 
38947e4937aSGao Xiang /* data.c */
390a08e67a0SHuang Jianan extern const struct file_operations erofs_file_fops;
391e655b5b3SGao Xiang struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr);
392eadcd6b5SGao Xiang int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
393eadcd6b5SGao Xiang 		 u64 start, u64 len);
39447e4937aSGao Xiang 
39547e4937aSGao Xiang /* inode.c */
39647e4937aSGao Xiang static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
39747e4937aSGao Xiang {
39847e4937aSGao Xiang #if BITS_PER_LONG == 32
39947e4937aSGao Xiang 	return (nid >> 32) ^ (nid & 0xffffffff);
40047e4937aSGao Xiang #else
40147e4937aSGao Xiang 	return nid;
40247e4937aSGao Xiang #endif
40347e4937aSGao Xiang }
40447e4937aSGao Xiang 
40547e4937aSGao Xiang extern const struct inode_operations erofs_generic_iops;
40647e4937aSGao Xiang extern const struct inode_operations erofs_symlink_iops;
40747e4937aSGao Xiang extern const struct inode_operations erofs_fast_symlink_iops;
40847e4937aSGao Xiang 
40947e4937aSGao Xiang struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
410549c7297SChristian Brauner int erofs_getattr(struct user_namespace *mnt_userns, const struct path *path,
411549c7297SChristian Brauner 		  struct kstat *stat, u32 request_mask,
412549c7297SChristian Brauner 		  unsigned int query_flags);
41347e4937aSGao Xiang 
41447e4937aSGao Xiang /* namei.c */
41547e4937aSGao Xiang extern const struct inode_operations erofs_dir_iops;
41647e4937aSGao Xiang 
41747e4937aSGao Xiang int erofs_namei(struct inode *dir, struct qstr *name,
41847e4937aSGao Xiang 		erofs_nid_t *nid, unsigned int *d_type);
41947e4937aSGao Xiang 
42047e4937aSGao Xiang /* dir.c */
42147e4937aSGao Xiang extern const struct file_operations erofs_dir_fops;
42247e4937aSGao Xiang 
423598162d0SGao Xiang static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)
424598162d0SGao Xiang {
425598162d0SGao Xiang 	int retried = 0;
426598162d0SGao Xiang 
427598162d0SGao Xiang 	while (1) {
428598162d0SGao Xiang 		void *p = vm_map_ram(pages, count, -1);
429598162d0SGao Xiang 
430598162d0SGao Xiang 		/* retry two more times (totally 3 times) */
431598162d0SGao Xiang 		if (p || ++retried >= 3)
432598162d0SGao Xiang 			return p;
433598162d0SGao Xiang 		vm_unmap_aliases();
434598162d0SGao Xiang 	}
435598162d0SGao Xiang 	return NULL;
436598162d0SGao Xiang }
437598162d0SGao Xiang 
43852488734SGao Xiang /* pcpubuf.c */
43952488734SGao Xiang void *erofs_get_pcpubuf(unsigned int requiredpages);
44052488734SGao Xiang void erofs_put_pcpubuf(void *ptr);
44152488734SGao Xiang int erofs_pcpubuf_growsize(unsigned int nrpages);
44252488734SGao Xiang void erofs_pcpubuf_init(void);
44352488734SGao Xiang void erofs_pcpubuf_exit(void);
44452488734SGao Xiang 
44547e4937aSGao Xiang /* utils.c / zdata.c */
4465ddcee1fSGao Xiang struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
44747e4937aSGao Xiang 
44847e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_ZIP
44947e4937aSGao Xiang int erofs_workgroup_put(struct erofs_workgroup *grp);
45047e4937aSGao Xiang struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
451997626d8SVladimir Zapolskiy 					     pgoff_t index);
45264094a04SGao Xiang struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
453e5e9a432SVladimir Zapolskiy 					       struct erofs_workgroup *grp);
45447e4937aSGao Xiang void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
45547e4937aSGao Xiang void erofs_shrinker_register(struct super_block *sb);
45647e4937aSGao Xiang void erofs_shrinker_unregister(struct super_block *sb);
45747e4937aSGao Xiang int __init erofs_init_shrinker(void);
45847e4937aSGao Xiang void erofs_exit_shrinker(void);
45947e4937aSGao Xiang int __init z_erofs_init_zip_subsystem(void);
46047e4937aSGao Xiang void z_erofs_exit_zip_subsystem(void);
46147e4937aSGao Xiang int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
46247e4937aSGao Xiang 				       struct erofs_workgroup *egrp);
463d252ff3dSYue Hu int erofs_try_to_free_cached_page(struct page *page);
4645d50538fSHuang Jianan int z_erofs_load_lz4_config(struct super_block *sb,
46546249cdeSGao Xiang 			    struct erofs_super_block *dsb,
46646249cdeSGao Xiang 			    struct z_erofs_lz4_cfgs *lz4, int len);
46747e4937aSGao Xiang #else
46847e4937aSGao Xiang static inline void erofs_shrinker_register(struct super_block *sb) {}
46947e4937aSGao Xiang static inline void erofs_shrinker_unregister(struct super_block *sb) {}
47047e4937aSGao Xiang static inline int erofs_init_shrinker(void) { return 0; }
47147e4937aSGao Xiang static inline void erofs_exit_shrinker(void) {}
47247e4937aSGao Xiang static inline int z_erofs_init_zip_subsystem(void) { return 0; }
47347e4937aSGao Xiang static inline void z_erofs_exit_zip_subsystem(void) {}
4745d50538fSHuang Jianan static inline int z_erofs_load_lz4_config(struct super_block *sb,
47546249cdeSGao Xiang 				  struct erofs_super_block *dsb,
47646249cdeSGao Xiang 				  struct z_erofs_lz4_cfgs *lz4, int len)
4775d50538fSHuang Jianan {
47814373711SGao Xiang 	if (lz4 || dsb->u1.lz4_max_distance) {
4795d50538fSHuang Jianan 		erofs_err(sb, "lz4 algorithm isn't enabled");
4805d50538fSHuang Jianan 		return -EINVAL;
4815d50538fSHuang Jianan 	}
4825d50538fSHuang Jianan 	return 0;
4835d50538fSHuang Jianan }
48447e4937aSGao Xiang #endif	/* !CONFIG_EROFS_FS_ZIP */
48547e4937aSGao Xiang 
48647e4937aSGao Xiang #define EFSCORRUPTED    EUCLEAN         /* Filesystem is corrupted */
48747e4937aSGao Xiang 
48847e4937aSGao Xiang #endif	/* __EROFS_INTERNAL_H */
489