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