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/ 5c5aa903aSGao 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/magic.h> 1647e4937aSGao Xiang #include <linux/slab.h> 1747e4937aSGao Xiang #include <linux/vmalloc.h> 18eadcd6b5SGao Xiang #include <linux/iomap.h> 1947e4937aSGao Xiang #include "erofs_fs.h" 2047e4937aSGao Xiang 2147e4937aSGao Xiang /* redefine pr_fmt "erofs: " */ 2247e4937aSGao Xiang #undef pr_fmt 2347e4937aSGao Xiang #define pr_fmt(fmt) "erofs: " fmt 2447e4937aSGao Xiang 254f761fa2SGao Xiang __printf(3, 4) void _erofs_err(struct super_block *sb, 264f761fa2SGao Xiang const char *function, const char *fmt, ...); 274f761fa2SGao Xiang #define erofs_err(sb, fmt, ...) \ 284f761fa2SGao Xiang _erofs_err(sb, __func__, fmt "\n", ##__VA_ARGS__) 294f761fa2SGao Xiang __printf(3, 4) void _erofs_info(struct super_block *sb, 304f761fa2SGao Xiang const char *function, const char *fmt, ...); 314f761fa2SGao Xiang #define erofs_info(sb, fmt, ...) \ 324f761fa2SGao Xiang _erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__) 3347e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_DEBUG 3447e4937aSGao Xiang #define DBG_BUGON BUG_ON 3547e4937aSGao Xiang #else 3647e4937aSGao Xiang #define DBG_BUGON(x) ((void)(x)) 3747e4937aSGao Xiang #endif /* !CONFIG_EROFS_FS_DEBUG */ 3847e4937aSGao Xiang 3947e4937aSGao Xiang /* EROFS_SUPER_MAGIC_V1 to represent the whole file system */ 4047e4937aSGao Xiang #define EROFS_SUPER_MAGIC EROFS_SUPER_MAGIC_V1 4147e4937aSGao Xiang 4247e4937aSGao Xiang typedef u64 erofs_nid_t; 4347e4937aSGao Xiang typedef u64 erofs_off_t; 4447e4937aSGao Xiang /* data type for filesystem-wide blocks number */ 4547e4937aSGao Xiang typedef u32 erofs_blk_t; 4647e4937aSGao Xiang 47dfeab2e9SGao Xiang struct erofs_device_info { 48dfeab2e9SGao Xiang char *path; 49955b478eSJeffle Xu struct erofs_fscache *fscache; 50dfeab2e9SGao Xiang struct block_device *bdev; 51dfeab2e9SGao Xiang struct dax_device *dax_dev; 52cd913c76SChristoph Hellwig u64 dax_part_off; 53dfeab2e9SGao Xiang 54dfeab2e9SGao Xiang u32 blocks; 55dfeab2e9SGao Xiang u32 mapped_blkaddr; 56dfeab2e9SGao Xiang }; 57dfeab2e9SGao Xiang 5840452ffcSHuang Jianan enum { 5940452ffcSHuang Jianan EROFS_SYNC_DECOMPRESS_AUTO, 6040452ffcSHuang Jianan EROFS_SYNC_DECOMPRESS_FORCE_ON, 6140452ffcSHuang Jianan EROFS_SYNC_DECOMPRESS_FORCE_OFF 6240452ffcSHuang Jianan }; 6340452ffcSHuang Jianan 64e6242465SGao Xiang struct erofs_mount_opts { 65f57a3fe4SChao Yu #ifdef CONFIG_EROFS_FS_ZIP 66f57a3fe4SChao Yu /* current strategy of how to use managed cache */ 67f57a3fe4SChao Yu unsigned char cache_strategy; 6840452ffcSHuang Jianan /* strategy of sync decompression (0 - auto, 1 - force on, 2 - force off) */ 6940452ffcSHuang Jianan unsigned int sync_decompress; 70f57a3fe4SChao Yu 71f57a3fe4SChao Yu /* threshold for decompression synchronously */ 72f57a3fe4SChao Yu unsigned int max_sync_decompress_pages; 73f57a3fe4SChao Yu #endif 74f57a3fe4SChao Yu unsigned int mount_opt; 75f57a3fe4SChao Yu }; 76f57a3fe4SChao Yu 77dfeab2e9SGao Xiang struct erofs_dev_context { 78dfeab2e9SGao Xiang struct idr tree; 79dfeab2e9SGao Xiang struct rw_semaphore rwsem; 80dfeab2e9SGao Xiang 81dfeab2e9SGao Xiang unsigned int extra_devices; 828b465fecSJia Zhu bool flatdev; 83dfeab2e9SGao Xiang }; 84dfeab2e9SGao Xiang 85e6242465SGao Xiang struct erofs_fs_context { 86e6242465SGao Xiang struct erofs_mount_opts opt; 87dfeab2e9SGao Xiang struct erofs_dev_context *devs; 8839bfcb81SJingbo Xu char *fsid; 8939bfcb81SJingbo Xu char *domain_id; 90e6242465SGao Xiang }; 91e6242465SGao Xiang 925d50538fSHuang Jianan /* all filesystem-wide lz4 configurations */ 935d50538fSHuang Jianan struct erofs_sb_lz4_info { 945d50538fSHuang Jianan /* # of pages needed for EROFS lz4 rolling decompression */ 955d50538fSHuang Jianan u16 max_distance_pages; 964fea63f7SGao Xiang /* maximum possible blocks for pclusters in the filesystem */ 974fea63f7SGao Xiang u16 max_pclusterblks; 985d50538fSHuang Jianan }; 995d50538fSHuang Jianan 1008b7adf1dSJia Zhu struct erofs_domain { 1018b7adf1dSJia Zhu refcount_t ref; 1028b7adf1dSJia Zhu struct list_head list; 1038b7adf1dSJia Zhu struct fscache_volume *volume; 1048b7adf1dSJia Zhu char *domain_id; 1058b7adf1dSJia Zhu }; 1068b7adf1dSJia Zhu 107b02c602fSJeffle Xu struct erofs_fscache { 108b02c602fSJeffle Xu struct fscache_cookie *cookie; 10961fef989SJingbo Xu struct inode *inode; /* anonymous inode for the blob */ 1102dfb8c3bSJingbo Xu 1112dfb8c3bSJingbo Xu /* used for share domain mode */ 1127d419637SJia Zhu struct erofs_domain *domain; 1132dfb8c3bSJingbo Xu struct list_head node; 1142dfb8c3bSJingbo Xu refcount_t ref; 1157d419637SJia Zhu char *name; 116b02c602fSJeffle Xu }; 117b02c602fSJeffle Xu 1189e382914SJingbo Xu struct erofs_xattr_prefix_item { 1199e382914SJingbo Xu struct erofs_xattr_long_prefix *prefix; 1209e382914SJingbo Xu u8 infix_len; 1219e382914SJingbo Xu }; 1229e382914SJingbo Xu 12347e4937aSGao Xiang struct erofs_sb_info { 124e6242465SGao Xiang struct erofs_mount_opts opt; /* options */ 12547e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_ZIP 12647e4937aSGao Xiang /* list for all registered superblocks, mainly for shrinker */ 12747e4937aSGao Xiang struct list_head list; 12847e4937aSGao Xiang struct mutex umount_mutex; 12947e4937aSGao Xiang 13064094a04SGao Xiang /* managed XArray arranged in physical block number */ 13164094a04SGao Xiang struct xarray managed_pslots; 13247e4937aSGao Xiang 13347e4937aSGao Xiang unsigned int shrinker_run_no; 13414373711SGao Xiang u16 available_compr_algs; 13547e4937aSGao Xiang 13647e4937aSGao Xiang /* pseudo inode to manage cached pages */ 13747e4937aSGao Xiang struct inode *managed_cache; 1385d50538fSHuang Jianan 1395d50538fSHuang Jianan struct erofs_sb_lz4_info lz4; 14047e4937aSGao Xiang #endif /* CONFIG_EROFS_FS_ZIP */ 141a97a218bSJingbo Xu struct inode *packed_inode; 142dfeab2e9SGao Xiang struct erofs_dev_context *devs; 14306252e9cSGao Xiang struct dax_device *dax_dev; 144cd913c76SChristoph Hellwig u64 dax_part_off; 145dfeab2e9SGao Xiang u64 total_blocks; 146dfeab2e9SGao Xiang u32 primarydevice_blocks; 147dfeab2e9SGao Xiang 14847e4937aSGao Xiang u32 meta_blkaddr; 14947e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_XATTR 15047e4937aSGao Xiang u32 xattr_blkaddr; 1519e382914SJingbo Xu u32 xattr_prefix_start; 1529e382914SJingbo Xu u8 xattr_prefix_count; 1539e382914SJingbo Xu struct erofs_xattr_prefix_item *xattr_prefixes; 15447e4937aSGao Xiang #endif 155dfeab2e9SGao Xiang u16 device_id_mask; /* valid bits of device id to be used */ 15647e4937aSGao Xiang 1573acea5fcSJingbo Xu unsigned char islotbits; /* inode slot unit size in bit shift */ 158d3c4bdccSJingbo Xu unsigned char blkszbits; /* filesystem block size in bit shift */ 15947e4937aSGao Xiang 16014373711SGao Xiang u32 sb_size; /* total superblock size */ 16147e4937aSGao Xiang u32 build_time_nsec; 16247e4937aSGao Xiang u64 build_time; 16347e4937aSGao Xiang 16447e4937aSGao Xiang /* what we really care is nid, rather than ino.. */ 16547e4937aSGao Xiang erofs_nid_t root_nid; 166cb9bce79SJingbo Xu erofs_nid_t packed_nid; 16747e4937aSGao Xiang /* used for statfs, f_files - f_favail */ 16847e4937aSGao Xiang u64 inos; 16947e4937aSGao Xiang 17047e4937aSGao Xiang u8 uuid[16]; /* 128-bit uuid for volume */ 17147e4937aSGao Xiang u8 volume_name[16]; /* volume name */ 172b858a484SPratik Shinde u32 feature_compat; 173426a9308SGao Xiang u32 feature_incompat; 174168e9a76SHuang Jianan 175168e9a76SHuang Jianan /* sysfs support */ 176168e9a76SHuang Jianan struct kobject s_kobj; /* /sys/fs/erofs/<devname> */ 177168e9a76SHuang Jianan struct completion s_kobj_unregister; 178c6be2bd0SJeffle Xu 179c6be2bd0SJeffle Xu /* fscache support */ 180c6be2bd0SJeffle Xu struct fscache_volume *volume; 18137c90c5fSJeffle Xu struct erofs_fscache *s_fscache; 1828b7adf1dSJia Zhu struct erofs_domain *domain; 18339bfcb81SJingbo Xu char *fsid; 18439bfcb81SJingbo Xu char *domain_id; 18547e4937aSGao Xiang }; 18647e4937aSGao Xiang 18747e4937aSGao Xiang #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info) 18847e4937aSGao Xiang #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info) 18947e4937aSGao Xiang 19047e4937aSGao Xiang /* Mount flags set via mount options or defaults */ 19147e4937aSGao Xiang #define EROFS_MOUNT_XATTR_USER 0x00000010 19247e4937aSGao Xiang #define EROFS_MOUNT_POSIX_ACL 0x00000020 19306252e9cSGao Xiang #define EROFS_MOUNT_DAX_ALWAYS 0x00000040 19406252e9cSGao Xiang #define EROFS_MOUNT_DAX_NEVER 0x00000080 19547e4937aSGao Xiang 196e6242465SGao Xiang #define clear_opt(opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option) 197e6242465SGao Xiang #define set_opt(opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option) 198e6242465SGao Xiang #define test_opt(opt, option) ((opt)->mount_opt & EROFS_MOUNT_##option) 19947e4937aSGao Xiang 20093b856bbSJeffle Xu static inline bool erofs_is_fscache_mode(struct super_block *sb) 20193b856bbSJeffle Xu { 20293b856bbSJeffle Xu return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !sb->s_bdev; 20393b856bbSJeffle Xu } 20493b856bbSJeffle Xu 20547e4937aSGao Xiang enum { 20647e4937aSGao Xiang EROFS_ZIP_CACHE_DISABLED, 20747e4937aSGao Xiang EROFS_ZIP_CACHE_READAHEAD, 20847e4937aSGao Xiang EROFS_ZIP_CACHE_READAROUND 20947e4937aSGao Xiang }; 21047e4937aSGao Xiang 21147e4937aSGao Xiang /* basic unit of the workstation of a super_block */ 21247e4937aSGao Xiang struct erofs_workgroup { 21347e4937aSGao Xiang pgoff_t index; 214*7674a42fSGao Xiang struct lockref lockref; 21547e4937aSGao Xiang }; 21647e4937aSGao Xiang 217fdf80a47SGao Xiang enum erofs_kmap_type { 218fdf80a47SGao Xiang EROFS_NO_KMAP, /* don't map the buffer */ 219927e5010SGao Xiang EROFS_KMAP, /* use kmap_local_page() to map the buffer */ 220fdf80a47SGao Xiang }; 221fdf80a47SGao Xiang 222fdf80a47SGao Xiang struct erofs_buf { 223eb2c5e41SGao Xiang struct inode *inode; 224fdf80a47SGao Xiang struct page *page; 225fdf80a47SGao Xiang void *base; 226fdf80a47SGao Xiang enum erofs_kmap_type kmap_type; 227fdf80a47SGao Xiang }; 228fdf80a47SGao Xiang #define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL }) 229fdf80a47SGao Xiang 23047e4937aSGao Xiang #define ROOT_NID(sb) ((sb)->root_nid) 23147e4937aSGao Xiang 2323acea5fcSJingbo Xu #define erofs_blknr(sb, addr) ((addr) >> (sb)->s_blocksize_bits) 2333acea5fcSJingbo Xu #define erofs_blkoff(sb, addr) ((addr) & ((sb)->s_blocksize - 1)) 2343acea5fcSJingbo Xu #define erofs_pos(sb, blk) ((erofs_off_t)(blk) << (sb)->s_blocksize_bits) 2353acea5fcSJingbo Xu #define erofs_iblks(i) (round_up((i)->i_size, i_blocksize(i)) >> (i)->i_blkbits) 23647e4937aSGao Xiang 237de06a6a3SGao Xiang #define EROFS_FEATURE_FUNCS(name, compat, feature) \ 238de06a6a3SGao Xiang static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \ 239de06a6a3SGao Xiang { \ 240de06a6a3SGao Xiang return sbi->feature_##compat & EROFS_FEATURE_##feature; \ 241de06a6a3SGao Xiang } 242de06a6a3SGao Xiang 2437e508f2cSHuang Jianan EROFS_FEATURE_FUNCS(zero_padding, incompat, INCOMPAT_ZERO_PADDING) 24414373711SGao Xiang EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS) 2455404c330SGao Xiang EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER) 246168e9a76SHuang Jianan EROFS_FEATURE_FUNCS(chunked_file, incompat, INCOMPAT_CHUNKED_FILE) 247dfeab2e9SGao Xiang EROFS_FEATURE_FUNCS(device_table, incompat, INCOMPAT_DEVICE_TABLE) 248168e9a76SHuang Jianan EROFS_FEATURE_FUNCS(compr_head2, incompat, INCOMPAT_COMPR_HEAD2) 249ab92184fSYue Hu EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING) 250b15b2e30SYue Hu EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS) 2515c2a6425SGao Xiang EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE) 2526a318ccdSJingbo Xu EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES) 253de06a6a3SGao Xiang EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) 254de06a6a3SGao Xiang 25547e4937aSGao Xiang /* atomic flag definitions */ 256a5876e24SGao Xiang #define EROFS_I_EA_INITED_BIT 0 257a5876e24SGao Xiang #define EROFS_I_Z_INITED_BIT 1 25847e4937aSGao Xiang 25947e4937aSGao Xiang /* bitlock definitions (arranged in reverse order) */ 260a5876e24SGao Xiang #define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1) 261a5876e24SGao Xiang #define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2) 26247e4937aSGao Xiang 263a5876e24SGao Xiang struct erofs_inode { 26447e4937aSGao Xiang erofs_nid_t nid; 26547e4937aSGao Xiang 26647e4937aSGao Xiang /* atomic flags (including bitlocks) */ 26747e4937aSGao Xiang unsigned long flags; 26847e4937aSGao Xiang 2698a765682SGao Xiang unsigned char datalayout; 27047e4937aSGao Xiang unsigned char inode_isize; 2711b3567a1SJingbo Xu unsigned int xattr_isize; 27247e4937aSGao Xiang 27347e4937aSGao Xiang unsigned int xattr_shared_count; 27447e4937aSGao Xiang unsigned int *xattr_shared_xattrs; 27547e4937aSGao Xiang 27647e4937aSGao Xiang union { 27747e4937aSGao Xiang erofs_blk_t raw_blkaddr; 278c5aa903aSGao Xiang struct { 279c5aa903aSGao Xiang unsigned short chunkformat; 280c5aa903aSGao Xiang unsigned char chunkbits; 281c5aa903aSGao Xiang }; 28247e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_ZIP 28347e4937aSGao Xiang struct { 28447e4937aSGao Xiang unsigned short z_advise; 28547e4937aSGao Xiang unsigned char z_algorithmtype[2]; 28647e4937aSGao Xiang unsigned char z_logical_clusterbits; 287ab92184fSYue Hu unsigned long z_tailextent_headlcn; 288b15b2e30SYue Hu union { 289b15b2e30SYue Hu struct { 29022ba5e99SGao Xiang erofs_off_t z_idataoff; 291ab92184fSYue Hu unsigned short z_idata_size; 29247e4937aSGao Xiang }; 293b15b2e30SYue Hu erofs_off_t z_fragmentoff; 294b15b2e30SYue Hu }; 295b15b2e30SYue Hu }; 29647e4937aSGao Xiang #endif /* CONFIG_EROFS_FS_ZIP */ 29747e4937aSGao Xiang }; 29847e4937aSGao Xiang /* the corresponding vfs inode */ 29947e4937aSGao Xiang struct inode vfs_inode; 30047e4937aSGao Xiang }; 30147e4937aSGao Xiang 302b780d3fcSGao Xiang #define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode) 30347e4937aSGao Xiang 304b780d3fcSGao Xiang static inline erofs_off_t erofs_iloc(struct inode *inode) 30547e4937aSGao Xiang { 306b780d3fcSGao Xiang struct erofs_sb_info *sbi = EROFS_I_SB(inode); 307b780d3fcSGao Xiang 3083acea5fcSJingbo Xu return erofs_pos(inode->i_sb, sbi->meta_blkaddr) + 309b780d3fcSGao Xiang (EROFS_I(inode)->nid << sbi->islotbits); 31047e4937aSGao Xiang } 31147e4937aSGao Xiang 312745ed7d7SGao Xiang static inline unsigned int erofs_inode_version(unsigned int ifmt) 31347e4937aSGao Xiang { 314745ed7d7SGao Xiang return (ifmt >> EROFS_I_VERSION_BIT) & EROFS_I_VERSION_MASK; 31547e4937aSGao Xiang } 31647e4937aSGao Xiang 317745ed7d7SGao Xiang static inline unsigned int erofs_inode_datalayout(unsigned int ifmt) 31847e4937aSGao Xiang { 319745ed7d7SGao Xiang return (ifmt >> EROFS_I_DATALAYOUT_BIT) & EROFS_I_DATALAYOUT_MASK; 32047e4937aSGao Xiang } 32147e4937aSGao Xiang 32238629291SGao Xiang /* 32338629291SGao Xiang * Different from grab_cache_page_nowait(), reclaiming is never triggered 32438629291SGao Xiang * when allocating new pages. 32538629291SGao Xiang */ 32638629291SGao Xiang static inline 32738629291SGao Xiang struct page *erofs_grab_cache_page_nowait(struct address_space *mapping, 32838629291SGao Xiang pgoff_t index) 32938629291SGao Xiang { 33038629291SGao Xiang return pagecache_get_page(mapping, index, 33138629291SGao Xiang FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT, 33238629291SGao Xiang readahead_gfp_mask(mapping) & ~__GFP_RECLAIM); 33338629291SGao Xiang } 33438629291SGao Xiang 33547e4937aSGao Xiang /* Has a disk mapping */ 336768bb10aSGao Xiang #define EROFS_MAP_MAPPED 0x0001 33747e4937aSGao Xiang /* Located in metadata (could be copied from bd_inode) */ 338768bb10aSGao Xiang #define EROFS_MAP_META 0x0002 3398f899262SGao Xiang /* The extent is encoded */ 340768bb10aSGao Xiang #define EROFS_MAP_ENCODED 0x0004 34147e4937aSGao Xiang /* The length of extent is full */ 342768bb10aSGao Xiang #define EROFS_MAP_FULL_MAPPED 0x0008 343b15b2e30SYue Hu /* Located in the special packed inode */ 344768bb10aSGao Xiang #define EROFS_MAP_FRAGMENT 0x0010 3455c2a6425SGao Xiang /* The extent refers to partial decompressed data */ 346768bb10aSGao Xiang #define EROFS_MAP_PARTIAL_REF 0x0020 34747e4937aSGao Xiang 34847e4937aSGao Xiang struct erofs_map_blocks { 34909c54379SGao Xiang struct erofs_buf buf; 35009c54379SGao Xiang 35147e4937aSGao Xiang erofs_off_t m_pa, m_la; 35247e4937aSGao Xiang u64 m_plen, m_llen; 35347e4937aSGao Xiang 354dfeab2e9SGao Xiang unsigned short m_deviceid; 3558f899262SGao Xiang char m_algorithmformat; 35647e4937aSGao Xiang unsigned int m_flags; 35747e4937aSGao Xiang }; 35847e4937aSGao Xiang 359d95ae5e2SGao Xiang /* 360d95ae5e2SGao Xiang * Used to get the exact decompressed length, e.g. fiemap (consider lookback 361d95ae5e2SGao Xiang * approach instead if possible since it's more metadata lightweight.) 362d95ae5e2SGao Xiang */ 3638b58f9f0SJingbo Xu #define EROFS_GET_BLOCKS_FIEMAP 0x0001 364622ceaddSGao Xiang /* Used to map the whole extent if non-negligible data is requested for LZMA */ 3658b58f9f0SJingbo Xu #define EROFS_GET_BLOCKS_READMORE 0x0002 366b15b2e30SYue Hu /* Used to map tail extent for tailpacking inline or fragment pcluster */ 3678b58f9f0SJingbo Xu #define EROFS_GET_BLOCKS_FINDTAIL 0x0004 36847e4937aSGao Xiang 3698f899262SGao Xiang enum { 3708f899262SGao Xiang Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX, 371fdffc091SYue Hu Z_EROFS_COMPRESSION_INTERLACED, 3728f899262SGao Xiang Z_EROFS_COMPRESSION_RUNTIME_MAX 3738f899262SGao Xiang }; 3748f899262SGao Xiang 375dfeab2e9SGao Xiang struct erofs_map_dev { 376955b478eSJeffle Xu struct erofs_fscache *m_fscache; 377dfeab2e9SGao Xiang struct block_device *m_bdev; 378dfeab2e9SGao Xiang struct dax_device *m_daxdev; 379de205114SChristoph Hellwig u64 m_dax_part_off; 380dfeab2e9SGao Xiang 381dfeab2e9SGao Xiang erofs_off_t m_pa; 382dfeab2e9SGao Xiang unsigned int m_deviceid; 383dfeab2e9SGao Xiang }; 384dfeab2e9SGao Xiang 385557afdd9SGao Xiang extern struct file_system_type erofs_fs_type; 386557afdd9SGao Xiang extern const struct super_operations erofs_sops; 387557afdd9SGao Xiang 388557afdd9SGao Xiang extern const struct address_space_operations erofs_raw_access_aops; 389557afdd9SGao Xiang extern const struct address_space_operations z_erofs_aops; 390557afdd9SGao Xiang extern const struct address_space_operations erofs_fscache_access_aops; 391557afdd9SGao Xiang 392557afdd9SGao Xiang extern const struct inode_operations erofs_generic_iops; 393557afdd9SGao Xiang extern const struct inode_operations erofs_symlink_iops; 394557afdd9SGao Xiang extern const struct inode_operations erofs_fast_symlink_iops; 395557afdd9SGao Xiang extern const struct inode_operations erofs_dir_iops; 396557afdd9SGao Xiang 397a08e67a0SHuang Jianan extern const struct file_operations erofs_file_fops; 398557afdd9SGao Xiang extern const struct file_operations erofs_dir_fops; 399557afdd9SGao Xiang 400557afdd9SGao Xiang extern const struct iomap_ops z_erofs_iomap_report_ops; 401557afdd9SGao Xiang 402557afdd9SGao Xiang /* flags for erofs_fscache_register_cookie() */ 40361fef989SJingbo Xu #define EROFS_REG_COOKIE_SHARE 0x0001 40461fef989SJingbo Xu #define EROFS_REG_COOKIE_NEED_NOEXIST 0x0002 405557afdd9SGao Xiang 4069e382914SJingbo Xu void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, 4079e382914SJingbo Xu erofs_off_t *offset, int *lengthp); 40809c54379SGao Xiang void erofs_unmap_metabuf(struct erofs_buf *buf); 409c521e3adSGao Xiang void erofs_put_metabuf(struct erofs_buf *buf); 410eb2c5e41SGao Xiang void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, 411eb2c5e41SGao Xiang enum erofs_kmap_type type); 412eb2c5e41SGao Xiang void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb); 413c521e3adSGao Xiang void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, 414c521e3adSGao Xiang erofs_blk_t blkaddr, enum erofs_kmap_type type); 415dfeab2e9SGao Xiang int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev); 416eadcd6b5SGao Xiang int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 417eadcd6b5SGao Xiang u64 start, u64 len); 4188b58f9f0SJingbo Xu int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map); 419312fe643SGao Xiang struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid); 420b74d24f7SChristian Brauner int erofs_getattr(struct mnt_idmap *idmap, const struct path *path, 421549c7297SChristian Brauner struct kstat *stat, u32 request_mask, 422549c7297SChristian Brauner unsigned int query_flags); 4233e917cc3SHongnan Li int erofs_namei(struct inode *dir, const struct qstr *name, 42447e4937aSGao Xiang erofs_nid_t *nid, unsigned int *d_type); 42547e4937aSGao Xiang 426598162d0SGao Xiang static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count) 427598162d0SGao Xiang { 428598162d0SGao Xiang int retried = 0; 429598162d0SGao Xiang 430598162d0SGao Xiang while (1) { 431598162d0SGao Xiang void *p = vm_map_ram(pages, count, -1); 432598162d0SGao Xiang 433598162d0SGao Xiang /* retry two more times (totally 3 times) */ 434598162d0SGao Xiang if (p || ++retried >= 3) 435598162d0SGao Xiang return p; 436598162d0SGao Xiang vm_unmap_aliases(); 437598162d0SGao Xiang } 438598162d0SGao Xiang return NULL; 439598162d0SGao Xiang } 440598162d0SGao Xiang 441168e9a76SHuang Jianan int erofs_register_sysfs(struct super_block *sb); 442168e9a76SHuang Jianan void erofs_unregister_sysfs(struct super_block *sb); 443168e9a76SHuang Jianan int __init erofs_init_sysfs(void); 444168e9a76SHuang Jianan void erofs_exit_sysfs(void); 445168e9a76SHuang Jianan 446eaa9172aSGao Xiang struct page *erofs_allocpage(struct page **pagepool, gfp_t gfp); 447557afdd9SGao Xiang static inline void erofs_pagepool_add(struct page **pagepool, struct page *page) 448eaa9172aSGao Xiang { 449eaa9172aSGao Xiang set_page_private(page, (unsigned long)*pagepool); 450eaa9172aSGao Xiang *pagepool = page; 451eaa9172aSGao Xiang } 452eaa9172aSGao Xiang void erofs_release_pages(struct page **pagepool); 45347e4937aSGao Xiang 45447e4937aSGao Xiang #ifdef CONFIG_EROFS_FS_ZIP 455*7674a42fSGao Xiang void erofs_workgroup_put(struct erofs_workgroup *grp); 45647e4937aSGao Xiang struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb, 457997626d8SVladimir Zapolskiy pgoff_t index); 45864094a04SGao Xiang struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb, 459e5e9a432SVladimir Zapolskiy struct erofs_workgroup *grp); 46047e4937aSGao Xiang void erofs_workgroup_free_rcu(struct erofs_workgroup *grp); 46147e4937aSGao Xiang void erofs_shrinker_register(struct super_block *sb); 46247e4937aSGao Xiang void erofs_shrinker_unregister(struct super_block *sb); 46347e4937aSGao Xiang int __init erofs_init_shrinker(void); 46447e4937aSGao Xiang void erofs_exit_shrinker(void); 46547e4937aSGao Xiang int __init z_erofs_init_zip_subsystem(void); 46647e4937aSGao Xiang void z_erofs_exit_zip_subsystem(void); 46747e4937aSGao Xiang int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi, 46847e4937aSGao Xiang struct erofs_workgroup *egrp); 4695d50538fSHuang Jianan int z_erofs_load_lz4_config(struct super_block *sb, 47046249cdeSGao Xiang struct erofs_super_block *dsb, 47146249cdeSGao Xiang struct z_erofs_lz4_cfgs *lz4, int len); 472557afdd9SGao Xiang int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map, 473557afdd9SGao Xiang int flags); 474285d0f85SYue Hu void *erofs_get_pcpubuf(unsigned int requiredpages); 475285d0f85SYue Hu void erofs_put_pcpubuf(void *ptr); 476285d0f85SYue Hu int erofs_pcpubuf_growsize(unsigned int nrpages); 477285d0f85SYue Hu void __init erofs_pcpubuf_init(void); 478285d0f85SYue Hu void erofs_pcpubuf_exit(void); 4797b4e372cSGao Xiang int erofs_init_managed_cache(struct super_block *sb); 48047e4937aSGao Xiang #else 48147e4937aSGao Xiang static inline void erofs_shrinker_register(struct super_block *sb) {} 48247e4937aSGao Xiang static inline void erofs_shrinker_unregister(struct super_block *sb) {} 48347e4937aSGao Xiang static inline int erofs_init_shrinker(void) { return 0; } 48447e4937aSGao Xiang static inline void erofs_exit_shrinker(void) {} 48547e4937aSGao Xiang static inline int z_erofs_init_zip_subsystem(void) { return 0; } 48647e4937aSGao Xiang static inline void z_erofs_exit_zip_subsystem(void) {} 4875d50538fSHuang Jianan static inline int z_erofs_load_lz4_config(struct super_block *sb, 48846249cdeSGao Xiang struct erofs_super_block *dsb, 48946249cdeSGao Xiang struct z_erofs_lz4_cfgs *lz4, int len) 4905d50538fSHuang Jianan { 49114373711SGao Xiang if (lz4 || dsb->u1.lz4_max_distance) { 4925d50538fSHuang Jianan erofs_err(sb, "lz4 algorithm isn't enabled"); 4935d50538fSHuang Jianan return -EINVAL; 4945d50538fSHuang Jianan } 4955d50538fSHuang Jianan return 0; 4965d50538fSHuang Jianan } 497285d0f85SYue Hu static inline void erofs_pcpubuf_init(void) {} 498285d0f85SYue Hu static inline void erofs_pcpubuf_exit(void) {} 4997b4e372cSGao Xiang static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; } 50047e4937aSGao Xiang #endif /* !CONFIG_EROFS_FS_ZIP */ 50147e4937aSGao Xiang 502622ceaddSGao Xiang #ifdef CONFIG_EROFS_FS_ZIP_LZMA 503a279adedSYangtao Li int __init z_erofs_lzma_init(void); 504622ceaddSGao Xiang void z_erofs_lzma_exit(void); 505622ceaddSGao Xiang int z_erofs_load_lzma_config(struct super_block *sb, 506622ceaddSGao Xiang struct erofs_super_block *dsb, 507622ceaddSGao Xiang struct z_erofs_lzma_cfgs *lzma, int size); 508622ceaddSGao Xiang #else 509622ceaddSGao Xiang static inline int z_erofs_lzma_init(void) { return 0; } 510622ceaddSGao Xiang static inline int z_erofs_lzma_exit(void) { return 0; } 511622ceaddSGao Xiang static inline int z_erofs_load_lzma_config(struct super_block *sb, 512622ceaddSGao Xiang struct erofs_super_block *dsb, 513622ceaddSGao Xiang struct z_erofs_lzma_cfgs *lzma, int size) { 514622ceaddSGao Xiang if (lzma) { 515622ceaddSGao Xiang erofs_err(sb, "lzma algorithm isn't enabled"); 516622ceaddSGao Xiang return -EINVAL; 517622ceaddSGao Xiang } 518622ceaddSGao Xiang return 0; 519622ceaddSGao Xiang } 520557afdd9SGao Xiang #endif /* !CONFIG_EROFS_FS_ZIP_LZMA */ 521622ceaddSGao Xiang 522c6be2bd0SJeffle Xu #ifdef CONFIG_EROFS_FS_ONDEMAND 523c6be2bd0SJeffle Xu int erofs_fscache_register_fs(struct super_block *sb); 524c6be2bd0SJeffle Xu void erofs_fscache_unregister_fs(struct super_block *sb); 525b02c602fSJeffle Xu 526e1de2da0SJia Zhu struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, 527557afdd9SGao Xiang char *name, unsigned int flags); 528e1de2da0SJia Zhu void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); 529c6be2bd0SJeffle Xu #else 530c6be2bd0SJeffle Xu static inline int erofs_fscache_register_fs(struct super_block *sb) 531c6be2bd0SJeffle Xu { 532e1de2da0SJia Zhu return -EOPNOTSUPP; 533c6be2bd0SJeffle Xu } 534c6be2bd0SJeffle Xu static inline void erofs_fscache_unregister_fs(struct super_block *sb) {} 535b02c602fSJeffle Xu 536e1de2da0SJia Zhu static inline 537e1de2da0SJia Zhu struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, 538557afdd9SGao Xiang char *name, unsigned int flags) 539b02c602fSJeffle Xu { 540e1de2da0SJia Zhu return ERR_PTR(-EOPNOTSUPP); 541b02c602fSJeffle Xu } 542b02c602fSJeffle Xu 543e1de2da0SJia Zhu static inline void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache) 544b02c602fSJeffle Xu { 545b02c602fSJeffle Xu } 546c6be2bd0SJeffle Xu #endif 547c6be2bd0SJeffle Xu 54847e4937aSGao Xiang #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 54947e4937aSGao Xiang 55047e4937aSGao Xiang #endif /* __EROFS_INTERNAL_H */ 551