Gao Xiang | 29b24f6 | 2019-07-31 23:57:31 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 2 | /* |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +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 | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 5 | * Created by Gao Xiang <gaoxiang25@huawei.com> |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/buffer_head.h> |
| 9 | #include <linux/statfs.h> |
| 10 | #include <linux/parser.h> |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 11 | #include <linux/seq_file.h> |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 12 | #include <linux/crc32c.h> |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 13 | #include <linux/fs_context.h> |
| 14 | #include <linux/fs_parser.h> |
Gao Xiang | 6af7b48 | 2019-01-14 19:40:25 +0800 | [diff] [blame] | 15 | #include "xattr.h" |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 16 | |
Chao Yu | 13f06f4 | 2018-07-26 20:21:55 +0800 | [diff] [blame] | 17 | #define CREATE_TRACE_POINTS |
| 18 | #include <trace/events/erofs.h> |
| 19 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 20 | static struct kmem_cache *erofs_inode_cachep __read_mostly; |
| 21 | |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 22 | void _erofs_err(struct super_block *sb, const char *function, |
| 23 | const char *fmt, ...) |
| 24 | { |
| 25 | struct va_format vaf; |
| 26 | va_list args; |
| 27 | |
| 28 | va_start(args, fmt); |
| 29 | |
| 30 | vaf.fmt = fmt; |
| 31 | vaf.va = &args; |
| 32 | |
| 33 | pr_err("(device %s): %s: %pV", sb->s_id, function, &vaf); |
| 34 | va_end(args); |
| 35 | } |
| 36 | |
| 37 | void _erofs_info(struct super_block *sb, const char *function, |
| 38 | const char *fmt, ...) |
| 39 | { |
| 40 | struct va_format vaf; |
| 41 | va_list args; |
| 42 | |
| 43 | va_start(args, fmt); |
| 44 | |
| 45 | vaf.fmt = fmt; |
| 46 | vaf.va = &args; |
| 47 | |
| 48 | pr_info("(device %s): %pV", sb->s_id, &vaf); |
| 49 | va_end(args); |
| 50 | } |
| 51 | |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 52 | static int erofs_superblock_csum_verify(struct super_block *sb, void *sbdata) |
| 53 | { |
| 54 | struct erofs_super_block *dsb; |
| 55 | u32 expected_crc, crc; |
| 56 | |
| 57 | dsb = kmemdup(sbdata + EROFS_SUPER_OFFSET, |
| 58 | EROFS_BLKSIZ - EROFS_SUPER_OFFSET, GFP_KERNEL); |
| 59 | if (!dsb) |
| 60 | return -ENOMEM; |
| 61 | |
| 62 | expected_crc = le32_to_cpu(dsb->checksum); |
| 63 | dsb->checksum = 0; |
| 64 | /* to allow for x86 boot sectors and other oddities. */ |
| 65 | crc = crc32c(~0, dsb, EROFS_BLKSIZ - EROFS_SUPER_OFFSET); |
| 66 | kfree(dsb); |
| 67 | |
| 68 | if (crc != expected_crc) { |
| 69 | erofs_err(sb, "invalid checksum 0x%08x, 0x%08x expected", |
| 70 | crc, expected_crc); |
| 71 | return -EBADMSG; |
| 72 | } |
| 73 | return 0; |
| 74 | } |
| 75 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 76 | static void erofs_inode_init_once(void *ptr) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 77 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 78 | struct erofs_inode *vi = ptr; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 79 | |
| 80 | inode_init_once(&vi->vfs_inode); |
| 81 | } |
| 82 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 83 | static struct inode *erofs_alloc_inode(struct super_block *sb) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 84 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 85 | struct erofs_inode *vi = |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 86 | kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL); |
| 87 | |
Vatsala Narang | e2ff9f1 | 2019-03-21 05:36:13 +0530 | [diff] [blame] | 88 | if (!vi) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 89 | return NULL; |
| 90 | |
| 91 | /* zero out everything except vfs_inode */ |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 92 | memset(vi, 0, offsetof(struct erofs_inode, vfs_inode)); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 93 | return &vi->vfs_inode; |
| 94 | } |
| 95 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 96 | static void erofs_free_inode(struct inode *inode) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 97 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 98 | struct erofs_inode *vi = EROFS_I(inode); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 99 | |
Gao Xiang | a2c75c8 | 2019-09-04 10:08:59 +0800 | [diff] [blame] | 100 | /* be careful of RCU symlink path */ |
| 101 | if (inode->i_op == &erofs_fast_symlink_iops) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 102 | kfree(inode->i_link); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 103 | kfree(vi->xattr_shared_xattrs); |
| 104 | |
| 105 | kmem_cache_free(erofs_inode_cachep, vi); |
| 106 | } |
| 107 | |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 108 | static bool check_layout_compatibility(struct super_block *sb, |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 109 | struct erofs_super_block *dsb) |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 110 | { |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 111 | const unsigned int feature = le32_to_cpu(dsb->feature_incompat); |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 112 | |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 113 | EROFS_SB(sb)->feature_incompat = feature; |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 114 | |
| 115 | /* check if current kernel meets all mandatory requirements */ |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 116 | if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 117 | erofs_err(sb, |
| 118 | "unidentified incompatible feature %x, please upgrade kernel version", |
| 119 | feature & ~EROFS_ALL_FEATURE_INCOMPAT); |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 120 | return false; |
| 121 | } |
| 122 | return true; |
| 123 | } |
| 124 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 125 | static int erofs_read_superblock(struct super_block *sb) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 126 | { |
| 127 | struct erofs_sb_info *sbi; |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 128 | struct page *page; |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 129 | struct erofs_super_block *dsb; |
Thomas Weißschuh | 7dd68b1 | 2018-09-10 21:41:14 +0200 | [diff] [blame] | 130 | unsigned int blkszbits; |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 131 | void *data; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 132 | int ret; |
| 133 | |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 134 | page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL); |
Wei Yongjun | 517d6b9 | 2019-09-18 08:30:33 +0000 | [diff] [blame] | 135 | if (IS_ERR(page)) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 136 | erofs_err(sb, "cannot read erofs superblock"); |
Wei Yongjun | 517d6b9 | 2019-09-18 08:30:33 +0000 | [diff] [blame] | 137 | return PTR_ERR(page); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | sbi = EROFS_SB(sb); |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 141 | |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 142 | data = kmap(page); |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 143 | dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 144 | |
| 145 | ret = -EINVAL; |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 146 | if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 147 | erofs_err(sb, "cannot find valid erofs superblock"); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 148 | goto out; |
| 149 | } |
| 150 | |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 151 | sbi->feature_compat = le32_to_cpu(dsb->feature_compat); |
| 152 | if (sbi->feature_compat & EROFS_FEATURE_COMPAT_SB_CHKSUM) { |
| 153 | ret = erofs_superblock_csum_verify(sb, data); |
| 154 | if (ret) |
| 155 | goto out; |
| 156 | } |
| 157 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 158 | blkszbits = dsb->blkszbits; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 159 | /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */ |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 160 | if (blkszbits != LOG_BLOCK_SIZE) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 161 | erofs_err(sb, "blksize %u isn't supported on this platform", |
| 162 | 1 << blkszbits); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 163 | goto out; |
| 164 | } |
| 165 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 166 | if (!check_layout_compatibility(sb, dsb)) |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 167 | goto out; |
| 168 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 169 | sbi->blocks = le32_to_cpu(dsb->blocks); |
| 170 | sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 171 | #ifdef CONFIG_EROFS_FS_XATTR |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 172 | sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 173 | #endif |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 174 | sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact)); |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 175 | sbi->root_nid = le16_to_cpu(dsb->root_nid); |
| 176 | sbi->inos = le64_to_cpu(dsb->inos); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 177 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 178 | sbi->build_time = le64_to_cpu(dsb->build_time); |
| 179 | sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 180 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 181 | memcpy(&sb->s_uuid, dsb->uuid, sizeof(dsb->uuid)); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 182 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 183 | ret = strscpy(sbi->volume_name, dsb->volume_name, |
| 184 | sizeof(dsb->volume_name)); |
Gao Xiang | a64d949 | 2019-08-18 18:28:24 +0800 | [diff] [blame] | 185 | if (ret < 0) { /* -E2BIG */ |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 186 | erofs_err(sb, "bad volume name without NIL terminator"); |
Gao Xiang | a64d949 | 2019-08-18 18:28:24 +0800 | [diff] [blame] | 187 | ret = -EFSCORRUPTED; |
| 188 | goto out; |
| 189 | } |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 190 | ret = 0; |
| 191 | out: |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 192 | kunmap(page); |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 193 | put_page(page); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 194 | return ret; |
| 195 | } |
| 196 | |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 197 | /* set up default EROFS parameters */ |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 198 | static void erofs_default_options(struct erofs_fs_context *ctx) |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 199 | { |
| 200 | #ifdef CONFIG_EROFS_FS_ZIP |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 201 | ctx->cache_strategy = EROFS_ZIP_CACHE_READAROUND; |
| 202 | ctx->max_sync_decompress_pages = 3; |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 203 | #endif |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 204 | #ifdef CONFIG_EROFS_FS_XATTR |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 205 | set_opt(ctx, XATTR_USER); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 206 | #endif |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 207 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 208 | set_opt(ctx, POSIX_ACL); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 209 | #endif |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | enum { |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 213 | Opt_user_xattr, |
| 214 | Opt_nouser_xattr, |
| 215 | Opt_acl, |
| 216 | Opt_noacl, |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 217 | Opt_cache_strategy, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 218 | Opt_err |
| 219 | }; |
| 220 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 221 | static const struct constant_table erofs_param_cache_strategy[] = { |
| 222 | {"disabled", EROFS_ZIP_CACHE_DISABLED}, |
| 223 | {"readahead", EROFS_ZIP_CACHE_READAHEAD}, |
| 224 | {"readaround", EROFS_ZIP_CACHE_READAROUND}, |
| 225 | {} |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 226 | }; |
| 227 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 228 | static const struct fs_parameter_spec erofs_fs_parameters[] = { |
| 229 | fsparam_flag_no("user_xattr", Opt_user_xattr), |
| 230 | fsparam_flag_no("acl", Opt_acl), |
| 231 | fsparam_enum("cache_strategy", Opt_cache_strategy, |
| 232 | erofs_param_cache_strategy), |
| 233 | {} |
| 234 | }; |
| 235 | |
| 236 | static int erofs_fc_parse_param(struct fs_context *fc, |
| 237 | struct fs_parameter *param) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 238 | { |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 239 | struct erofs_fs_context *ctx __maybe_unused = fc->fs_private; |
| 240 | struct fs_parse_result result; |
| 241 | int opt; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 242 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 243 | opt = fs_parse(fc, erofs_fs_parameters, param, &result); |
| 244 | if (opt < 0) |
| 245 | return opt; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 246 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 247 | switch (opt) { |
| 248 | case Opt_user_xattr: |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 249 | #ifdef CONFIG_EROFS_FS_XATTR |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 250 | if (result.boolean) |
| 251 | set_opt(ctx, XATTR_USER); |
| 252 | else |
| 253 | clear_opt(ctx, XATTR_USER); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 254 | #else |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 255 | errorfc(fc, "{,no}user_xattr options not supported"); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 256 | #endif |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 257 | break; |
| 258 | case Opt_acl: |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 259 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 260 | if (result.boolean) |
| 261 | set_opt(ctx, POSIX_ACL); |
| 262 | else |
| 263 | clear_opt(ctx, POSIX_ACL); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 264 | #else |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 265 | errorfc(fc, "{,no}acl options not supported"); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 266 | #endif |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 267 | break; |
| 268 | case Opt_cache_strategy: |
| 269 | #ifdef CONFIG_EROFS_FS_ZIP |
| 270 | ctx->cache_strategy = result.uint_32; |
| 271 | #else |
| 272 | errorfc(fc, "compression not supported, cache_strategy ignored"); |
| 273 | #endif |
| 274 | break; |
| 275 | default: |
| 276 | return -ENOPARAM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 277 | } |
| 278 | return 0; |
| 279 | } |
| 280 | |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 281 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 282 | static const struct address_space_operations managed_cache_aops; |
| 283 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 284 | static int erofs_managed_cache_releasepage(struct page *page, gfp_t gfp_mask) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 285 | { |
| 286 | int ret = 1; /* 0 - busy */ |
| 287 | struct address_space *const mapping = page->mapping; |
| 288 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 289 | DBG_BUGON(!PageLocked(page)); |
| 290 | DBG_BUGON(mapping->a_ops != &managed_cache_aops); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 291 | |
| 292 | if (PagePrivate(page)) |
Gao Xiang | 47e541a | 2018-07-29 13:34:58 +0800 | [diff] [blame] | 293 | ret = erofs_try_to_free_cached_page(mapping, page); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 294 | |
| 295 | return ret; |
| 296 | } |
| 297 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 298 | static void erofs_managed_cache_invalidatepage(struct page *page, |
| 299 | unsigned int offset, |
| 300 | unsigned int length) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 301 | { |
| 302 | const unsigned int stop = length + offset; |
| 303 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 304 | DBG_BUGON(!PageLocked(page)); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 305 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 306 | /* Check for potential overflow in debug mode */ |
| 307 | DBG_BUGON(stop > PAGE_SIZE || stop < length); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 308 | |
| 309 | if (offset == 0 && stop == PAGE_SIZE) |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 310 | while (!erofs_managed_cache_releasepage(page, GFP_NOFS)) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 311 | cond_resched(); |
| 312 | } |
| 313 | |
| 314 | static const struct address_space_operations managed_cache_aops = { |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 315 | .releasepage = erofs_managed_cache_releasepage, |
| 316 | .invalidatepage = erofs_managed_cache_invalidatepage, |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 317 | }; |
| 318 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 319 | static int erofs_init_managed_cache(struct super_block *sb) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 320 | { |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 321 | struct erofs_sb_info *const sbi = EROFS_SB(sb); |
| 322 | struct inode *const inode = new_inode(sb); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 323 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 324 | if (!inode) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 325 | return -ENOMEM; |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 326 | |
| 327 | set_nlink(inode, 1); |
| 328 | inode->i_size = OFFSET_MAX; |
| 329 | |
| 330 | inode->i_mapping->a_ops = &managed_cache_aops; |
| 331 | mapping_set_gfp_mask(inode->i_mapping, |
Gao Xiang | 8494c29 | 2019-07-31 23:57:42 +0800 | [diff] [blame] | 332 | GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 333 | sbi->managed_cache = inode; |
| 334 | return 0; |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 335 | } |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 336 | #else |
| 337 | static int erofs_init_managed_cache(struct super_block *sb) { return 0; } |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 338 | #endif |
| 339 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 340 | static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 341 | { |
| 342 | struct inode *inode; |
| 343 | struct erofs_sb_info *sbi; |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 344 | struct erofs_fs_context *ctx = fc->fs_private; |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 345 | int err; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 346 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 347 | sb->s_magic = EROFS_SUPER_MAGIC; |
| 348 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 349 | if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 350 | erofs_err(sb, "failed to set erofs blksize"); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 351 | return -EINVAL; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 352 | } |
| 353 | |
Shobhit Kukreti | a9f69bd | 2019-06-26 22:31:18 -0700 | [diff] [blame] | 354 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 355 | if (!sbi) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 356 | return -ENOMEM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 357 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 358 | sb->s_fs_info = sbi; |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 359 | err = erofs_read_superblock(sb); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 360 | if (err) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 361 | return err; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 362 | |
Gao Xiang | 5f0abea | 2018-09-06 17:01:47 +0800 | [diff] [blame] | 363 | sb->s_flags |= SB_RDONLY | SB_NOATIME; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 364 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
| 365 | sb->s_time_gran = 1; |
| 366 | |
| 367 | sb->s_op = &erofs_sops; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 368 | sb->s_xattr = erofs_xattr_handlers; |
Chengguang Xu | e7cda1e | 2020-05-26 17:03:43 +0800 | [diff] [blame] | 369 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 370 | if (test_opt(ctx, POSIX_ACL)) |
Gao Xiang | 516c115c | 2019-01-29 16:35:20 +0800 | [diff] [blame] | 371 | sb->s_flags |= SB_POSIXACL; |
| 372 | else |
| 373 | sb->s_flags &= ~SB_POSIXACL; |
| 374 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 375 | sbi->ctx = *ctx; |
| 376 | |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 377 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 64094a0 | 2020-02-20 10:46:42 +0800 | [diff] [blame] | 378 | xa_init(&sbi->managed_pslots); |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 379 | #endif |
| 380 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 381 | /* get the root inode */ |
| 382 | inode = erofs_iget(sb, ROOT_NID(sbi), true); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 383 | if (IS_ERR(inode)) |
| 384 | return PTR_ERR(inode); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 385 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 386 | if (!S_ISDIR(inode->i_mode)) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 387 | erofs_err(sb, "rootino(nid %llu) is not a directory(i_mode %o)", |
| 388 | ROOT_NID(sbi), inode->i_mode); |
Chengguang Xu | 94832d9 | 2019-01-23 14:12:25 +0800 | [diff] [blame] | 389 | iput(inode); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 390 | return -EINVAL; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | sb->s_root = d_make_root(inode); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 394 | if (!sb->s_root) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 395 | return -ENOMEM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 396 | |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 397 | erofs_shrinker_register(sb); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 398 | /* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */ |
| 399 | err = erofs_init_managed_cache(sb); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 400 | if (err) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 401 | return err; |
Gao Xiang | 2497ee4 | 2018-07-26 20:22:03 +0800 | [diff] [blame] | 402 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 403 | erofs_info(sb, "mounted with root inode @ nid %llu.", ROOT_NID(sbi)); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 404 | return 0; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 405 | } |
| 406 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 407 | static int erofs_fc_get_tree(struct fs_context *fc) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 408 | { |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 409 | return get_tree_bdev(fc, erofs_fc_fill_super); |
| 410 | } |
| 411 | |
| 412 | static int erofs_fc_reconfigure(struct fs_context *fc) |
| 413 | { |
| 414 | struct super_block *sb = fc->root->d_sb; |
| 415 | struct erofs_sb_info *sbi = EROFS_SB(sb); |
| 416 | struct erofs_fs_context *ctx = fc->fs_private; |
| 417 | |
| 418 | DBG_BUGON(!sb_rdonly(sb)); |
| 419 | |
| 420 | if (test_opt(ctx, POSIX_ACL)) |
| 421 | fc->sb_flags |= SB_POSIXACL; |
| 422 | else |
| 423 | fc->sb_flags &= ~SB_POSIXACL; |
| 424 | |
| 425 | sbi->ctx = *ctx; |
| 426 | |
| 427 | fc->sb_flags |= SB_RDONLY; |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static void erofs_fc_free(struct fs_context *fc) |
| 432 | { |
| 433 | kfree(fc->fs_private); |
| 434 | } |
| 435 | |
| 436 | static const struct fs_context_operations erofs_context_ops = { |
| 437 | .parse_param = erofs_fc_parse_param, |
| 438 | .get_tree = erofs_fc_get_tree, |
| 439 | .reconfigure = erofs_fc_reconfigure, |
| 440 | .free = erofs_fc_free, |
| 441 | }; |
| 442 | |
| 443 | static int erofs_init_fs_context(struct fs_context *fc) |
| 444 | { |
| 445 | fc->fs_private = kzalloc(sizeof(struct erofs_fs_context), GFP_KERNEL); |
| 446 | if (!fc->fs_private) |
| 447 | return -ENOMEM; |
| 448 | |
| 449 | /* set default mount options */ |
| 450 | erofs_default_options(fc->fs_private); |
| 451 | |
| 452 | fc->ops = &erofs_context_ops; |
| 453 | |
| 454 | return 0; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 455 | } |
| 456 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 457 | /* |
| 458 | * could be triggered after deactivate_locked_super() |
| 459 | * is called, thus including umount and failed to initialize. |
| 460 | */ |
| 461 | static void erofs_kill_sb(struct super_block *sb) |
| 462 | { |
| 463 | struct erofs_sb_info *sbi; |
| 464 | |
| 465 | WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 466 | |
| 467 | kill_block_super(sb); |
| 468 | |
| 469 | sbi = EROFS_SB(sb); |
| 470 | if (!sbi) |
| 471 | return; |
| 472 | kfree(sbi); |
| 473 | sb->s_fs_info = NULL; |
| 474 | } |
| 475 | |
| 476 | /* called when ->s_root is non-NULL */ |
| 477 | static void erofs_put_super(struct super_block *sb) |
| 478 | { |
| 479 | struct erofs_sb_info *const sbi = EROFS_SB(sb); |
| 480 | |
| 481 | DBG_BUGON(!sbi); |
| 482 | |
| 483 | erofs_shrinker_unregister(sb); |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 484 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 485 | iput(sbi->managed_cache); |
| 486 | sbi->managed_cache = NULL; |
| 487 | #endif |
| 488 | } |
| 489 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 490 | static struct file_system_type erofs_fs_type = { |
| 491 | .owner = THIS_MODULE, |
| 492 | .name = "erofs", |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 493 | .init_fs_context = erofs_init_fs_context, |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 494 | .kill_sb = erofs_kill_sb, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 495 | .fs_flags = FS_REQUIRES_DEV, |
| 496 | }; |
| 497 | MODULE_ALIAS_FS("erofs"); |
| 498 | |
| 499 | static int __init erofs_module_init(void) |
| 500 | { |
| 501 | int err; |
| 502 | |
| 503 | erofs_check_ondisk_layout_definitions(); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 504 | |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 505 | erofs_inode_cachep = kmem_cache_create("erofs_inode", |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 506 | sizeof(struct erofs_inode), 0, |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 507 | SLAB_RECLAIM_ACCOUNT, |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 508 | erofs_inode_init_once); |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 509 | if (!erofs_inode_cachep) { |
| 510 | err = -ENOMEM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 511 | goto icache_err; |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 512 | } |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 513 | |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 514 | err = erofs_init_shrinker(); |
Gao Xiang | a158131 | 2018-07-26 20:22:04 +0800 | [diff] [blame] | 515 | if (err) |
| 516 | goto shrinker_err; |
| 517 | |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 518 | err = z_erofs_init_zip_subsystem(); |
| 519 | if (err) |
| 520 | goto zip_err; |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 521 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 522 | err = register_filesystem(&erofs_fs_type); |
| 523 | if (err) |
| 524 | goto fs_err; |
| 525 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 526 | return 0; |
| 527 | |
| 528 | fs_err: |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 529 | z_erofs_exit_zip_subsystem(); |
| 530 | zip_err: |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 531 | erofs_exit_shrinker(); |
Gao Xiang | a158131 | 2018-07-26 20:22:04 +0800 | [diff] [blame] | 532 | shrinker_err: |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 533 | kmem_cache_destroy(erofs_inode_cachep); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 534 | icache_err: |
| 535 | return err; |
| 536 | } |
| 537 | |
| 538 | static void __exit erofs_module_exit(void) |
| 539 | { |
| 540 | unregister_filesystem(&erofs_fs_type); |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 541 | z_erofs_exit_zip_subsystem(); |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 542 | erofs_exit_shrinker(); |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 543 | |
| 544 | /* Ensure all RCU free inodes are safe before cache is destroyed. */ |
| 545 | rcu_barrier(); |
| 546 | kmem_cache_destroy(erofs_inode_cachep); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /* get filesystem statistics */ |
| 550 | static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 551 | { |
| 552 | struct super_block *sb = dentry->d_sb; |
| 553 | struct erofs_sb_info *sbi = EROFS_SB(sb); |
| 554 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); |
| 555 | |
| 556 | buf->f_type = sb->s_magic; |
| 557 | buf->f_bsize = EROFS_BLKSIZ; |
| 558 | buf->f_blocks = sbi->blocks; |
| 559 | buf->f_bfree = buf->f_bavail = 0; |
| 560 | |
| 561 | buf->f_files = ULLONG_MAX; |
| 562 | buf->f_ffree = ULLONG_MAX - sbi->inos; |
| 563 | |
| 564 | buf->f_namelen = EROFS_NAME_LEN; |
| 565 | |
| 566 | buf->f_fsid.val[0] = (u32)id; |
| 567 | buf->f_fsid.val[1] = (u32)(id >> 32); |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | static int erofs_show_options(struct seq_file *seq, struct dentry *root) |
| 572 | { |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 573 | struct erofs_sb_info *sbi __maybe_unused = EROFS_SB(root->d_sb); |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 574 | struct erofs_fs_context *ctx __maybe_unused = &sbi->ctx; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 575 | |
| 576 | #ifdef CONFIG_EROFS_FS_XATTR |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 577 | if (test_opt(ctx, XATTR_USER)) |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 578 | seq_puts(seq, ",user_xattr"); |
| 579 | else |
| 580 | seq_puts(seq, ",nouser_xattr"); |
| 581 | #endif |
| 582 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 583 | if (test_opt(ctx, POSIX_ACL)) |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 584 | seq_puts(seq, ",acl"); |
| 585 | else |
| 586 | seq_puts(seq, ",noacl"); |
| 587 | #endif |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 588 | #ifdef CONFIG_EROFS_FS_ZIP |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 589 | if (ctx->cache_strategy == EROFS_ZIP_CACHE_DISABLED) |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 590 | seq_puts(seq, ",cache_strategy=disabled"); |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 591 | else if (ctx->cache_strategy == EROFS_ZIP_CACHE_READAHEAD) |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 592 | seq_puts(seq, ",cache_strategy=readahead"); |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 593 | else if (ctx->cache_strategy == EROFS_ZIP_CACHE_READAROUND) |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 594 | seq_puts(seq, ",cache_strategy=readaround"); |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 595 | #endif |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 596 | return 0; |
| 597 | } |
| 598 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 599 | const struct super_operations erofs_sops = { |
| 600 | .put_super = erofs_put_super, |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 601 | .alloc_inode = erofs_alloc_inode, |
| 602 | .free_inode = erofs_free_inode, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 603 | .statfs = erofs_statfs, |
| 604 | .show_options = erofs_show_options, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 605 | }; |
| 606 | |
| 607 | module_init(erofs_module_init); |
| 608 | module_exit(erofs_module_exit); |
| 609 | |
| 610 | MODULE_DESCRIPTION("Enhanced ROM File System"); |
Gao Xiang | bc33d9f | 2019-07-31 23:57:51 +0800 | [diff] [blame] | 611 | MODULE_AUTHOR("Gao Xiang, Chao Yu, Miao Xie, CONSUMER BG, HUAWEI Inc."); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 612 | MODULE_LICENSE("GPL"); |
| 613 | |