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 | c5aa903 | 2021-08-20 18:00:19 +0800 | [diff] [blame] | 5 | * Copyright (C) 2021, Alibaba Cloud |
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> |
Gao Xiang | 47e4937 | 2019-08-23 05:36:59 +0800 | [diff] [blame] | 15 | #include <linux/magic.h> |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 16 | #include <linux/slab.h> |
| 17 | #include <linux/vmalloc.h> |
Gao Xiang | eadcd6b | 2021-08-13 13:29:31 +0800 | [diff] [blame] | 18 | #include <linux/iomap.h> |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 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 | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 34 | #define DBG_BUGON BUG_ON |
| 35 | #else |
Gao Xiang | eef1687 | 2018-11-23 01:15:59 +0800 | [diff] [blame] | 36 | #define DBG_BUGON(x) ((void)(x)) |
Gao Xiang | 14f362b | 2019-07-31 23:57:36 +0800 | [diff] [blame] | 37 | #endif /* !CONFIG_EROFS_FS_DEBUG */ |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 38 | |
| 39 | /* EROFS_SUPER_MAGIC_V1 to represent the whole file system */ |
| 40 | #define EROFS_SUPER_MAGIC EROFS_SUPER_MAGIC_V1 |
| 41 | |
| 42 | typedef u64 erofs_nid_t; |
Gao Xiang | 14f362b | 2019-07-31 23:57:36 +0800 | [diff] [blame] | 43 | typedef u64 erofs_off_t; |
| 44 | /* data type for filesystem-wide blocks number */ |
| 45 | typedef u32 erofs_blk_t; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 46 | |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 47 | struct erofs_device_info { |
| 48 | char *path; |
Jeffle Xu | 955b478 | 2022-04-25 20:21:38 +0800 | [diff] [blame] | 49 | struct erofs_fscache *fscache; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 50 | struct block_device *bdev; |
| 51 | struct dax_device *dax_dev; |
Christoph Hellwig | cd913c7 | 2021-11-29 11:21:59 +0100 | [diff] [blame] | 52 | u64 dax_part_off; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 53 | |
| 54 | u32 blocks; |
| 55 | u32 mapped_blkaddr; |
| 56 | }; |
| 57 | |
Huang Jianan | 40452ff | 2021-12-06 22:35:52 +0800 | [diff] [blame] | 58 | enum { |
| 59 | EROFS_SYNC_DECOMPRESS_AUTO, |
| 60 | EROFS_SYNC_DECOMPRESS_FORCE_ON, |
| 61 | EROFS_SYNC_DECOMPRESS_FORCE_OFF |
| 62 | }; |
| 63 | |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 64 | struct erofs_mount_opts { |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 65 | #ifdef CONFIG_EROFS_FS_ZIP |
| 66 | /* current strategy of how to use managed cache */ |
| 67 | unsigned char cache_strategy; |
Huang Jianan | 40452ff | 2021-12-06 22:35:52 +0800 | [diff] [blame] | 68 | /* strategy of sync decompression (0 - auto, 1 - force on, 2 - force off) */ |
| 69 | unsigned int sync_decompress; |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 70 | |
| 71 | /* threshold for decompression synchronously */ |
| 72 | unsigned int max_sync_decompress_pages; |
| 73 | #endif |
| 74 | unsigned int mount_opt; |
| 75 | }; |
| 76 | |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 77 | struct erofs_dev_context { |
| 78 | struct idr tree; |
| 79 | struct rw_semaphore rwsem; |
| 80 | |
| 81 | unsigned int extra_devices; |
Jia Zhu | 8b465fe | 2023-03-02 15:17:51 +0800 | [diff] [blame] | 82 | bool flatdev; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 83 | }; |
| 84 | |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 85 | struct erofs_fs_context { |
| 86 | struct erofs_mount_opts opt; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 87 | struct erofs_dev_context *devs; |
Jingbo Xu | 39bfcb8 | 2022-10-21 10:31:53 +0800 | [diff] [blame] | 88 | char *fsid; |
| 89 | char *domain_id; |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 90 | }; |
| 91 | |
Huang Jianan | 5d50538 | 2021-03-29 09:23:06 +0800 | [diff] [blame] | 92 | /* all filesystem-wide lz4 configurations */ |
| 93 | struct erofs_sb_lz4_info { |
| 94 | /* # of pages needed for EROFS lz4 rolling decompression */ |
| 95 | u16 max_distance_pages; |
Gao Xiang | 4fea63f | 2021-04-07 12:39:23 +0800 | [diff] [blame] | 96 | /* maximum possible blocks for pclusters in the filesystem */ |
| 97 | u16 max_pclusterblks; |
Huang Jianan | 5d50538 | 2021-03-29 09:23:06 +0800 | [diff] [blame] | 98 | }; |
| 99 | |
Jia Zhu | 8b7adf1 | 2022-09-18 12:34:53 +0800 | [diff] [blame] | 100 | struct erofs_domain { |
| 101 | refcount_t ref; |
| 102 | struct list_head list; |
| 103 | struct fscache_volume *volume; |
| 104 | char *domain_id; |
| 105 | }; |
| 106 | |
Jeffle Xu | b02c602 | 2022-04-25 20:21:34 +0800 | [diff] [blame] | 107 | struct erofs_fscache { |
| 108 | struct fscache_cookie *cookie; |
Jingbo Xu | 61fef98 | 2023-02-09 14:39:13 +0800 | [diff] [blame] | 109 | struct inode *inode; /* anonymous inode for the blob */ |
Jingbo Xu | 2dfb8c3 | 2023-02-09 14:39:11 +0800 | [diff] [blame] | 110 | |
| 111 | /* used for share domain mode */ |
Jia Zhu | 7d41963 | 2022-09-18 19:01:50 +0800 | [diff] [blame] | 112 | struct erofs_domain *domain; |
Jingbo Xu | 2dfb8c3 | 2023-02-09 14:39:11 +0800 | [diff] [blame] | 113 | struct list_head node; |
| 114 | refcount_t ref; |
Jia Zhu | 7d41963 | 2022-09-18 19:01:50 +0800 | [diff] [blame] | 115 | char *name; |
Jeffle Xu | b02c602 | 2022-04-25 20:21:34 +0800 | [diff] [blame] | 116 | }; |
| 117 | |
Jingbo Xu | 9e38291 | 2023-04-07 22:17:08 +0800 | [diff] [blame] | 118 | struct erofs_xattr_prefix_item { |
| 119 | struct erofs_xattr_long_prefix *prefix; |
| 120 | u8 infix_len; |
| 121 | }; |
| 122 | |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 123 | struct erofs_sb_info { |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 124 | struct erofs_mount_opts opt; /* options */ |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 125 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 2497ee4 | 2018-07-26 20:22:03 +0800 | [diff] [blame] | 126 | /* list for all registered superblocks, mainly for shrinker */ |
| 127 | struct list_head list; |
Gao Xiang | a158131 | 2018-07-26 20:22:04 +0800 | [diff] [blame] | 128 | struct mutex umount_mutex; |
Gao Xiang | 2497ee4 | 2018-07-26 20:22:03 +0800 | [diff] [blame] | 129 | |
Gao Xiang | 64094a0 | 2020-02-20 10:46:42 +0800 | [diff] [blame] | 130 | /* managed XArray arranged in physical block number */ |
| 131 | struct xarray managed_pslots; |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 132 | |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 133 | unsigned int shrinker_run_no; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 134 | u16 available_compr_algs; |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 135 | |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 136 | /* pseudo inode to manage cached pages */ |
| 137 | struct inode *managed_cache; |
Huang Jianan | 5d50538 | 2021-03-29 09:23:06 +0800 | [diff] [blame] | 138 | |
| 139 | struct erofs_sb_lz4_info lz4; |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 140 | #endif /* CONFIG_EROFS_FS_ZIP */ |
Jingbo Xu | a97a218 | 2023-04-07 22:17:06 +0800 | [diff] [blame] | 141 | struct inode *packed_inode; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 142 | struct erofs_dev_context *devs; |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 143 | struct dax_device *dax_dev; |
Christoph Hellwig | cd913c7 | 2021-11-29 11:21:59 +0100 | [diff] [blame] | 144 | u64 dax_part_off; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 145 | u64 total_blocks; |
| 146 | u32 primarydevice_blocks; |
| 147 | |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 148 | u32 meta_blkaddr; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 149 | #ifdef CONFIG_EROFS_FS_XATTR |
| 150 | u32 xattr_blkaddr; |
Jingbo Xu | 9e38291 | 2023-04-07 22:17:08 +0800 | [diff] [blame] | 151 | u32 xattr_prefix_start; |
| 152 | u8 xattr_prefix_count; |
| 153 | struct erofs_xattr_prefix_item *xattr_prefixes; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 154 | #endif |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 155 | u16 device_id_mask; /* valid bits of device id to be used */ |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 156 | |
Jingbo Xu | 3acea5f | 2023-03-13 21:53:08 +0800 | [diff] [blame] | 157 | unsigned char islotbits; /* inode slot unit size in bit shift */ |
Jingbo Xu | d3c4bdc | 2023-03-13 21:53:09 +0800 | [diff] [blame] | 158 | unsigned char blkszbits; /* filesystem block size in bit shift */ |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 159 | |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 160 | u32 sb_size; /* total superblock size */ |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 161 | u32 build_time_nsec; |
| 162 | u64 build_time; |
| 163 | |
| 164 | /* what we really care is nid, rather than ino.. */ |
| 165 | erofs_nid_t root_nid; |
Jingbo Xu | cb9bce7 | 2023-04-07 22:17:05 +0800 | [diff] [blame] | 166 | erofs_nid_t packed_nid; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 167 | /* used for statfs, f_files - f_favail */ |
| 168 | u64 inos; |
| 169 | |
| 170 | u8 uuid[16]; /* 128-bit uuid for volume */ |
| 171 | u8 volume_name[16]; /* volume name */ |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 172 | u32 feature_compat; |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 173 | u32 feature_incompat; |
Huang Jianan | 168e9a7 | 2021-12-01 22:54:36 +0800 | [diff] [blame] | 174 | |
| 175 | /* sysfs support */ |
| 176 | struct kobject s_kobj; /* /sys/fs/erofs/<devname> */ |
| 177 | struct completion s_kobj_unregister; |
Jeffle Xu | c6be2bd | 2022-04-25 20:21:33 +0800 | [diff] [blame] | 178 | |
| 179 | /* fscache support */ |
| 180 | struct fscache_volume *volume; |
Jeffle Xu | 37c90c5 | 2022-04-25 20:21:37 +0800 | [diff] [blame] | 181 | struct erofs_fscache *s_fscache; |
Jia Zhu | 8b7adf1 | 2022-09-18 12:34:53 +0800 | [diff] [blame] | 182 | struct erofs_domain *domain; |
Jingbo Xu | 39bfcb8 | 2022-10-21 10:31:53 +0800 | [diff] [blame] | 183 | char *fsid; |
| 184 | char *domain_id; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info) |
| 188 | #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info) |
| 189 | |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 190 | /* Mount flags set via mount options or defaults */ |
| 191 | #define EROFS_MOUNT_XATTR_USER 0x00000010 |
| 192 | #define EROFS_MOUNT_POSIX_ACL 0x00000020 |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 193 | #define EROFS_MOUNT_DAX_ALWAYS 0x00000040 |
| 194 | #define EROFS_MOUNT_DAX_NEVER 0x00000080 |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 195 | |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 196 | #define clear_opt(opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option) |
| 197 | #define set_opt(opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option) |
| 198 | #define test_opt(opt, option) ((opt)->mount_opt & EROFS_MOUNT_##option) |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 199 | |
Jeffle Xu | 93b856b | 2022-04-25 20:21:32 +0800 | [diff] [blame] | 200 | static inline bool erofs_is_fscache_mode(struct super_block *sb) |
| 201 | { |
| 202 | return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !sb->s_bdev; |
| 203 | } |
| 204 | |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 205 | enum { |
| 206 | EROFS_ZIP_CACHE_DISABLED, |
| 207 | EROFS_ZIP_CACHE_READAHEAD, |
| 208 | EROFS_ZIP_CACHE_READAROUND |
| 209 | }; |
| 210 | |
Gao Xiang | 14f362b | 2019-07-31 23:57:36 +0800 | [diff] [blame] | 211 | #define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL) |
| 212 | |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 213 | /* basic unit of the workstation of a super_block */ |
| 214 | struct erofs_workgroup { |
| 215 | /* the workgroup index in the workstation */ |
| 216 | pgoff_t index; |
| 217 | |
| 218 | /* overall workgroup reference count */ |
| 219 | atomic_t refcount; |
| 220 | }; |
| 221 | |
Gao Xiang | 73f5c66 | 2018-11-23 01:16:02 +0800 | [diff] [blame] | 222 | static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp, |
| 223 | int val) |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 224 | { |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 225 | preempt_disable(); |
Gao Xiang | 73f5c66 | 2018-11-23 01:16:02 +0800 | [diff] [blame] | 226 | if (val != atomic_cmpxchg(&grp->refcount, val, EROFS_LOCKED_MAGIC)) { |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 227 | preempt_enable(); |
| 228 | return false; |
| 229 | } |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 230 | return true; |
| 231 | } |
| 232 | |
Gao Xiang | 73f5c66 | 2018-11-23 01:16:02 +0800 | [diff] [blame] | 233 | static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp, |
| 234 | int orig_val) |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 235 | { |
Gao Xiang | 948bbdb | 2018-11-23 01:16:03 +0800 | [diff] [blame] | 236 | /* |
| 237 | * other observers should notice all modifications |
| 238 | * in the freezing period. |
| 239 | */ |
| 240 | smp_mb(); |
Gao Xiang | 73f5c66 | 2018-11-23 01:16:02 +0800 | [diff] [blame] | 241 | atomic_set(&grp->refcount, orig_val); |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 242 | preempt_enable(); |
| 243 | } |
| 244 | |
Gao Xiang | df134b8 | 2018-11-23 01:16:01 +0800 | [diff] [blame] | 245 | static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp) |
| 246 | { |
| 247 | return atomic_cond_read_relaxed(&grp->refcount, |
| 248 | VAL != EROFS_LOCKED_MAGIC); |
| 249 | } |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 250 | |
Gao Xiang | fdf80a4 | 2022-01-02 12:00:13 +0800 | [diff] [blame] | 251 | enum erofs_kmap_type { |
| 252 | EROFS_NO_KMAP, /* don't map the buffer */ |
Gao Xiang | 927e501 | 2022-10-18 18:53:13 +0800 | [diff] [blame] | 253 | EROFS_KMAP, /* use kmap_local_page() to map the buffer */ |
Gao Xiang | fdf80a4 | 2022-01-02 12:00:13 +0800 | [diff] [blame] | 254 | }; |
| 255 | |
| 256 | struct erofs_buf { |
Gao Xiang | eb2c5e4 | 2023-04-07 22:17:04 +0800 | [diff] [blame] | 257 | struct inode *inode; |
Gao Xiang | fdf80a4 | 2022-01-02 12:00:13 +0800 | [diff] [blame] | 258 | struct page *page; |
| 259 | void *base; |
| 260 | enum erofs_kmap_type kmap_type; |
| 261 | }; |
| 262 | #define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL }) |
| 263 | |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 264 | #define ROOT_NID(sb) ((sb)->root_nid) |
| 265 | |
Jingbo Xu | 3acea5f | 2023-03-13 21:53:08 +0800 | [diff] [blame] | 266 | #define erofs_blknr(sb, addr) ((addr) >> (sb)->s_blocksize_bits) |
| 267 | #define erofs_blkoff(sb, addr) ((addr) & ((sb)->s_blocksize - 1)) |
| 268 | #define erofs_pos(sb, blk) ((erofs_off_t)(blk) << (sb)->s_blocksize_bits) |
| 269 | #define erofs_iblks(i) (round_up((i)->i_size, i_blocksize(i)) >> (i)->i_blkbits) |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 270 | |
Gao Xiang | de06a6a | 2021-03-29 09:23:05 +0800 | [diff] [blame] | 271 | #define EROFS_FEATURE_FUNCS(name, compat, feature) \ |
| 272 | static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \ |
| 273 | { \ |
| 274 | return sbi->feature_##compat & EROFS_FEATURE_##feature; \ |
| 275 | } |
| 276 | |
Huang Jianan | 7e508f2 | 2021-11-13 00:09:33 +0800 | [diff] [blame] | 277 | EROFS_FEATURE_FUNCS(zero_padding, incompat, INCOMPAT_ZERO_PADDING) |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 278 | EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS) |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 279 | EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER) |
Huang Jianan | 168e9a7 | 2021-12-01 22:54:36 +0800 | [diff] [blame] | 280 | EROFS_FEATURE_FUNCS(chunked_file, incompat, INCOMPAT_CHUNKED_FILE) |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 281 | EROFS_FEATURE_FUNCS(device_table, incompat, INCOMPAT_DEVICE_TABLE) |
Huang Jianan | 168e9a7 | 2021-12-01 22:54:36 +0800 | [diff] [blame] | 282 | EROFS_FEATURE_FUNCS(compr_head2, incompat, INCOMPAT_COMPR_HEAD2) |
Yue Hu | ab92184 | 2021-12-28 13:46:04 +0800 | [diff] [blame] | 283 | EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING) |
Yue Hu | b15b2e3 | 2022-09-23 10:11:22 +0800 | [diff] [blame] | 284 | EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS) |
Gao Xiang | 5c2a642 | 2022-09-23 09:49:15 +0800 | [diff] [blame] | 285 | EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE) |
Jingbo Xu | 6a318cc | 2023-04-08 06:28:08 +0800 | [diff] [blame] | 286 | EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES) |
Gao Xiang | de06a6a | 2021-03-29 09:23:05 +0800 | [diff] [blame] | 287 | EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) |
| 288 | |
Gao Xiang | 62dc459 | 2019-02-18 15:19:04 +0800 | [diff] [blame] | 289 | /* atomic flag definitions */ |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 290 | #define EROFS_I_EA_INITED_BIT 0 |
| 291 | #define EROFS_I_Z_INITED_BIT 1 |
Gao Xiang | 62dc459 | 2019-02-18 15:19:04 +0800 | [diff] [blame] | 292 | |
| 293 | /* bitlock definitions (arranged in reverse order) */ |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 294 | #define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1) |
| 295 | #define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2) |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 296 | |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 297 | struct erofs_inode { |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 298 | erofs_nid_t nid; |
Gao Xiang | 62dc459 | 2019-02-18 15:19:04 +0800 | [diff] [blame] | 299 | |
| 300 | /* atomic flags (including bitlocks) */ |
| 301 | unsigned long flags; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 302 | |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 303 | unsigned char datalayout; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 304 | unsigned char inode_isize; |
Jingbo Xu | 1b3567a | 2023-04-14 14:18:10 +0800 | [diff] [blame] | 305 | unsigned int xattr_isize; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 306 | |
Pratik Shinde | e82a9a1 | 2019-07-15 17:51:27 +0530 | [diff] [blame] | 307 | unsigned int xattr_shared_count; |
| 308 | unsigned int *xattr_shared_xattrs; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 309 | |
Gao Xiang | 152a333 | 2019-06-24 15:22:52 +0800 | [diff] [blame] | 310 | union { |
| 311 | erofs_blk_t raw_blkaddr; |
Gao Xiang | c5aa903 | 2021-08-20 18:00:19 +0800 | [diff] [blame] | 312 | struct { |
| 313 | unsigned short chunkformat; |
| 314 | unsigned char chunkbits; |
| 315 | }; |
Gao Xiang | 152a333 | 2019-06-24 15:22:52 +0800 | [diff] [blame] | 316 | #ifdef CONFIG_EROFS_FS_ZIP |
| 317 | struct { |
| 318 | unsigned short z_advise; |
| 319 | unsigned char z_algorithmtype[2]; |
| 320 | unsigned char z_logical_clusterbits; |
Yue Hu | ab92184 | 2021-12-28 13:46:04 +0800 | [diff] [blame] | 321 | unsigned long z_tailextent_headlcn; |
Yue Hu | b15b2e3 | 2022-09-23 10:11:22 +0800 | [diff] [blame] | 322 | union { |
| 323 | struct { |
| 324 | erofs_off_t z_idataoff; |
| 325 | unsigned short z_idata_size; |
| 326 | }; |
| 327 | erofs_off_t z_fragmentoff; |
| 328 | }; |
Gao Xiang | 152a333 | 2019-06-24 15:22:52 +0800 | [diff] [blame] | 329 | }; |
Gao Xiang | 14f362b | 2019-07-31 23:57:36 +0800 | [diff] [blame] | 330 | #endif /* CONFIG_EROFS_FS_ZIP */ |
Gao Xiang | 152a333 | 2019-06-24 15:22:52 +0800 | [diff] [blame] | 331 | }; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 332 | /* the corresponding vfs inode */ |
| 333 | struct inode vfs_inode; |
| 334 | }; |
| 335 | |
Gao Xiang | b780d3f | 2023-01-14 23:08:23 +0800 | [diff] [blame] | 336 | #define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode) |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 337 | |
Gao Xiang | b780d3f | 2023-01-14 23:08:23 +0800 | [diff] [blame] | 338 | static inline erofs_off_t erofs_iloc(struct inode *inode) |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 339 | { |
Gao Xiang | b780d3f | 2023-01-14 23:08:23 +0800 | [diff] [blame] | 340 | struct erofs_sb_info *sbi = EROFS_I_SB(inode); |
| 341 | |
Jingbo Xu | 3acea5f | 2023-03-13 21:53:08 +0800 | [diff] [blame] | 342 | return erofs_pos(inode->i_sb, sbi->meta_blkaddr) + |
Gao Xiang | b780d3f | 2023-01-14 23:08:23 +0800 | [diff] [blame] | 343 | (EROFS_I(inode)->nid << sbi->islotbits); |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 344 | } |
| 345 | |
Gao Xiang | 745ed7d | 2023-04-14 16:30:27 +0800 | [diff] [blame] | 346 | static inline unsigned int erofs_inode_version(unsigned int ifmt) |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 347 | { |
Gao Xiang | 745ed7d | 2023-04-14 16:30:27 +0800 | [diff] [blame] | 348 | return (ifmt >> EROFS_I_VERSION_BIT) & EROFS_I_VERSION_MASK; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 349 | } |
| 350 | |
Gao Xiang | 745ed7d | 2023-04-14 16:30:27 +0800 | [diff] [blame] | 351 | static inline unsigned int erofs_inode_datalayout(unsigned int ifmt) |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 352 | { |
Gao Xiang | 745ed7d | 2023-04-14 16:30:27 +0800 | [diff] [blame] | 353 | return (ifmt >> EROFS_I_DATALAYOUT_BIT) & EROFS_I_DATALAYOUT_MASK; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 354 | } |
| 355 | |
Gao Xiang | 3862929 | 2021-10-09 04:08:39 +0800 | [diff] [blame] | 356 | /* |
| 357 | * Different from grab_cache_page_nowait(), reclaiming is never triggered |
| 358 | * when allocating new pages. |
| 359 | */ |
| 360 | static inline |
| 361 | struct page *erofs_grab_cache_page_nowait(struct address_space *mapping, |
| 362 | pgoff_t index) |
| 363 | { |
| 364 | return pagecache_get_page(mapping, index, |
| 365 | FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT, |
| 366 | readahead_gfp_mask(mapping) & ~__GFP_RECLAIM); |
| 367 | } |
| 368 | |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 369 | /* Has a disk mapping */ |
Gao Xiang | 768bb10 | 2023-01-13 14:52:26 +0800 | [diff] [blame] | 370 | #define EROFS_MAP_MAPPED 0x0001 |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 371 | /* Located in metadata (could be copied from bd_inode) */ |
Gao Xiang | 768bb10 | 2023-01-13 14:52:26 +0800 | [diff] [blame] | 372 | #define EROFS_MAP_META 0x0002 |
Gao Xiang | 8f89926 | 2021-10-09 04:08:37 +0800 | [diff] [blame] | 373 | /* The extent is encoded */ |
Gao Xiang | 768bb10 | 2023-01-13 14:52:26 +0800 | [diff] [blame] | 374 | #define EROFS_MAP_ENCODED 0x0004 |
Gao Xiang | b6a7618 | 2019-06-24 15:22:58 +0800 | [diff] [blame] | 375 | /* The length of extent is full */ |
Gao Xiang | 768bb10 | 2023-01-13 14:52:26 +0800 | [diff] [blame] | 376 | #define EROFS_MAP_FULL_MAPPED 0x0008 |
Yue Hu | b15b2e3 | 2022-09-23 10:11:22 +0800 | [diff] [blame] | 377 | /* Located in the special packed inode */ |
Gao Xiang | 768bb10 | 2023-01-13 14:52:26 +0800 | [diff] [blame] | 378 | #define EROFS_MAP_FRAGMENT 0x0010 |
Gao Xiang | 5c2a642 | 2022-09-23 09:49:15 +0800 | [diff] [blame] | 379 | /* The extent refers to partial decompressed data */ |
Gao Xiang | 768bb10 | 2023-01-13 14:52:26 +0800 | [diff] [blame] | 380 | #define EROFS_MAP_PARTIAL_REF 0x0020 |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 381 | |
| 382 | struct erofs_map_blocks { |
Gao Xiang | 09c5437 | 2022-01-02 12:00:17 +0800 | [diff] [blame] | 383 | struct erofs_buf buf; |
| 384 | |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 385 | erofs_off_t m_pa, m_la; |
| 386 | u64 m_plen, m_llen; |
| 387 | |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 388 | unsigned short m_deviceid; |
Gao Xiang | 8f89926 | 2021-10-09 04:08:37 +0800 | [diff] [blame] | 389 | char m_algorithmformat; |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 390 | unsigned int m_flags; |
| 391 | }; |
| 392 | |
Gao Xiang | d95ae5e | 2021-08-18 23:22:31 +0800 | [diff] [blame] | 393 | /* |
| 394 | * Used to get the exact decompressed length, e.g. fiemap (consider lookback |
| 395 | * approach instead if possible since it's more metadata lightweight.) |
| 396 | */ |
Jingbo Xu | 8b58f9f | 2023-02-09 10:48:25 +0800 | [diff] [blame] | 397 | #define EROFS_GET_BLOCKS_FIEMAP 0x0001 |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 398 | /* Used to map the whole extent if non-negligible data is requested for LZMA */ |
Jingbo Xu | 8b58f9f | 2023-02-09 10:48:25 +0800 | [diff] [blame] | 399 | #define EROFS_GET_BLOCKS_READMORE 0x0002 |
Yue Hu | b15b2e3 | 2022-09-23 10:11:22 +0800 | [diff] [blame] | 400 | /* Used to map tail extent for tailpacking inline or fragment pcluster */ |
Jingbo Xu | 8b58f9f | 2023-02-09 10:48:25 +0800 | [diff] [blame] | 401 | #define EROFS_GET_BLOCKS_FINDTAIL 0x0004 |
Gao Xiang | bfb8674 | 2018-07-26 20:21:45 +0800 | [diff] [blame] | 402 | |
Gao Xiang | 8f89926 | 2021-10-09 04:08:37 +0800 | [diff] [blame] | 403 | enum { |
| 404 | Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX, |
Yue Hu | fdffc09 | 2022-09-23 10:11:21 +0800 | [diff] [blame] | 405 | Z_EROFS_COMPRESSION_INTERLACED, |
Gao Xiang | 8f89926 | 2021-10-09 04:08:37 +0800 | [diff] [blame] | 406 | Z_EROFS_COMPRESSION_RUNTIME_MAX |
| 407 | }; |
| 408 | |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 409 | struct erofs_map_dev { |
Jeffle Xu | 955b478 | 2022-04-25 20:21:38 +0800 | [diff] [blame] | 410 | struct erofs_fscache *m_fscache; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 411 | struct block_device *m_bdev; |
| 412 | struct dax_device *m_daxdev; |
Christoph Hellwig | de20511 | 2021-11-29 11:22:00 +0100 | [diff] [blame] | 413 | u64 m_dax_part_off; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 414 | |
| 415 | erofs_off_t m_pa; |
| 416 | unsigned int m_deviceid; |
| 417 | }; |
| 418 | |
Gao Xiang | 557afdd | 2023-02-04 17:30:40 +0800 | [diff] [blame] | 419 | extern struct file_system_type erofs_fs_type; |
| 420 | extern const struct super_operations erofs_sops; |
| 421 | |
| 422 | extern const struct address_space_operations erofs_raw_access_aops; |
| 423 | extern const struct address_space_operations z_erofs_aops; |
| 424 | extern const struct address_space_operations erofs_fscache_access_aops; |
| 425 | |
| 426 | extern const struct inode_operations erofs_generic_iops; |
| 427 | extern const struct inode_operations erofs_symlink_iops; |
| 428 | extern const struct inode_operations erofs_fast_symlink_iops; |
| 429 | extern const struct inode_operations erofs_dir_iops; |
| 430 | |
Huang Jianan | a08e67a | 2021-08-05 08:35:59 +0800 | [diff] [blame] | 431 | extern const struct file_operations erofs_file_fops; |
Gao Xiang | 557afdd | 2023-02-04 17:30:40 +0800 | [diff] [blame] | 432 | extern const struct file_operations erofs_dir_fops; |
| 433 | |
| 434 | extern const struct iomap_ops z_erofs_iomap_report_ops; |
| 435 | |
| 436 | /* flags for erofs_fscache_register_cookie() */ |
Jingbo Xu | 61fef98 | 2023-02-09 14:39:13 +0800 | [diff] [blame] | 437 | #define EROFS_REG_COOKIE_SHARE 0x0001 |
| 438 | #define EROFS_REG_COOKIE_NEED_NOEXIST 0x0002 |
Gao Xiang | 557afdd | 2023-02-04 17:30:40 +0800 | [diff] [blame] | 439 | |
Jingbo Xu | 9e38291 | 2023-04-07 22:17:08 +0800 | [diff] [blame] | 440 | void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, |
| 441 | erofs_off_t *offset, int *lengthp); |
Gao Xiang | 09c5437 | 2022-01-02 12:00:17 +0800 | [diff] [blame] | 442 | void erofs_unmap_metabuf(struct erofs_buf *buf); |
Gao Xiang | c521e3a | 2022-01-02 12:00:14 +0800 | [diff] [blame] | 443 | void erofs_put_metabuf(struct erofs_buf *buf); |
Gao Xiang | eb2c5e4 | 2023-04-07 22:17:04 +0800 | [diff] [blame] | 444 | void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, |
| 445 | enum erofs_kmap_type type); |
| 446 | void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb); |
Gao Xiang | c521e3a | 2022-01-02 12:00:14 +0800 | [diff] [blame] | 447 | void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, |
| 448 | erofs_blk_t blkaddr, enum erofs_kmap_type type); |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 449 | int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev); |
Gao Xiang | eadcd6b | 2021-08-13 13:29:31 +0800 | [diff] [blame] | 450 | int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
| 451 | u64 start, u64 len); |
Jingbo Xu | 8b58f9f | 2023-02-09 10:48:25 +0800 | [diff] [blame] | 452 | int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map); |
Gao Xiang | 312fe64 | 2022-09-27 14:36:07 +0800 | [diff] [blame] | 453 | struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid); |
Christian Brauner | b74d24f | 2023-01-13 12:49:12 +0100 | [diff] [blame] | 454 | int erofs_getattr(struct mnt_idmap *idmap, const struct path *path, |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame] | 455 | struct kstat *stat, u32 request_mask, |
| 456 | unsigned int query_flags); |
Hongnan Li | 3e917cc | 2022-04-25 12:07:12 +0800 | [diff] [blame] | 457 | int erofs_namei(struct inode *dir, const struct qstr *name, |
Gao Xiang | 6093982 | 2019-01-14 19:40:24 +0800 | [diff] [blame] | 458 | erofs_nid_t *nid, unsigned int *d_type); |
| 459 | |
Gao Xiang | 598162d | 2021-04-07 12:39:26 +0800 | [diff] [blame] | 460 | static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count) |
| 461 | { |
| 462 | int retried = 0; |
| 463 | |
| 464 | while (1) { |
| 465 | void *p = vm_map_ram(pages, count, -1); |
| 466 | |
| 467 | /* retry two more times (totally 3 times) */ |
| 468 | if (p || ++retried >= 3) |
| 469 | return p; |
| 470 | vm_unmap_aliases(); |
| 471 | } |
| 472 | return NULL; |
| 473 | } |
| 474 | |
Huang Jianan | 168e9a7 | 2021-12-01 22:54:36 +0800 | [diff] [blame] | 475 | int erofs_register_sysfs(struct super_block *sb); |
| 476 | void erofs_unregister_sysfs(struct super_block *sb); |
| 477 | int __init erofs_init_sysfs(void); |
| 478 | void erofs_exit_sysfs(void); |
| 479 | |
Gao Xiang | eaa9172 | 2021-10-22 17:01:20 +0800 | [diff] [blame] | 480 | struct page *erofs_allocpage(struct page **pagepool, gfp_t gfp); |
Gao Xiang | 557afdd | 2023-02-04 17:30:40 +0800 | [diff] [blame] | 481 | static inline void erofs_pagepool_add(struct page **pagepool, struct page *page) |
Gao Xiang | eaa9172 | 2021-10-22 17:01:20 +0800 | [diff] [blame] | 482 | { |
| 483 | set_page_private(page, (unsigned long)*pagepool); |
| 484 | *pagepool = page; |
| 485 | } |
| 486 | void erofs_release_pages(struct page **pagepool); |
Gao Xiang | fa61a33 | 2019-06-24 15:22:53 +0800 | [diff] [blame] | 487 | |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 488 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 14f362b | 2019-07-31 23:57:36 +0800 | [diff] [blame] | 489 | int erofs_workgroup_put(struct erofs_workgroup *grp); |
| 490 | struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb, |
Vladimir Zapolskiy | 997626d | 2020-01-02 14:01:16 +0200 | [diff] [blame] | 491 | pgoff_t index); |
Gao Xiang | 64094a0 | 2020-02-20 10:46:42 +0800 | [diff] [blame] | 492 | struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb, |
| 493 | struct erofs_workgroup *grp); |
Gao Xiang | 14f362b | 2019-07-31 23:57:36 +0800 | [diff] [blame] | 494 | void erofs_workgroup_free_rcu(struct erofs_workgroup *grp); |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 495 | void erofs_shrinker_register(struct super_block *sb); |
| 496 | void erofs_shrinker_unregister(struct super_block *sb); |
| 497 | int __init erofs_init_shrinker(void); |
| 498 | void erofs_exit_shrinker(void); |
| 499 | int __init z_erofs_init_zip_subsystem(void); |
| 500 | void z_erofs_exit_zip_subsystem(void); |
Gao Xiang | 14f362b | 2019-07-31 23:57:36 +0800 | [diff] [blame] | 501 | int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi, |
| 502 | struct erofs_workgroup *egrp); |
Yue Hu | d252ff3 | 2021-08-10 15:24:16 +0800 | [diff] [blame] | 503 | int erofs_try_to_free_cached_page(struct page *page); |
Huang Jianan | 5d50538 | 2021-03-29 09:23:06 +0800 | [diff] [blame] | 504 | int z_erofs_load_lz4_config(struct super_block *sb, |
Gao Xiang | 46249cd | 2021-03-29 09:23:07 +0800 | [diff] [blame] | 505 | struct erofs_super_block *dsb, |
| 506 | struct z_erofs_lz4_cfgs *lz4, int len); |
Gao Xiang | 557afdd | 2023-02-04 17:30:40 +0800 | [diff] [blame] | 507 | int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map, |
| 508 | int flags); |
Yue Hu | 285d0f8 | 2023-05-15 17:57:58 +0800 | [diff] [blame] | 509 | void *erofs_get_pcpubuf(unsigned int requiredpages); |
| 510 | void erofs_put_pcpubuf(void *ptr); |
| 511 | int erofs_pcpubuf_growsize(unsigned int nrpages); |
| 512 | void __init erofs_pcpubuf_init(void); |
| 513 | void erofs_pcpubuf_exit(void); |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 514 | #else |
| 515 | static inline void erofs_shrinker_register(struct super_block *sb) {} |
| 516 | static inline void erofs_shrinker_unregister(struct super_block *sb) {} |
| 517 | static inline int erofs_init_shrinker(void) { return 0; } |
| 518 | static inline void erofs_exit_shrinker(void) {} |
| 519 | static inline int z_erofs_init_zip_subsystem(void) { return 0; } |
| 520 | static inline void z_erofs_exit_zip_subsystem(void) {} |
Huang Jianan | 5d50538 | 2021-03-29 09:23:06 +0800 | [diff] [blame] | 521 | static inline int z_erofs_load_lz4_config(struct super_block *sb, |
Gao Xiang | 46249cd | 2021-03-29 09:23:07 +0800 | [diff] [blame] | 522 | struct erofs_super_block *dsb, |
| 523 | struct z_erofs_lz4_cfgs *lz4, int len) |
Huang Jianan | 5d50538 | 2021-03-29 09:23:06 +0800 | [diff] [blame] | 524 | { |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 525 | if (lz4 || dsb->u1.lz4_max_distance) { |
Huang Jianan | 5d50538 | 2021-03-29 09:23:06 +0800 | [diff] [blame] | 526 | erofs_err(sb, "lz4 algorithm isn't enabled"); |
| 527 | return -EINVAL; |
| 528 | } |
| 529 | return 0; |
| 530 | } |
Yue Hu | 285d0f8 | 2023-05-15 17:57:58 +0800 | [diff] [blame] | 531 | static inline void erofs_pcpubuf_init(void) {} |
| 532 | static inline void erofs_pcpubuf_exit(void) {} |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 533 | #endif /* !CONFIG_EROFS_FS_ZIP */ |
Gao Xiang | 2e1d663 | 2019-01-16 16:59:56 +0800 | [diff] [blame] | 534 | |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 535 | #ifdef CONFIG_EROFS_FS_ZIP_LZMA |
Yangtao Li | a279aded | 2023-03-03 14:37:31 +0800 | [diff] [blame] | 536 | int __init z_erofs_lzma_init(void); |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 537 | void z_erofs_lzma_exit(void); |
| 538 | int z_erofs_load_lzma_config(struct super_block *sb, |
| 539 | struct erofs_super_block *dsb, |
| 540 | struct z_erofs_lzma_cfgs *lzma, int size); |
| 541 | #else |
| 542 | static inline int z_erofs_lzma_init(void) { return 0; } |
| 543 | static inline int z_erofs_lzma_exit(void) { return 0; } |
| 544 | static inline int z_erofs_load_lzma_config(struct super_block *sb, |
| 545 | struct erofs_super_block *dsb, |
| 546 | struct z_erofs_lzma_cfgs *lzma, int size) { |
| 547 | if (lzma) { |
| 548 | erofs_err(sb, "lzma algorithm isn't enabled"); |
| 549 | return -EINVAL; |
| 550 | } |
| 551 | return 0; |
| 552 | } |
Gao Xiang | 557afdd | 2023-02-04 17:30:40 +0800 | [diff] [blame] | 553 | #endif /* !CONFIG_EROFS_FS_ZIP_LZMA */ |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 554 | |
Jeffle Xu | c6be2bd | 2022-04-25 20:21:33 +0800 | [diff] [blame] | 555 | #ifdef CONFIG_EROFS_FS_ONDEMAND |
| 556 | int erofs_fscache_register_fs(struct super_block *sb); |
| 557 | void erofs_fscache_unregister_fs(struct super_block *sb); |
Jeffle Xu | b02c602 | 2022-04-25 20:21:34 +0800 | [diff] [blame] | 558 | |
Jia Zhu | e1de2da | 2022-09-18 12:34:52 +0800 | [diff] [blame] | 559 | struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, |
Gao Xiang | 557afdd | 2023-02-04 17:30:40 +0800 | [diff] [blame] | 560 | char *name, unsigned int flags); |
Jia Zhu | e1de2da | 2022-09-18 12:34:52 +0800 | [diff] [blame] | 561 | void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); |
Jeffle Xu | c6be2bd | 2022-04-25 20:21:33 +0800 | [diff] [blame] | 562 | #else |
| 563 | static inline int erofs_fscache_register_fs(struct super_block *sb) |
| 564 | { |
Jia Zhu | e1de2da | 2022-09-18 12:34:52 +0800 | [diff] [blame] | 565 | return -EOPNOTSUPP; |
Jeffle Xu | c6be2bd | 2022-04-25 20:21:33 +0800 | [diff] [blame] | 566 | } |
| 567 | static inline void erofs_fscache_unregister_fs(struct super_block *sb) {} |
Jeffle Xu | b02c602 | 2022-04-25 20:21:34 +0800 | [diff] [blame] | 568 | |
Jia Zhu | e1de2da | 2022-09-18 12:34:52 +0800 | [diff] [blame] | 569 | static inline |
| 570 | struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, |
Gao Xiang | 557afdd | 2023-02-04 17:30:40 +0800 | [diff] [blame] | 571 | char *name, unsigned int flags) |
Jeffle Xu | b02c602 | 2022-04-25 20:21:34 +0800 | [diff] [blame] | 572 | { |
Jia Zhu | e1de2da | 2022-09-18 12:34:52 +0800 | [diff] [blame] | 573 | return ERR_PTR(-EOPNOTSUPP); |
Jeffle Xu | b02c602 | 2022-04-25 20:21:34 +0800 | [diff] [blame] | 574 | } |
| 575 | |
Jia Zhu | e1de2da | 2022-09-18 12:34:52 +0800 | [diff] [blame] | 576 | static inline void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache) |
Jeffle Xu | b02c602 | 2022-04-25 20:21:34 +0800 | [diff] [blame] | 577 | { |
| 578 | } |
Jeffle Xu | c6be2bd | 2022-04-25 20:21:33 +0800 | [diff] [blame] | 579 | #endif |
| 580 | |
Gao Xiang | a6b9b1d | 2019-08-14 18:37:03 +0800 | [diff] [blame] | 581 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ |
| 582 | |
Gao Xiang | 14f362b | 2019-07-31 23:57:36 +0800 | [diff] [blame] | 583 | #endif /* __EROFS_INTERNAL_H */ |