Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2017-2018 HUAWEI, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *             https://www.huawei.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Created by Gao Xiang <gaoxiang25@huawei.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #ifndef __EROFS_INTERNAL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define __EROFS_INTERNAL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/dcache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/magic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "erofs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* redefine pr_fmt "erofs: " */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #undef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define pr_fmt(fmt) "erofs: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) __printf(3, 4) void _erofs_err(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			       const char *function, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define erofs_err(sb, fmt, ...)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	_erofs_err(sb, __func__, fmt "\n", ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) __printf(3, 4) void _erofs_info(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			       const char *function, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define erofs_info(sb, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	_erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #ifdef CONFIG_EROFS_FS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define erofs_dbg(x, ...)       pr_debug(x "\n", ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define DBG_BUGON               BUG_ON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define erofs_dbg(x, ...)       ((void)0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define DBG_BUGON(x)            ((void)(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #endif	/* !CONFIG_EROFS_FS_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /* EROFS_SUPER_MAGIC_V1 to represent the whole file system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define EROFS_SUPER_MAGIC   EROFS_SUPER_MAGIC_V1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) typedef u64 erofs_nid_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) typedef u64 erofs_off_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /* data type for filesystem-wide blocks number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) typedef u32 erofs_blk_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) struct erofs_fs_context {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	/* current strategy of how to use managed cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned char cache_strategy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	/* strategy of sync decompression (false - auto, true - force on) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	bool readahead_sync_decompress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* threshold for decompression synchronously */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	unsigned int max_sync_decompress_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	unsigned int mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) /* all filesystem-wide lz4 configurations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) struct erofs_sb_lz4_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	/* # of pages needed for EROFS lz4 rolling decompression */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u16 max_distance_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* maximum possible blocks for pclusters in the filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u16 max_pclusterblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) struct erofs_sb_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* list for all registered superblocks, mainly for shrinker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct mutex umount_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* managed XArray arranged in physical block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct xarray managed_pslots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned int shrinker_run_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u16 available_compr_algs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* pseudo inode to manage cached pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct inode *managed_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct erofs_sb_lz4_info lz4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #endif	/* CONFIG_EROFS_FS_ZIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct dax_device *dax_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	u32 blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	u32 meta_blkaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #ifdef CONFIG_EROFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	u32 xattr_blkaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	/* inode slot unit size in bit shift */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	unsigned char islotbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	u32 sb_size;			/* total superblock size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	u32 build_time_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	u64 build_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* what we really care is nid, rather than ino.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	erofs_nid_t root_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/* used for statfs, f_files - f_favail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	u64 inos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	u8 uuid[16];                    /* 128-bit uuid for volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	u8 volume_name[16];             /* volume name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u32 feature_compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	u32 feature_incompat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct erofs_fs_context ctx;	/* options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* Mount flags set via mount options or defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define EROFS_MOUNT_XATTR_USER		0x00000010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define EROFS_MOUNT_POSIX_ACL		0x00000020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define EROFS_MOUNT_DAX_ALWAYS		0x00000040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define EROFS_MOUNT_DAX_NEVER		0x00000080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define clear_opt(ctx, option)	((ctx)->mount_opt &= ~EROFS_MOUNT_##option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define set_opt(ctx, option)	((ctx)->mount_opt |= EROFS_MOUNT_##option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define test_opt(ctx, option)	((ctx)->mount_opt & EROFS_MOUNT_##option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	EROFS_ZIP_CACHE_DISABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	EROFS_ZIP_CACHE_READAHEAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	EROFS_ZIP_CACHE_READAROUND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define EROFS_LOCKED_MAGIC     (INT_MIN | 0xE0F510CCL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* basic unit of the workstation of a super_block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct erofs_workgroup {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	/* the workgroup index in the workstation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	pgoff_t index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/* overall workgroup reference count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	atomic_t refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #if defined(CONFIG_SMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 						 int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (val != atomic_cmpxchg(&grp->refcount, val, EROFS_LOCKED_MAGIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 					    int orig_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 * other observers should notice all modifications
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 * in the freezing period.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	atomic_set(&grp->refcount, orig_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return atomic_cond_read_relaxed(&grp->refcount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 					VAL != EROFS_LOCKED_MAGIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 						 int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* no need to spin on UP platforms, let's just disable preemption. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (val != atomic_read(&grp->refcount)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 					    int orig_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int v = atomic_read(&grp->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	/* workgroup is never freezed on uniprocessor systems */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	DBG_BUGON(v == EROFS_LOCKED_MAGIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	return v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #endif	/* !CONFIG_SMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #endif	/* !CONFIG_EROFS_FS_ZIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* we strictly follow PAGE_SIZE and no buffer head yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define LOG_BLOCK_SIZE		PAGE_SHIFT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #undef LOG_SECTORS_PER_BLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #define LOG_SECTORS_PER_BLOCK	(PAGE_SHIFT - 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #undef SECTORS_PER_BLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #define SECTORS_PER_BLOCK	(1 << SECTORS_PER_BLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define EROFS_BLKSIZ		(1 << LOG_BLOCK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #if (EROFS_BLKSIZ % 4096 || !EROFS_BLKSIZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #error erofs cannot be used in this platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define ROOT_NID(sb)		((sb)->root_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define erofs_blknr(addr)       ((addr) / EROFS_BLKSIZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define erofs_blkoff(addr)      ((addr) % EROFS_BLKSIZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #define blknr_to_addr(nr)       ((erofs_off_t)(nr) * EROFS_BLKSIZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return blknr_to_addr(sbi->meta_blkaddr) + (nid << sbi->islotbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #define EROFS_FEATURE_FUNCS(name, compat, feature) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	return sbi->feature_##compat & EROFS_FEATURE_##feature; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) EROFS_FEATURE_FUNCS(lz4_0padding, incompat, INCOMPAT_LZ4_0PADDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* atomic flag definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define EROFS_I_EA_INITED_BIT	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #define EROFS_I_Z_INITED_BIT	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* bitlock definitions (arranged in reverse order) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #define EROFS_I_BL_XATTR_BIT	(BITS_PER_LONG - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #define EROFS_I_BL_Z_BIT	(BITS_PER_LONG - 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct erofs_inode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	erofs_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	/* atomic flags (including bitlocks) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	unsigned char datalayout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	unsigned char inode_isize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	unsigned short xattr_isize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	unsigned int xattr_shared_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	unsigned int *xattr_shared_xattrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		erofs_blk_t raw_blkaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			unsigned short z_advise;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			unsigned char  z_algorithmtype[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			unsigned char  z_logical_clusterbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #endif	/* CONFIG_EROFS_FS_ZIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/* the corresponding vfs inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct inode vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #define EROFS_I(ptr)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	container_of(ptr, struct erofs_inode, vfs_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static inline unsigned long erofs_inode_datablocks(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/* since i_size cannot be changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static inline unsigned int erofs_bitrange(unsigned int value, unsigned int bit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 					  unsigned int bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	return (value >> bit) & ((1 << bits) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static inline unsigned int erofs_inode_version(unsigned int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return erofs_bitrange(value, EROFS_I_VERSION_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			      EROFS_I_VERSION_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline unsigned int erofs_inode_datalayout(unsigned int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return erofs_bitrange(value, EROFS_I_DATALAYOUT_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			      EROFS_I_DATALAYOUT_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) extern const struct super_operations erofs_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) extern const struct address_space_operations erofs_raw_access_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) extern const struct address_space_operations z_erofs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * Logical to physical block mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  * Different with other file systems, it is used for 2 access modes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  * 1) RAW access mode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  * Users pass a valid (m_lblk, m_lofs -- usually 0) pair,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * and get the valid m_pblk, m_pofs and the longest m_len(in bytes).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * Note that m_lblk in the RAW access mode refers to the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * the compressed ondisk block rather than the uncompressed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * in-memory block for the compressed file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * m_pofs equals to m_lofs except for the inline data page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * 2) Normal access mode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  * If the inode is not compressed, it has no difference with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  * the RAW access mode. However, if the inode is compressed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  * users should pass a valid (m_lblk, m_lofs) pair, and get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * the needed m_pblk, m_pofs, m_len to get the compressed data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * and the updated m_lblk, m_lofs which indicates the start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * of the corresponding uncompressed data in the file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	BH_Zipped = BH_PrivateStart,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	BH_FullMapped,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* Has a disk mapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) #define EROFS_MAP_MAPPED	(1 << BH_Mapped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* Located in metadata (could be copied from bd_inode) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #define EROFS_MAP_META		(1 << BH_Meta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* The extent has been compressed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) #define EROFS_MAP_ZIPPED	(1 << BH_Zipped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* The length of extent is full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) #define EROFS_MAP_FULL_MAPPED	(1 << BH_FullMapped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct erofs_map_blocks {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	erofs_off_t m_pa, m_la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	u64 m_plen, m_llen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	unsigned int m_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	struct page *mpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* Flags used by erofs_map_blocks_flatmode() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #define EROFS_GET_BLOCKS_RAW    0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* zmap.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) int z_erofs_fill_inode(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int z_erofs_map_blocks_iter(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			    struct erofs_map_blocks *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			    int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static inline int z_erofs_fill_inode(struct inode *inode) { return -EOPNOTSUPP; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static inline int z_erofs_map_blocks_iter(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 					  struct erofs_map_blocks *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 					  int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) #endif	/* !CONFIG_EROFS_FS_ZIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) /* data.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) extern const struct file_operations erofs_file_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /* inode.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #if BITS_PER_LONG == 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	return (nid >> 32) ^ (nid & 0xffffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	return nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) extern const struct inode_operations erofs_generic_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) extern const struct inode_operations erofs_symlink_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) extern const struct inode_operations erofs_fast_symlink_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) int erofs_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		  u32 request_mask, unsigned int query_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* namei.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) extern const struct inode_operations erofs_dir_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) int erofs_namei(struct inode *dir, struct qstr *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		erofs_nid_t *nid, unsigned int *d_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* dir.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) extern const struct file_operations erofs_dir_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	int retried = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		void *p = vm_map_ram(pages, count, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		/* retry two more times (totally 3 times) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		if (p || ++retried >= 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		vm_unmap_aliases();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /* pcpubuf.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) void *erofs_get_pcpubuf(unsigned int requiredpages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) void erofs_put_pcpubuf(void *ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) int erofs_pcpubuf_growsize(unsigned int nrpages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) void erofs_pcpubuf_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) void erofs_pcpubuf_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /* utils.c / zdata.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) int erofs_workgroup_put(struct erofs_workgroup *grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 					     pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 					       struct erofs_workgroup *grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) void erofs_shrinker_register(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) void erofs_shrinker_unregister(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int __init erofs_init_shrinker(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) void erofs_exit_shrinker(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int __init z_erofs_init_zip_subsystem(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) void z_erofs_exit_zip_subsystem(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 				       struct erofs_workgroup *egrp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) int erofs_try_to_free_cached_page(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 				  struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) int z_erofs_load_lz4_config(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			    struct erofs_super_block *dsb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			    struct z_erofs_lz4_cfgs *lz4, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) static inline void erofs_shrinker_register(struct super_block *sb) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static inline void erofs_shrinker_unregister(struct super_block *sb) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static inline int erofs_init_shrinker(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static inline void erofs_exit_shrinker(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static inline int z_erofs_init_zip_subsystem(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static inline void z_erofs_exit_zip_subsystem(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static inline int z_erofs_load_lz4_config(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 				  struct erofs_super_block *dsb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 				  struct z_erofs_lz4_cfgs *lz4, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	if (lz4 || dsb->u1.lz4_max_distance) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		erofs_err(sb, "lz4 algorithm isn't enabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) #endif	/* !CONFIG_EROFS_FS_ZIP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) #define EFSCORRUPTED    EUCLEAN         /* Filesystem is corrupted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) #endif	/* __EROFS_INTERNAL_H */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)