xref: /openbmc/linux/fs/erofs/super.c (revision e481ff3f)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2017-2018 HUAWEI, Inc.
4  *             https://www.huawei.com/
5  */
6 #include <linux/module.h>
7 #include <linux/buffer_head.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 "xattr.h"
15 
16 #define CREATE_TRACE_POINTS
17 #include <trace/events/erofs.h>
18 
19 static struct kmem_cache *erofs_inode_cachep __read_mostly;
20 
21 void _erofs_err(struct super_block *sb, const char *function,
22 		const char *fmt, ...)
23 {
24 	struct va_format vaf;
25 	va_list args;
26 
27 	va_start(args, fmt);
28 
29 	vaf.fmt = fmt;
30 	vaf.va = &args;
31 
32 	pr_err("(device %s): %s: %pV", sb->s_id, function, &vaf);
33 	va_end(args);
34 }
35 
36 void _erofs_info(struct super_block *sb, const char *function,
37 		 const char *fmt, ...)
38 {
39 	struct va_format vaf;
40 	va_list args;
41 
42 	va_start(args, fmt);
43 
44 	vaf.fmt = fmt;
45 	vaf.va = &args;
46 
47 	pr_info("(device %s): %pV", sb->s_id, &vaf);
48 	va_end(args);
49 }
50 
51 static int erofs_superblock_csum_verify(struct super_block *sb, void *sbdata)
52 {
53 	struct erofs_super_block *dsb;
54 	u32 expected_crc, crc;
55 
56 	dsb = kmemdup(sbdata + EROFS_SUPER_OFFSET,
57 		      EROFS_BLKSIZ - EROFS_SUPER_OFFSET, GFP_KERNEL);
58 	if (!dsb)
59 		return -ENOMEM;
60 
61 	expected_crc = le32_to_cpu(dsb->checksum);
62 	dsb->checksum = 0;
63 	/* to allow for x86 boot sectors and other oddities. */
64 	crc = crc32c(~0, dsb, EROFS_BLKSIZ - EROFS_SUPER_OFFSET);
65 	kfree(dsb);
66 
67 	if (crc != expected_crc) {
68 		erofs_err(sb, "invalid checksum 0x%08x, 0x%08x expected",
69 			  crc, expected_crc);
70 		return -EBADMSG;
71 	}
72 	return 0;
73 }
74 
75 static void erofs_inode_init_once(void *ptr)
76 {
77 	struct erofs_inode *vi = ptr;
78 
79 	inode_init_once(&vi->vfs_inode);
80 }
81 
82 static struct inode *erofs_alloc_inode(struct super_block *sb)
83 {
84 	struct erofs_inode *vi =
85 		kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL);
86 
87 	if (!vi)
88 		return NULL;
89 
90 	/* zero out everything except vfs_inode */
91 	memset(vi, 0, offsetof(struct erofs_inode, vfs_inode));
92 	return &vi->vfs_inode;
93 }
94 
95 static void erofs_free_inode(struct inode *inode)
96 {
97 	struct erofs_inode *vi = EROFS_I(inode);
98 
99 	/* be careful of RCU symlink path */
100 	if (inode->i_op == &erofs_fast_symlink_iops)
101 		kfree(inode->i_link);
102 	kfree(vi->xattr_shared_xattrs);
103 
104 	kmem_cache_free(erofs_inode_cachep, vi);
105 }
106 
107 static bool check_layout_compatibility(struct super_block *sb,
108 				       struct erofs_super_block *dsb)
109 {
110 	const unsigned int feature = le32_to_cpu(dsb->feature_incompat);
111 
112 	EROFS_SB(sb)->feature_incompat = feature;
113 
114 	/* check if current kernel meets all mandatory requirements */
115 	if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) {
116 		erofs_err(sb,
117 			  "unidentified incompatible feature %x, please upgrade kernel version",
118 			   feature & ~EROFS_ALL_FEATURE_INCOMPAT);
119 		return false;
120 	}
121 	return true;
122 }
123 
124 #ifdef CONFIG_EROFS_FS_ZIP
125 /* read variable-sized metadata, offset will be aligned by 4-byte */
126 static void *erofs_read_metadata(struct super_block *sb, struct page **pagep,
127 				 erofs_off_t *offset, int *lengthp)
128 {
129 	struct page *page = *pagep;
130 	u8 *buffer, *ptr;
131 	int len, i, cnt;
132 	erofs_blk_t blk;
133 
134 	*offset = round_up(*offset, 4);
135 	blk = erofs_blknr(*offset);
136 
137 	if (!page || page->index != blk) {
138 		if (page) {
139 			unlock_page(page);
140 			put_page(page);
141 		}
142 		page = erofs_get_meta_page(sb, blk);
143 		if (IS_ERR(page))
144 			goto err_nullpage;
145 	}
146 
147 	ptr = kmap(page);
148 	len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(*offset)]);
149 	if (!len)
150 		len = U16_MAX + 1;
151 	buffer = kmalloc(len, GFP_KERNEL);
152 	if (!buffer) {
153 		buffer = ERR_PTR(-ENOMEM);
154 		goto out;
155 	}
156 	*offset += sizeof(__le16);
157 	*lengthp = len;
158 
159 	for (i = 0; i < len; i += cnt) {
160 		cnt = min(EROFS_BLKSIZ - (int)erofs_blkoff(*offset), len - i);
161 		blk = erofs_blknr(*offset);
162 
163 		if (!page || page->index != blk) {
164 			if (page) {
165 				kunmap(page);
166 				unlock_page(page);
167 				put_page(page);
168 			}
169 			page = erofs_get_meta_page(sb, blk);
170 			if (IS_ERR(page)) {
171 				kfree(buffer);
172 				goto err_nullpage;
173 			}
174 			ptr = kmap(page);
175 		}
176 		memcpy(buffer + i, ptr + erofs_blkoff(*offset), cnt);
177 		*offset += cnt;
178 	}
179 out:
180 	kunmap(page);
181 	*pagep = page;
182 	return buffer;
183 err_nullpage:
184 	*pagep = NULL;
185 	return page;
186 }
187 
188 static int erofs_load_compr_cfgs(struct super_block *sb,
189 				 struct erofs_super_block *dsb)
190 {
191 	struct erofs_sb_info *sbi;
192 	struct page *page;
193 	unsigned int algs, alg;
194 	erofs_off_t offset;
195 	int size, ret;
196 
197 	sbi = EROFS_SB(sb);
198 	sbi->available_compr_algs = le16_to_cpu(dsb->u1.available_compr_algs);
199 
200 	if (sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS) {
201 		erofs_err(sb, "try to load compressed fs with unsupported algorithms %x",
202 			  sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS);
203 		return -EINVAL;
204 	}
205 
206 	offset = EROFS_SUPER_OFFSET + sbi->sb_size;
207 	page = NULL;
208 	alg = 0;
209 	ret = 0;
210 
211 	for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) {
212 		void *data;
213 
214 		if (!(algs & 1))
215 			continue;
216 
217 		data = erofs_read_metadata(sb, &page, &offset, &size);
218 		if (IS_ERR(data)) {
219 			ret = PTR_ERR(data);
220 			goto err;
221 		}
222 
223 		switch (alg) {
224 		case Z_EROFS_COMPRESSION_LZ4:
225 			ret = z_erofs_load_lz4_config(sb, dsb, data, size);
226 			break;
227 		default:
228 			DBG_BUGON(1);
229 			ret = -EFAULT;
230 		}
231 		kfree(data);
232 		if (ret)
233 			goto err;
234 	}
235 err:
236 	if (page) {
237 		unlock_page(page);
238 		put_page(page);
239 	}
240 	return ret;
241 }
242 #else
243 static int erofs_load_compr_cfgs(struct super_block *sb,
244 				 struct erofs_super_block *dsb)
245 {
246 	if (dsb->u1.available_compr_algs) {
247 		erofs_err(sb, "try to load compressed fs when compression is disabled");
248 		return -EINVAL;
249 	}
250 	return 0;
251 }
252 #endif
253 
254 static int erofs_read_superblock(struct super_block *sb)
255 {
256 	struct erofs_sb_info *sbi;
257 	struct page *page;
258 	struct erofs_super_block *dsb;
259 	unsigned int blkszbits;
260 	void *data;
261 	int ret;
262 
263 	page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
264 	if (IS_ERR(page)) {
265 		erofs_err(sb, "cannot read erofs superblock");
266 		return PTR_ERR(page);
267 	}
268 
269 	sbi = EROFS_SB(sb);
270 
271 	data = kmap(page);
272 	dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
273 
274 	ret = -EINVAL;
275 	if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
276 		erofs_err(sb, "cannot find valid erofs superblock");
277 		goto out;
278 	}
279 
280 	sbi->feature_compat = le32_to_cpu(dsb->feature_compat);
281 	if (erofs_sb_has_sb_chksum(sbi)) {
282 		ret = erofs_superblock_csum_verify(sb, data);
283 		if (ret)
284 			goto out;
285 	}
286 
287 	ret = -EINVAL;
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