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