xref: /openbmc/linux/fs/erofs/super.c (revision e3211e41)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2017-2018 HUAWEI, Inc.
4  *             https://www.huawei.com/
5  * Created by Gao Xiang <gaoxiang25@huawei.com>
6  */
7 #include <linux/module.h>
8 #include <linux/buffer_head.h>
9 #include <linux/statfs.h>
10 #include <linux/parser.h>
11 #include <linux/seq_file.h>
12 #include <linux/crc32c.h>
13 #include <linux/fs_context.h>
14 #include <linux/fs_parser.h>
15 #include "xattr.h"
16 
17 #define CREATE_TRACE_POINTS
18 #include <trace/events/erofs.h>
19 
20 static struct kmem_cache *erofs_inode_cachep __read_mostly;
21 
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 
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 
76 static void erofs_inode_init_once(void *ptr)
77 {
78 	struct erofs_inode *vi = ptr;
79 
80 	inode_init_once(&vi->vfs_inode);
81 }
82 
83 static struct inode *erofs_alloc_inode(struct super_block *sb)
84 {
85 	struct erofs_inode *vi =
86 		kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL);
87 
88 	if (!vi)
89 		return NULL;
90 
91 	/* zero out everything except vfs_inode */
92 	memset(vi, 0, offsetof(struct erofs_inode, vfs_inode));
93 	return &vi->vfs_inode;
94 }
95 
96 static void erofs_free_inode(struct inode *inode)
97 {
98 	struct erofs_inode *vi = EROFS_I(inode);
99 
100 	/* be careful of RCU symlink path */
101 	if (inode->i_op == &erofs_fast_symlink_iops)
102 		kfree(inode->i_link);
103 	kfree(vi->xattr_shared_xattrs);
104 
105 	kmem_cache_free(erofs_inode_cachep, vi);
106 }
107 
108 static bool check_layout_compatibility(struct super_block *sb,
109 				       struct erofs_super_block *dsb)
110 {
111 	const unsigned int feature = le32_to_cpu(dsb->feature_incompat);
112 
113 	EROFS_SB(sb)->feature_incompat = feature;
114 
115 	/* check if current kernel meets all mandatory requirements */
116 	if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) {
117 		erofs_err(sb,
118 			  "unidentified incompatible feature %x, please upgrade kernel version",
119 			   feature & ~EROFS_ALL_FEATURE_INCOMPAT);
120 		return false;
121 	}
122 	return true;
123 }
124 
125 #ifdef CONFIG_EROFS_FS_ZIP
126 /* read variable-sized metadata, offset will be aligned by 4-byte */
127 static void *erofs_read_metadata(struct super_block *sb, struct page **pagep,
128 				 erofs_off_t *offset, int *lengthp)
129 {
130 	struct page *page = *pagep;
131 	u8 *buffer, *ptr;
132 	int len, i, cnt;
133 	erofs_blk_t blk;
134 
135 	*offset = round_up(*offset, 4);
136 	blk = erofs_blknr(*offset);
137 
138 	if (!page || page->index != blk) {
139 		if (page) {
140 			unlock_page(page);
141 			put_page(page);
142 		}
143 		page = erofs_get_meta_page(sb, blk);
144 		if (IS_ERR(page))
145 			goto err_nullpage;
146 	}
147 
148 	ptr = kmap(page);
149 	len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(*offset)]);
150 	if (!len)
151 		len = U16_MAX + 1;
152 	buffer = kmalloc(len, GFP_KERNEL);
153 	if (!buffer) {
154 		buffer = ERR_PTR(-ENOMEM);
155 		goto out;
156 	}
157 	*offset += sizeof(__le16);
158 	*lengthp = len;
159 
160 	for (i = 0; i < len; i += cnt) {
161 		cnt = min(EROFS_BLKSIZ - (int)erofs_blkoff(*offset), len - i);
162 		blk = erofs_blknr(*offset);
163 
164 		if (!page || page->index != blk) {
165 			if (page) {
166 				kunmap(page);
167 				unlock_page(page);
168 				put_page(page);
169 			}
170 			page = erofs_get_meta_page(sb, blk);
171 			if (IS_ERR(page)) {
172 				kfree(buffer);
173 				goto err_nullpage;
174 			}
175 			ptr = kmap(page);
176 		}
177 		memcpy(buffer + i, ptr + erofs_blkoff(*offset), cnt);
178 		*offset += cnt;
179 	}
180 out:
181 	kunmap(page);
182 	*pagep = page;
183 	return buffer;
184 err_nullpage:
185 	*pagep = NULL;
186 	return page;
187 }
188 
189 static int erofs_load_compr_cfgs(struct super_block *sb,
190 				 struct erofs_super_block *dsb)
191 {
192 	struct erofs_sb_info *sbi;
193 	struct page *page;
194 	unsigned int algs, alg;
195 	erofs_off_t offset;
196 	int size, ret;
197 
198 	sbi = EROFS_SB(sb);
199 	sbi->available_compr_algs = le16_to_cpu(dsb->u1.available_compr_algs);
200 
201 	if (sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS) {
202 		erofs_err(sb, "try to load compressed fs with unsupported algorithms %x",
203 			  sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS);
204 		return -EINVAL;
205 	}
206 
207 	offset = EROFS_SUPER_OFFSET + sbi->sb_size;
208 	page = NULL;
209 	alg = 0;
210 	ret = 0;
211 
212 	for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) {
213 		void *data;
214 
215 		if (!(algs & 1))
216 			continue;
217 
218 		data = erofs_read_metadata(sb, &page, &offset, &size);
219 		if (IS_ERR(data)) {
220 			ret = PTR_ERR(data);
221 			goto err;
222 		}
223 
224 		switch (alg) {
225 		case Z_EROFS_COMPRESSION_LZ4:
226 			ret = z_erofs_load_lz4_config(sb, dsb, data, size);
227 			break;
228 		default:
229 			DBG_BUGON(1);
230 			ret = -EFAULT;
231 		}
232 		kfree(data);
233 		if (ret)
234 			goto err;
235 	}
236 err:
237 	if (page) {
238 		unlock_page(page);
239 		put_page(page);
240 	}
241 	return ret;
242 }
243 #else
244 static int erofs_load_compr_cfgs(struct super_block *sb,
245 				 struct erofs_super_block *dsb)
246 {
247 	if (dsb->u1.available_compr_algs) {
248 		erofs_err(sb, "try to load compressed fs when compression is disabled");
249 		return -EINVAL;
250 	}
251 	return 0;
252 }
253 #endif
254 
255 static int erofs_read_superblock(struct super_block *sb)
256 {
257 	struct erofs_sb_info *sbi;
258 	struct page *page;
259 	struct erofs_super_block *dsb;
260 	unsigned int blkszbits;
261 	void *data;
262 	int ret;
263 
264 	page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
265 	if (IS_ERR(page)) {
266 		erofs_err(sb, "cannot read erofs superblock");
267 		return PTR_ERR(page);
268 	}
269 
270 	sbi = EROFS_SB(sb);
271 
272 	data = kmap(page);
273 	dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
274 
275 	ret = -EINVAL;
276 	if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
277 		erofs_err(sb, "cannot find valid erofs superblock");
278 		goto out;
279 	}
280 
281 	sbi->feature_compat = le32_to_cpu(dsb->feature_compat);
282 	if (erofs_sb_has_sb_chksum(sbi)) {
283 		ret = erofs_superblock_csum_verify(sb, data);
284 		if (ret)
285 			goto out;
286 	}
287 
288 	blkszbits = dsb->blkszbits;
289 	/* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
290 	if (blkszbits != LOG_BLOCK_SIZE) {
291 		erofs_err(sb, "blkszbits %u isn't supported on this platform",
292 			  blkszbits);
293 		goto out;
294 	}
295 
296 	if (!check_layout_compatibility(sb, dsb))
297 		goto out;
298 
299 	sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE;
300 	if (sbi->sb_size > EROFS_BLKSIZ) {
301 		erofs_err(sb, "invalid sb_extslots %u (more than a fs block)",
302 			  sbi->sb_size);
303 		goto out;
304 	}
305 	sbi->blocks = le32_to_cpu(dsb->blocks);
306 	sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
307 #ifdef CONFIG_EROFS_FS_XATTR
308 	sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
309 #endif
310 	sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
311 	sbi->root_nid = le16_to_cpu(dsb->root_nid);
312 	sbi->inos = le64_to_cpu(dsb->inos);
313 
314 	sbi->build_time = le64_to_cpu(dsb->build_time);
315 	sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec);
316 
317 	memcpy(&sb->s_uuid, dsb->uuid, sizeof(dsb->uuid));
318 
319 	ret = strscpy(sbi->volume_name, dsb->volume_name,
320 		      sizeof(dsb->volume_name));
321 	if (ret < 0) {	/* -E2BIG */
322 		erofs_err(sb, "bad volume name without NIL terminator");
323 		ret = -EFSCORRUPTED;
324 		goto out;
325 	}
326 
327 	/* parse on-disk compression configurations */
328 	if (erofs_sb_has_compr_cfgs(sbi))
329 		ret = erofs_load_compr_cfgs(sb, dsb);
330 	else
331 		ret = z_erofs_load_lz4_config(sb, dsb, NULL, 0);
332 out:
333 	kunmap(page);
334 	put_page(page);
335 	return ret;
336 }
337 
338 /* set up default EROFS parameters */
339 static void erofs_default_options(struct erofs_fs_context *ctx)
340 {
341 #ifdef CONFIG_EROFS_FS_ZIP
342 	ctx->cache_strategy = EROFS_ZIP_CACHE_READAROUND;
343 	ctx->max_sync_decompress_pages = 3;
344 	ctx->readahead_sync_decompress = false;
345 #endif
346 #ifdef CONFIG_EROFS_FS_XATTR
347 	set_opt(ctx, XATTR_USER);
348 #endif
349 #ifdef CONFIG_EROFS_FS_POSIX_ACL
350 	set_opt(ctx, POSIX_ACL);
351 #endif
352 }
353 
354 enum {
355 	Opt_user_xattr,
356 	Opt_acl,
357 	Opt_cache_strategy,
358 	Opt_err
359 };
360 
361 static const struct constant_table erofs_param_cache_strategy[] = {
362 	{"disabled",	EROFS_ZIP_CACHE_DISABLED},
363 	{"readahead",	EROFS_ZIP_CACHE_READAHEAD},
364 	{"readaround",	EROFS_ZIP_CACHE_READAROUND},
365 	{}
366 };
367 
368 static const struct fs_parameter_spec erofs_fs_parameters[] = {
369 	fsparam_flag_no("user_xattr",	Opt_user_xattr),
370 	fsparam_flag_no("acl",		Opt_acl),
371 	fsparam_enum("cache_strategy",	Opt_cache_strategy,
372 		     erofs_param_cache_strategy),
373 	{}
374 };
375 
376 static int erofs_fc_parse_param(struct fs_context *fc,
377 				struct fs_parameter *param)
378 {
379 	struct erofs_fs_context *ctx __maybe_unused = fc->fs_private;
380 	struct fs_parse_result result;
381 	int opt;
382 
383 	opt = fs_parse(fc, erofs_fs_parameters, param, &result);
384 	if (opt < 0)
385 		return opt;
386 
387 	switch (opt) {
388 	case Opt_user_xattr:
389 #ifdef CONFIG_EROFS_FS_XATTR
390 		if (result.boolean)
391 			set_opt(ctx, XATTR_USER);
392 		else
393 			clear_opt(ctx, XATTR_USER);
394 #else
395 		errorfc(fc, "{,no}user_xattr options not supported");
396 #endif
397 		break;
398 	case Opt_acl:
399 #ifdef CONFIG_EROFS_FS_POSIX_ACL
400 		if (result.boolean)
401 			set_opt(ctx, POSIX_ACL);
402 		else
403 			clear_opt(ctx, POSIX_ACL);
404 #else
405 		errorfc(fc, "{,no}acl options not supported");
406 #endif
407 		break;
408 	case Opt_cache_strategy:
409 #ifdef CONFIG_EROFS_FS_ZIP
410 		ctx->cache_strategy = result.uint_32;
411 #else
412 		errorfc(fc, "compression not supported, cache_strategy ignored");
413 #endif
414 		break;
415 	default:
416 		return -ENOPARAM;
417 	}
418 	return 0;
419 }
420 
421 #ifdef CONFIG_EROFS_FS_ZIP
422 static const struct address_space_operations managed_cache_aops;
423 
424 static int erofs_managed_cache_releasepage(struct page *page, gfp_t gfp_mask)
425 {
426 	int ret = 1;	/* 0 - busy */
427 	struct address_space *const mapping = page->mapping;
428 
429 	DBG_BUGON(!PageLocked(page));
430 	DBG_BUGON(mapping->a_ops != &managed_cache_aops);
431 
432 	if (PagePrivate(page))
433 		ret = erofs_try_to_free_cached_page(mapping, page);
434 
435 	return ret;
436 }
437 
438 static void erofs_managed_cache_invalidatepage(struct page *page,
439 					       unsigned int offset,
440 					       unsigned int length)
441 {
442 	const unsigned int stop = length + offset;
443 
444 	DBG_BUGON(!PageLocked(page));
445 
446 	/* Check for potential overflow in debug mode */
447 	DBG_BUGON(stop > PAGE_SIZE || stop < length);
448 
449 	if (offset == 0 && stop == PAGE_SIZE)
450 		while (!erofs_managed_cache_releasepage(page, GFP_NOFS))
451 			cond_resched();
452 }
453 
454 static const struct address_space_operations managed_cache_aops = {
455 	.releasepage = erofs_managed_cache_releasepage,
456 	.invalidatepage = erofs_managed_cache_invalidatepage,
457 };
458 
459 static int erofs_init_managed_cache(struct super_block *sb)
460 {
461 	struct erofs_sb_info *const sbi = EROFS_SB(sb);
462 	struct inode *const inode = new_inode(sb);
463 
464 	if (!inode)
465 		return -ENOMEM;
466 
467 	set_nlink(inode, 1);
468 	inode->i_size = OFFSET_MAX;
469 
470 	inode->i_mapping->a_ops = &managed_cache_aops;
471 	mapping_set_gfp_mask(inode->i_mapping,
472 			     GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE);
473 	sbi->managed_cache = inode;
474 	return 0;
475 }
476 #else
477 static int erofs_init_managed_cache(struct super_block *sb) { return 0; }
478 #endif
479 
480 static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
481 {
482 	struct inode *inode;
483 	struct erofs_sb_info *sbi;
484 	struct erofs_fs_context *ctx = fc->fs_private;
485 	int err;
486 
487 	sb->s_magic = EROFS_SUPER_MAGIC;
488 
489 	if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) {
490 		erofs_err(sb, "failed to set erofs blksize");
491 		return -EINVAL;
492 	}
493 
494 	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
495 	if (!sbi)
496 		return -ENOMEM;
497 
498 	sb->s_fs_info = sbi;
499 	err = erofs_read_superblock(sb);
500 	if (err)
501 		return err;
502 
503 	sb->s_flags |= SB_RDONLY | SB_NOATIME;
504 	sb->s_maxbytes = MAX_LFS_FILESIZE;
505 	sb->s_time_gran = 1;
506 
507 	sb->s_op = &erofs_sops;
508 	sb->s_xattr = erofs_xattr_handlers;
509 
510 	if (test_opt(ctx, POSIX_ACL))
511 		sb->s_flags |= SB_POSIXACL;
512 	else
513 		sb->s_flags &= ~SB_POSIXACL;
514 
515 	sbi->ctx = *ctx;
516 
517 #ifdef CONFIG_EROFS_FS_ZIP
518 	xa_init(&sbi->managed_pslots);
519 #endif
520 
521 	/* get the root inode */
522 	inode = erofs_iget(sb, ROOT_NID(sbi), true);
523 	if (IS_ERR(inode))
524 		return PTR_ERR(inode);
525 
526 	if (!S_ISDIR(inode->i_mode)) {
527 		erofs_err(sb, "rootino(nid %llu) is not a directory(i_mode %o)",
528 			  ROOT_NID(sbi), inode->i_mode);
529 		iput(inode);
530 		return -EINVAL;
531 	}
532 
533 	sb->s_root = d_make_root(inode);
534 	if (!sb->s_root)
535 		return -ENOMEM;
536 
537 	erofs_shrinker_register(sb);
538 	/* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */
539 	err = erofs_init_managed_cache(sb);
540 	if (err)
541 		return err;
542 
543 	erofs_info(sb, "mounted with root inode @ nid %llu.", ROOT_NID(sbi));
544 	return 0;
545 }
546 
547 static int erofs_fc_get_tree(struct fs_context *fc)
548 {
549 	return get_tree_bdev(fc, erofs_fc_fill_super);
550 }
551 
552 static int erofs_fc_reconfigure(struct fs_context *fc)
553 {
554 	struct super_block *sb = fc->root->d_sb;
555 	struct erofs_sb_info *sbi = EROFS_SB(sb);
556 	struct erofs_fs_context *ctx = fc->fs_private;
557 
558 	DBG_BUGON(!sb_rdonly(sb));
559 
560 	if (test_opt(ctx, POSIX_ACL))
561 		fc->sb_flags |= SB_POSIXACL;
562 	else
563 		fc->sb_flags &= ~SB_POSIXACL;
564 
565 	sbi->ctx = *ctx;
566 
567 	fc->sb_flags |= SB_RDONLY;
568 	return 0;
569 }
570 
571 static void erofs_fc_free(struct fs_context *fc)
572 {
573 	kfree(fc->fs_private);
574 }
575 
576 static const struct fs_context_operations erofs_context_ops = {
577 	.parse_param	= erofs_fc_parse_param,
578 	.get_tree       = erofs_fc_get_tree,
579 	.reconfigure    = erofs_fc_reconfigure,
580 	.free		= erofs_fc_free,
581 };
582 
583 static int erofs_init_fs_context(struct fs_context *fc)
584 {
585 	fc->fs_private = kzalloc(sizeof(struct erofs_fs_context), GFP_KERNEL);
586 	if (!fc->fs_private)
587 		return -ENOMEM;
588 
589 	/* set default mount options */
590 	erofs_default_options(fc->fs_private);
591 
592 	fc->ops = &erofs_context_ops;
593 
594 	return 0;
595 }
596 
597 /*
598  * could be triggered after deactivate_locked_super()
599  * is called, thus including umount and failed to initialize.
600  */
601 static void erofs_kill_sb(struct super_block *sb)
602 {
603 	struct erofs_sb_info *sbi;
604 
605 	WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
606 
607 	kill_block_super(sb);
608 
609 	sbi = EROFS_SB(sb);
610 	if (!sbi)
611 		return;
612 	kfree(sbi);
613 	sb->s_fs_info = NULL;
614 }
615 
616 /* called when ->s_root is non-NULL */
617 static void erofs_put_super(struct super_block *sb)
618 {
619 	struct erofs_sb_info *const sbi = EROFS_SB(sb);
620 
621 	DBG_BUGON(!sbi);
622 
623 	erofs_shrinker_unregister(sb);
624 #ifdef CONFIG_EROFS_FS_ZIP
625 	iput(sbi->managed_cache);
626 	sbi->managed_cache = NULL;
627 #endif
628 }
629 
630 static struct file_system_type erofs_fs_type = {
631 	.owner          = THIS_MODULE,
632 	.name           = "erofs",
633 	.init_fs_context = erofs_init_fs_context,
634 	.kill_sb        = erofs_kill_sb,
635 	.fs_flags       = FS_REQUIRES_DEV,
636 };
637 MODULE_ALIAS_FS("erofs");
638 
639 static int __init erofs_module_init(void)
640 {
641 	int err;
642 
643 	erofs_check_ondisk_layout_definitions();
644 
645 	erofs_inode_cachep = kmem_cache_create("erofs_inode",
646 					       sizeof(struct erofs_inode), 0,
647 					       SLAB_RECLAIM_ACCOUNT,
648 					       erofs_inode_init_once);
649 	if (!erofs_inode_cachep) {
650 		err = -ENOMEM;
651 		goto icache_err;
652 	}
653 
654 	err = erofs_init_shrinker();
655 	if (err)
656 		goto shrinker_err;
657 
658 	erofs_pcpubuf_init();
659 	err = z_erofs_init_zip_subsystem();
660 	if (err)
661 		goto zip_err;
662 
663 	err = register_filesystem(&erofs_fs_type);
664 	if (err)
665 		goto fs_err;
666 
667 	return 0;
668 
669 fs_err:
670 	z_erofs_exit_zip_subsystem();
671 zip_err:
672 	erofs_exit_shrinker();
673 shrinker_err:
674 	kmem_cache_destroy(erofs_inode_cachep);
675 icache_err:
676 	return err;
677 }
678 
679 static void __exit erofs_module_exit(void)
680 {
681 	unregister_filesystem(&erofs_fs_type);
682 	z_erofs_exit_zip_subsystem();
683 	erofs_exit_shrinker();
684 
685 	/* Ensure all RCU free inodes are safe before cache is destroyed. */
686 	rcu_barrier();
687 	kmem_cache_destroy(erofs_inode_cachep);
688 	erofs_pcpubuf_exit();
689 }
690 
691 /* get filesystem statistics */
692 static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
693 {
694 	struct super_block *sb = dentry->d_sb;
695 	struct erofs_sb_info *sbi = EROFS_SB(sb);
696 	u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
697 
698 	buf->f_type = sb->s_magic;
699 	buf->f_bsize = EROFS_BLKSIZ;
700 	buf->f_blocks = sbi->blocks;
701 	buf->f_bfree = buf->f_bavail = 0;
702 
703 	buf->f_files = ULLONG_MAX;
704 	buf->f_ffree = ULLONG_MAX - sbi->inos;
705 
706 	buf->f_namelen = EROFS_NAME_LEN;
707 
708 	buf->f_fsid    = u64_to_fsid(id);
709 	return 0;
710 }
711 
712 static int erofs_show_options(struct seq_file *seq, struct dentry *root)
713 {
714 	struct erofs_sb_info *sbi __maybe_unused = EROFS_SB(root->d_sb);
715 	struct erofs_fs_context *ctx __maybe_unused = &sbi->ctx;
716 
717 #ifdef CONFIG_EROFS_FS_XATTR
718 	if (test_opt(ctx, XATTR_USER))
719 		seq_puts(seq, ",user_xattr");
720 	else
721 		seq_puts(seq, ",nouser_xattr");
722 #endif
723 #ifdef CONFIG_EROFS_FS_POSIX_ACL
724 	if (test_opt(ctx, POSIX_ACL))
725 		seq_puts(seq, ",acl");
726 	else
727 		seq_puts(seq, ",noacl");
728 #endif
729 #ifdef CONFIG_EROFS_FS_ZIP
730 	if (ctx->cache_strategy == EROFS_ZIP_CACHE_DISABLED)
731 		seq_puts(seq, ",cache_strategy=disabled");
732 	else if (ctx->cache_strategy == EROFS_ZIP_CACHE_READAHEAD)
733 		seq_puts(seq, ",cache_strategy=readahead");
734 	else if (ctx->cache_strategy == EROFS_ZIP_CACHE_READAROUND)
735 		seq_puts(seq, ",cache_strategy=readaround");
736 #endif
737 	return 0;
738 }
739 
740 const struct super_operations erofs_sops = {
741 	.put_super = erofs_put_super,
742 	.alloc_inode = erofs_alloc_inode,
743 	.free_inode = erofs_free_inode,
744 	.statfs = erofs_statfs,
745 	.show_options = erofs_show_options,
746 };
747 
748 module_init(erofs_module_init);
749 module_exit(erofs_module_exit);
750 
751 MODULE_DESCRIPTION("Enhanced ROM File System");
752 MODULE_AUTHOR("Gao Xiang, Chao Yu, Miao Xie, CONSUMER BG, HUAWEI Inc.");
753 MODULE_LICENSE("GPL");
754 
755