1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2017-2018 HUAWEI, Inc.
4 * https://www.huawei.com/
5 * Copyright (C) 2021, Alibaba Cloud
7 #include <linux/module.h>
8 #include <linux/statfs.h>
9 #include <linux/parser.h>
10 #include <linux/seq_file.h>
11 #include <linux/crc32c.h>
12 #include <linux/fs_context.h>
13 #include <linux/fs_parser.h>
14 #include <linux/dax.h>
15 #include <linux/exportfs.h>
18 #define CREATE_TRACE_POINTS
19 #include <trace/events/erofs.h>
21 static struct kmem_cache *erofs_inode_cachep __read_mostly;
23 void _erofs_err(struct super_block *sb, const char *func, const char *fmt, ...)
33 pr_err("(device %s): %s: %pV", sb->s_id, func, &vaf);
37 void _erofs_info(struct super_block *sb, const char *func, const char *fmt, ...)
47 pr_info("(device %s): %pV", sb->s_id, &vaf);
51 static int erofs_superblock_csum_verify(struct super_block *sb, void *sbdata)
53 size_t len = 1 << EROFS_SB(sb)->blkszbits;
54 struct erofs_super_block *dsb;
55 u32 expected_crc, crc;
57 if (len > EROFS_SUPER_OFFSET)
58 len -= EROFS_SUPER_OFFSET;
60 dsb = kmemdup(sbdata + EROFS_SUPER_OFFSET, len, GFP_KERNEL);
64 expected_crc = le32_to_cpu(dsb->checksum);
66 /* to allow for x86 boot sectors and other oddities. */
67 crc = crc32c(~0, dsb, len);
70 if (crc != expected_crc) {
71 erofs_err(sb, "invalid checksum 0x%08x, 0x%08x expected",
78 static void erofs_inode_init_once(void *ptr)
80 struct erofs_inode *vi = ptr;
82 inode_init_once(&vi->vfs_inode);
85 static struct inode *erofs_alloc_inode(struct super_block *sb)
87 struct erofs_inode *vi =
88 alloc_inode_sb(sb, erofs_inode_cachep, GFP_KERNEL);
93 /* zero out everything except vfs_inode */
94 memset(vi, 0, offsetof(struct erofs_inode, vfs_inode));
95 return &vi->vfs_inode;
98 static void erofs_free_inode(struct inode *inode)
100 struct erofs_inode *vi = EROFS_I(inode);
102 if (inode->i_op == &erofs_fast_symlink_iops)
103 kfree(inode->i_link);
104 kfree(vi->xattr_shared_xattrs);
105 kmem_cache_free(erofs_inode_cachep, vi);
108 static bool check_layout_compatibility(struct super_block *sb,
109 struct erofs_super_block *dsb)
111 const unsigned int feature = le32_to_cpu(dsb->feature_incompat);
113 EROFS_SB(sb)->feature_incompat = feature;
115 /* check if current kernel meets all mandatory requirements */
116 if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) {
117 erofs_err(sb, "unidentified incompatible feature %x, please upgrade kernel",
118 feature & ~EROFS_ALL_FEATURE_INCOMPAT);
124 /* read variable-sized metadata, offset will be aligned by 4-byte */
125 void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
126 erofs_off_t *offset, int *lengthp)
131 *offset = round_up(*offset, 4);
132 ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP);
136 len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(sb, *offset)]);
139 buffer = kmalloc(len, GFP_KERNEL);
141 return ERR_PTR(-ENOMEM);
142 *offset += sizeof(__le16);
145 for (i = 0; i < len; i += cnt) {
146 cnt = min_t(int, sb->s_blocksize - erofs_blkoff(sb, *offset),
148 ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP);
153 memcpy(buffer + i, ptr + erofs_blkoff(sb, *offset), cnt);
159 #ifndef CONFIG_EROFS_FS_ZIP
160 static int z_erofs_parse_cfgs(struct super_block *sb,
161 struct erofs_super_block *dsb)
163 if (!dsb->u1.available_compr_algs)
166 erofs_err(sb, "compression disabled, unable to mount compressed EROFS");
171 static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
172 struct erofs_device_info *dif, erofs_off_t *pos)
174 struct erofs_sb_info *sbi = EROFS_SB(sb);
175 struct erofs_fscache *fscache;
176 struct erofs_deviceslot *dis;
177 struct block_device *bdev;
180 ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *pos), EROFS_KMAP);
183 dis = ptr + erofs_blkoff(sb, *pos);
185 if (!sbi->devs->flatdev && !dif->path) {
187 erofs_err(sb, "empty device tag @ pos %llu", *pos);
190 dif->path = kmemdup_nul(dis->tag, sizeof(dis->tag), GFP_KERNEL);
195 if (erofs_is_fscache_mode(sb)) {
196 fscache = erofs_fscache_register_cookie(sb, dif->path, 0);
198 return PTR_ERR(fscache);
199 dif->fscache = fscache;
200 } else if (!sbi->devs->flatdev) {
201 bdev = blkdev_get_by_path(dif->path, BLK_OPEN_READ, sb->s_type,
204 return PTR_ERR(bdev);
206 dif->dax_dev = fs_dax_get_by_bdev(bdev, &dif->dax_part_off,
210 dif->blocks = le32_to_cpu(dis->blocks);
211 dif->mapped_blkaddr = le32_to_cpu(dis->mapped_blkaddr);
212 sbi->total_blocks += dif->blocks;
213 *pos += EROFS_DEVT_SLOT_SIZE;
217 static int erofs_scan_devices(struct super_block *sb,
218 struct erofs_super_block *dsb)
220 struct erofs_sb_info *sbi = EROFS_SB(sb);
221 unsigned int ondisk_extradevs;
223 struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
224 struct erofs_device_info *dif;
227 sbi->total_blocks = sbi->primarydevice_blocks;
228 if (!erofs_sb_has_device_table(sbi))
229 ondisk_extradevs = 0;
231 ondisk_extradevs = le16_to_cpu(dsb->extra_devices);
233 if (sbi->devs->extra_devices &&
234 ondisk_extradevs != sbi->devs->extra_devices) {
235 erofs_err(sb, "extra devices don't match (ondisk %u, given %u)",
236 ondisk_extradevs, sbi->devs->extra_devices);
239 if (!ondisk_extradevs)
242 if (!sbi->devs->extra_devices && !erofs_is_fscache_mode(sb))
243 sbi->devs->flatdev = true;
245 sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1;
246 pos = le16_to_cpu(dsb->devt_slotoff) * EROFS_DEVT_SLOT_SIZE;
247 down_read(&sbi->devs->rwsem);
248 if (sbi->devs->extra_devices) {
249 idr_for_each_entry(&sbi->devs->tree, dif, id) {
250 err = erofs_init_device(&buf, sb, dif, &pos);
255 for (id = 0; id < ondisk_extradevs; id++) {
256 dif = kzalloc(sizeof(*dif), GFP_KERNEL);
262 err = idr_alloc(&sbi->devs->tree, dif, 0, 0, GFP_KERNEL);
267 ++sbi->devs->extra_devices;
269 err = erofs_init_device(&buf, sb, dif, &pos);
274 up_read(&sbi->devs->rwsem);
275 erofs_put_metabuf(&buf);
279 static int erofs_read_superblock(struct super_block *sb)
281 struct erofs_sb_info *sbi;
282 struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
283 struct erofs_super_block *dsb;
287 data = erofs_read_metabuf(&buf, sb, 0, EROFS_KMAP);
289 erofs_err(sb, "cannot read erofs superblock");
290 return PTR_ERR(data);
294 dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
297 if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
298 erofs_err(sb, "cannot find valid erofs superblock");
302 sbi->blkszbits = dsb->blkszbits;
303 if (sbi->blkszbits < 9 || sbi->blkszbits > PAGE_SHIFT) {
304 erofs_err(sb, "blkszbits %u isn't supported", sbi->blkszbits);
307 if (dsb->dirblkbits) {
308 erofs_err(sb, "dirblkbits %u isn't supported", dsb->dirblkbits);
312 sbi->feature_compat = le32_to_cpu(dsb->feature_compat);
313 if (erofs_sb_has_sb_chksum(sbi)) {
314 ret = erofs_superblock_csum_verify(sb, data);
320 if (!check_layout_compatibility(sb, dsb))
323 sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE;
324 if (sbi->sb_size > PAGE_SIZE - EROFS_SUPER_OFFSET) {
325 erofs_err(sb, "invalid sb_extslots %u (more than a fs block)",
329 sbi->primarydevice_blocks = le32_to_cpu(dsb->blocks);
330 sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
331 #ifdef CONFIG_EROFS_FS_XATTR
332 sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
333 sbi->xattr_prefix_start = le32_to_cpu(dsb->xattr_prefix_start);
334 sbi->xattr_prefix_count = dsb->xattr_prefix_count;
335 sbi->xattr_filter_reserved = dsb->xattr_filter_reserved;
337 sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
338 sbi->root_nid = le16_to_cpu(dsb->root_nid);
339 sbi->packed_nid = le64_to_cpu(dsb->packed_nid);
340 sbi->inos = le64_to_cpu(dsb->inos);
342 sbi->build_time = le64_to_cpu(dsb->build_time);
343 sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec);
345 memcpy(&sb->s_uuid, dsb->uuid, sizeof(dsb->uuid));
347 ret = strscpy(sbi->volume_name, dsb->volume_name,
348 sizeof(dsb->volume_name));
349 if (ret < 0) { /* -E2BIG */
350 erofs_err(sb, "bad volume name without NIL terminator");
355 /* parse on-disk compression configurations */
356 ret = z_erofs_parse_cfgs(sb, dsb);
360 /* handle multiple devices */
361 ret = erofs_scan_devices(sb, dsb);
363 if (erofs_is_fscache_mode(sb))
364 erofs_info(sb, "EXPERIMENTAL fscache-based on-demand read feature in use. Use at your own risk!");
366 erofs_put_metabuf(&buf);
370 static void erofs_default_options(struct erofs_fs_context *ctx)
372 #ifdef CONFIG_EROFS_FS_ZIP
373 ctx->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND;
374 ctx->opt.max_sync_decompress_pages = 3;
375 ctx->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO;
377 #ifdef CONFIG_EROFS_FS_XATTR
378 set_opt(&ctx->opt, XATTR_USER);
380 #ifdef CONFIG_EROFS_FS_POSIX_ACL
381 set_opt(&ctx->opt, POSIX_ACL);
397 static const struct constant_table erofs_param_cache_strategy[] = {
398 {"disabled", EROFS_ZIP_CACHE_DISABLED},
399 {"readahead", EROFS_ZIP_CACHE_READAHEAD},
400 {"readaround", EROFS_ZIP_CACHE_READAROUND},
404 static const struct constant_table erofs_dax_param_enums[] = {
405 {"always", EROFS_MOUNT_DAX_ALWAYS},
406 {"never", EROFS_MOUNT_DAX_NEVER},
410 static const struct fs_parameter_spec erofs_fs_parameters[] = {
411 fsparam_flag_no("user_xattr", Opt_user_xattr),
412 fsparam_flag_no("acl", Opt_acl),
413 fsparam_enum("cache_strategy", Opt_cache_strategy,
414 erofs_param_cache_strategy),
415 fsparam_flag("dax", Opt_dax),
416 fsparam_enum("dax", Opt_dax_enum, erofs_dax_param_enums),
417 fsparam_string("device", Opt_device),
418 fsparam_string("fsid", Opt_fsid),
419 fsparam_string("domain_id", Opt_domain_id),
423 static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode)
426 struct erofs_fs_context *ctx = fc->fs_private;
429 case EROFS_MOUNT_DAX_ALWAYS:
430 warnfc(fc, "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
431 set_opt(&ctx->opt, DAX_ALWAYS);
432 clear_opt(&ctx->opt, DAX_NEVER);
434 case EROFS_MOUNT_DAX_NEVER:
435 set_opt(&ctx->opt, DAX_NEVER);
436 clear_opt(&ctx->opt, DAX_ALWAYS);
443 errorfc(fc, "dax options not supported");
448 static int erofs_fc_parse_param(struct fs_context *fc,
449 struct fs_parameter *param)
451 struct erofs_fs_context *ctx = fc->fs_private;
452 struct fs_parse_result result;
453 struct erofs_device_info *dif;
456 opt = fs_parse(fc, erofs_fs_parameters, param, &result);
462 #ifdef CONFIG_EROFS_FS_XATTR
464 set_opt(&ctx->opt, XATTR_USER);
466 clear_opt(&ctx->opt, XATTR_USER);
468 errorfc(fc, "{,no}user_xattr options not supported");
472 #ifdef CONFIG_EROFS_FS_POSIX_ACL
474 set_opt(&ctx->opt, POSIX_ACL);
476 clear_opt(&ctx->opt, POSIX_ACL);
478 errorfc(fc, "{,no}acl options not supported");
481 case Opt_cache_strategy:
482 #ifdef CONFIG_EROFS_FS_ZIP
483 ctx->opt.cache_strategy = result.uint_32;
485 errorfc(fc, "compression not supported, cache_strategy ignored");
489 if (!erofs_fc_set_dax_mode(fc, EROFS_MOUNT_DAX_ALWAYS))
493 if (!erofs_fc_set_dax_mode(fc, result.uint_32))
497 dif = kzalloc(sizeof(*dif), GFP_KERNEL);
500 dif->path = kstrdup(param->string, GFP_KERNEL);
505 down_write(&ctx->devs->rwsem);
506 ret = idr_alloc(&ctx->devs->tree, dif, 0, 0, GFP_KERNEL);
507 up_write(&ctx->devs->rwsem);
513 ++ctx->devs->extra_devices;
515 #ifdef CONFIG_EROFS_FS_ONDEMAND
518 ctx->fsid = kstrdup(param->string, GFP_KERNEL);
523 kfree(ctx->domain_id);
524 ctx->domain_id = kstrdup(param->string, GFP_KERNEL);
531 errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
540 static struct inode *erofs_nfs_get_inode(struct super_block *sb,
541 u64 ino, u32 generation)
543 return erofs_iget(sb, ino);
546 static struct dentry *erofs_fh_to_dentry(struct super_block *sb,
547 struct fid *fid, int fh_len, int fh_type)
549 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
550 erofs_nfs_get_inode);
553 static struct dentry *erofs_fh_to_parent(struct super_block *sb,
554 struct fid *fid, int fh_len, int fh_type)
556 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
557 erofs_nfs_get_inode);
560 static struct dentry *erofs_get_parent(struct dentry *child)
566 err = erofs_namei(d_inode(child), &dotdot_name, &nid, &d_type);
569 return d_obtain_alias(erofs_iget(child->d_sb, nid));
572 static const struct export_operations erofs_export_ops = {
573 .fh_to_dentry = erofs_fh_to_dentry,
574 .fh_to_parent = erofs_fh_to_parent,
575 .get_parent = erofs_get_parent,
578 static int erofs_fc_fill_pseudo_super(struct super_block *sb, struct fs_context *fc)
580 static const struct tree_descr empty_descr = {""};
582 return simple_fill_super(sb, EROFS_SUPER_MAGIC, &empty_descr);
585 static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
588 struct erofs_sb_info *sbi;
589 struct erofs_fs_context *ctx = fc->fs_private;
592 sb->s_magic = EROFS_SUPER_MAGIC;
593 sb->s_flags |= SB_RDONLY | SB_NOATIME;
594 sb->s_maxbytes = MAX_LFS_FILESIZE;
595 sb->s_op = &erofs_sops;
597 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
603 sbi->devs = ctx->devs;
605 sbi->fsid = ctx->fsid;
607 sbi->domain_id = ctx->domain_id;
608 ctx->domain_id = NULL;
610 sbi->blkszbits = PAGE_SHIFT;
611 if (erofs_is_fscache_mode(sb)) {
612 sb->s_blocksize = PAGE_SIZE;
613 sb->s_blocksize_bits = PAGE_SHIFT;
615 err = erofs_fscache_register_fs(sb);
619 err = super_setup_bdi(sb);
623 if (!sb_set_blocksize(sb, PAGE_SIZE)) {
624 errorfc(fc, "failed to set initial blksize");
628 sbi->dax_dev = fs_dax_get_by_bdev(sb->s_bdev,
633 err = erofs_read_superblock(sb);
637 if (sb->s_blocksize_bits != sbi->blkszbits) {
638 if (erofs_is_fscache_mode(sb)) {
639 errorfc(fc, "unsupported blksize for fscache mode");
642 if (!sb_set_blocksize(sb, 1 << sbi->blkszbits)) {
643 errorfc(fc, "failed to set erofs blksize");
648 if (test_opt(&sbi->opt, DAX_ALWAYS)) {
650 errorfc(fc, "DAX unsupported by block device. Turning off DAX.");
651 clear_opt(&sbi->opt, DAX_ALWAYS);
652 } else if (sbi->blkszbits != PAGE_SHIFT) {
653 errorfc(fc, "unsupported blocksize for DAX");
654 clear_opt(&sbi->opt, DAX_ALWAYS);
659 sb->s_xattr = erofs_xattr_handlers;
660 sb->s_export_op = &erofs_export_ops;
662 if (test_opt(&sbi->opt, POSIX_ACL))
663 sb->s_flags |= SB_POSIXACL;
665 sb->s_flags &= ~SB_POSIXACL;
667 #ifdef CONFIG_EROFS_FS_ZIP
668 xa_init(&sbi->managed_pslots);
671 inode = erofs_iget(sb, ROOT_NID(sbi));
673 return PTR_ERR(inode);
675 if (!S_ISDIR(inode->i_mode)) {
676 erofs_err(sb, "rootino(nid %llu) is not a directory(i_mode %o)",
677 ROOT_NID(sbi), inode->i_mode);
682 sb->s_root = d_make_root(inode);
686 erofs_shrinker_register(sb);
687 if (erofs_sb_has_fragments(sbi) && sbi->packed_nid) {
688 sbi->packed_inode = erofs_iget(sb, sbi->packed_nid);
689 if (IS_ERR(sbi->packed_inode)) {
690 err = PTR_ERR(sbi->packed_inode);
691 sbi->packed_inode = NULL;
695 err = erofs_init_managed_cache(sb);
699 err = erofs_xattr_prefixes_init(sb);
703 err = erofs_register_sysfs(sb);
707 erofs_info(sb, "mounted with root inode @ nid %llu.", ROOT_NID(sbi));
711 static int erofs_fc_anon_get_tree(struct fs_context *fc)
713 return get_tree_nodev(fc, erofs_fc_fill_pseudo_super);
716 static int erofs_fc_get_tree(struct fs_context *fc)
718 struct erofs_fs_context *ctx = fc->fs_private;
720 if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && ctx->fsid)
721 return get_tree_nodev(fc, erofs_fc_fill_super);
723 return get_tree_bdev(fc, erofs_fc_fill_super);
726 static int erofs_fc_reconfigure(struct fs_context *fc)
728 struct super_block *sb = fc->root->d_sb;
729 struct erofs_sb_info *sbi = EROFS_SB(sb);
730 struct erofs_fs_context *ctx = fc->fs_private;
732 DBG_BUGON(!sb_rdonly(sb));
734 if (ctx->fsid || ctx->domain_id)
735 erofs_info(sb, "ignoring reconfiguration for fsid|domain_id.");
737 if (test_opt(&ctx->opt, POSIX_ACL))
738 fc->sb_flags |= SB_POSIXACL;
740 fc->sb_flags &= ~SB_POSIXACL;
744 fc->sb_flags |= SB_RDONLY;
748 static int erofs_release_device_info(int id, void *ptr, void *data)
750 struct erofs_device_info *dif = ptr;
752 fs_put_dax(dif->dax_dev, NULL);
754 blkdev_put(dif->bdev, &erofs_fs_type);
755 erofs_fscache_unregister_cookie(dif->fscache);
762 static void erofs_free_dev_context(struct erofs_dev_context *devs)
766 idr_for_each(&devs->tree, &erofs_release_device_info, NULL);
767 idr_destroy(&devs->tree);
771 static void erofs_fc_free(struct fs_context *fc)
773 struct erofs_fs_context *ctx = fc->fs_private;
775 erofs_free_dev_context(ctx->devs);
777 kfree(ctx->domain_id);
781 static const struct fs_context_operations erofs_context_ops = {
782 .parse_param = erofs_fc_parse_param,
783 .get_tree = erofs_fc_get_tree,
784 .reconfigure = erofs_fc_reconfigure,
785 .free = erofs_fc_free,
788 static const struct fs_context_operations erofs_anon_context_ops = {
789 .get_tree = erofs_fc_anon_get_tree,
792 static int erofs_init_fs_context(struct fs_context *fc)
794 struct erofs_fs_context *ctx;
796 /* pseudo mount for anon inodes */
797 if (fc->sb_flags & SB_KERNMOUNT) {
798 fc->ops = &erofs_anon_context_ops;
802 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
805 ctx->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL);
810 fc->fs_private = ctx;
812 idr_init(&ctx->devs->tree);
813 init_rwsem(&ctx->devs->rwsem);
814 erofs_default_options(ctx);
815 fc->ops = &erofs_context_ops;
819 static void erofs_kill_sb(struct super_block *sb)
821 struct erofs_sb_info *sbi;
823 /* pseudo mount for anon inodes */
824 if (sb->s_flags & SB_KERNMOUNT) {
829 if (erofs_is_fscache_mode(sb))
832 kill_block_super(sb);
838 erofs_free_dev_context(sbi->devs);
839 fs_put_dax(sbi->dax_dev, NULL);
840 erofs_fscache_unregister_fs(sb);
842 kfree(sbi->domain_id);
844 sb->s_fs_info = NULL;
847 static void erofs_put_super(struct super_block *sb)
849 struct erofs_sb_info *const sbi = EROFS_SB(sb);
853 erofs_unregister_sysfs(sb);
854 erofs_shrinker_unregister(sb);
855 erofs_xattr_prefixes_cleanup(sb);
856 #ifdef CONFIG_EROFS_FS_ZIP
857 iput(sbi->managed_cache);
858 sbi->managed_cache = NULL;
860 iput(sbi->packed_inode);
861 sbi->packed_inode = NULL;
862 erofs_free_dev_context(sbi->devs);
864 erofs_fscache_unregister_fs(sb);
867 struct file_system_type erofs_fs_type = {
868 .owner = THIS_MODULE,
870 .init_fs_context = erofs_init_fs_context,
871 .kill_sb = erofs_kill_sb,
872 .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
874 MODULE_ALIAS_FS("erofs");
876 static int __init erofs_module_init(void)
880 erofs_check_ondisk_layout_definitions();
882 erofs_inode_cachep = kmem_cache_create("erofs_inode",
883 sizeof(struct erofs_inode), 0,
884 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD | SLAB_ACCOUNT,
885 erofs_inode_init_once);
886 if (!erofs_inode_cachep)
889 err = erofs_init_shrinker();
893 err = z_erofs_lzma_init();
897 err = z_erofs_deflate_init();
901 erofs_pcpubuf_init();
902 err = z_erofs_init_zip_subsystem();
906 err = erofs_init_sysfs();
910 err = register_filesystem(&erofs_fs_type);
919 z_erofs_exit_zip_subsystem();
921 z_erofs_deflate_exit();
925 erofs_exit_shrinker();
927 kmem_cache_destroy(erofs_inode_cachep);
931 static void __exit erofs_module_exit(void)
933 unregister_filesystem(&erofs_fs_type);
935 /* Ensure all RCU free inodes / pclusters are safe to be destroyed. */
939 z_erofs_exit_zip_subsystem();
940 z_erofs_deflate_exit();
942 erofs_exit_shrinker();
943 kmem_cache_destroy(erofs_inode_cachep);
944 erofs_pcpubuf_exit();
947 static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
949 struct super_block *sb = dentry->d_sb;
950 struct erofs_sb_info *sbi = EROFS_SB(sb);
953 if (!erofs_is_fscache_mode(sb))
954 id = huge_encode_dev(sb->s_bdev->bd_dev);
956 buf->f_type = sb->s_magic;
957 buf->f_bsize = sb->s_blocksize;
958 buf->f_blocks = sbi->total_blocks;
959 buf->f_bfree = buf->f_bavail = 0;
961 buf->f_files = ULLONG_MAX;
962 buf->f_ffree = ULLONG_MAX - sbi->inos;
964 buf->f_namelen = EROFS_NAME_LEN;
966 buf->f_fsid = u64_to_fsid(id);
970 static int erofs_show_options(struct seq_file *seq, struct dentry *root)
972 struct erofs_sb_info *sbi = EROFS_SB(root->d_sb);
973 struct erofs_mount_opts *opt = &sbi->opt;
975 #ifdef CONFIG_EROFS_FS_XATTR
976 if (test_opt(opt, XATTR_USER))
977 seq_puts(seq, ",user_xattr");
979 seq_puts(seq, ",nouser_xattr");
981 #ifdef CONFIG_EROFS_FS_POSIX_ACL
982 if (test_opt(opt, POSIX_ACL))
983 seq_puts(seq, ",acl");
985 seq_puts(seq, ",noacl");
987 #ifdef CONFIG_EROFS_FS_ZIP
988 if (opt->cache_strategy == EROFS_ZIP_CACHE_DISABLED)
989 seq_puts(seq, ",cache_strategy=disabled");
990 else if (opt->cache_strategy == EROFS_ZIP_CACHE_READAHEAD)
991 seq_puts(seq, ",cache_strategy=readahead");
992 else if (opt->cache_strategy == EROFS_ZIP_CACHE_READAROUND)
993 seq_puts(seq, ",cache_strategy=readaround");
995 if (test_opt(opt, DAX_ALWAYS))
996 seq_puts(seq, ",dax=always");
997 if (test_opt(opt, DAX_NEVER))
998 seq_puts(seq, ",dax=never");
999 #ifdef CONFIG_EROFS_FS_ONDEMAND
1001 seq_printf(seq, ",fsid=%s", sbi->fsid);
1003 seq_printf(seq, ",domain_id=%s", sbi->domain_id);
1008 const struct super_operations erofs_sops = {
1009 .put_super = erofs_put_super,
1010 .alloc_inode = erofs_alloc_inode,
1011 .free_inode = erofs_free_inode,
1012 .statfs = erofs_statfs,
1013 .show_options = erofs_show_options,
1016 module_init(erofs_module_init);
1017 module_exit(erofs_module_exit);
1019 MODULE_DESCRIPTION("Enhanced ROM File System");
1020 MODULE_AUTHOR("Gao Xiang, Chao Yu, Miao Xie, CONSUMER BG, HUAWEI Inc.");
1021 MODULE_LICENSE("GPL");