Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfs: Convert cramfs to use the new mount API

Convert the cramfs filesystem to the new internal mount API as the old
one will be obsoleted and removed. This allows greater flexibility in
communication of mount parameters between userspace, the VFS and the
filesystem.

See Documentation/filesystems/mount_api.txt for more information.

Signed-off-by: David Howells <dhowells@redhat.com>
Tested-by: Nicolas Pitre <nico@fluxnic.net>
Acked-by: Nicolas Pitre <nico@fluxnic.net>
cc: linux-mtd@lists.infradead.org
cc: linux-block@vger.kernel.org
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

David Howells and committed by
Al Viro
74f78fc5 b9417599

+39 -30
+39 -30
fs/cramfs/inode.c
··· 24 24 #include <linux/blkdev.h> 25 25 #include <linux/mtd/mtd.h> 26 26 #include <linux/mtd/super.h> 27 + #include <linux/fs_context.h> 27 28 #include <linux/slab.h> 28 29 #include <linux/vfs.h> 29 30 #include <linux/mutex.h> ··· 507 506 kfree(sbi); 508 507 } 509 508 510 - static int cramfs_remount(struct super_block *sb, int *flags, char *data) 509 + static int cramfs_reconfigure(struct fs_context *fc) 511 510 { 512 - sync_filesystem(sb); 513 - *flags |= SB_RDONLY; 511 + sync_filesystem(fc->root->d_sb); 512 + fc->sb_flags |= SB_RDONLY; 514 513 return 0; 515 514 } 516 515 517 - static int cramfs_read_super(struct super_block *sb, 518 - struct cramfs_super *super, int silent) 516 + static int cramfs_read_super(struct super_block *sb, struct fs_context *fc, 517 + struct cramfs_super *super) 519 518 { 520 519 struct cramfs_sb_info *sbi = CRAMFS_SB(sb); 521 520 unsigned long root_offset; 521 + bool silent = fc->sb_flags & SB_SILENT; 522 522 523 523 /* We don't know the real size yet */ 524 524 sbi->size = PAGE_SIZE; ··· 534 532 /* check for wrong endianness */ 535 533 if (super->magic == CRAMFS_MAGIC_WEND) { 536 534 if (!silent) 537 - pr_err("wrong endianness\n"); 535 + errorf(fc, "cramfs: wrong endianness"); 538 536 return -EINVAL; 539 537 } 540 538 ··· 546 544 mutex_unlock(&read_mutex); 547 545 if (super->magic != CRAMFS_MAGIC) { 548 546 if (super->magic == CRAMFS_MAGIC_WEND && !silent) 549 - pr_err("wrong endianness\n"); 547 + errorf(fc, "cramfs: wrong endianness"); 550 548 else if (!silent) 551 - pr_err("wrong magic\n"); 549 + errorf(fc, "cramfs: wrong magic"); 552 550 return -EINVAL; 553 551 } 554 552 } 555 553 556 554 /* get feature flags first */ 557 555 if (super->flags & ~CRAMFS_SUPPORTED_FLAGS) { 558 - pr_err("unsupported filesystem features\n"); 556 + errorf(fc, "cramfs: unsupported filesystem features"); 559 557 return -EINVAL; 560 558 } 561 559 562 560 /* Check that the root inode is in a sane state */ 563 561 if (!S_ISDIR(super->root.mode)) { 564 - pr_err("root is not a directory\n"); 562 + errorf(fc, "cramfs: root is not a directory"); 565 563 return -EINVAL; 566 564 } 567 565 /* correct strange, hard-coded permissions of mkcramfs */ ··· 580 578 sbi->magic = super->magic; 581 579 sbi->flags = super->flags; 582 580 if (root_offset == 0) 583 - pr_info("empty filesystem"); 581 + infof(fc, "cramfs: empty filesystem"); 584 582 else if (!(super->flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) && 585 583 ((root_offset != sizeof(struct cramfs_super)) && 586 584 (root_offset != 512 + sizeof(struct cramfs_super)))) 587 585 { 588 - pr_err("bad root offset %lu\n", root_offset); 586 + errorf(fc, "cramfs: bad root offset %lu", root_offset); 589 587 return -EINVAL; 590 588 } 591 589 ··· 609 607 return 0; 610 608 } 611 609 612 - static int cramfs_blkdev_fill_super(struct super_block *sb, void *data, 613 - int silent) 610 + static int cramfs_blkdev_fill_super(struct super_block *sb, struct fs_context *fc) 614 611 { 615 612 struct cramfs_sb_info *sbi; 616 613 struct cramfs_super super; ··· 624 623 for (i = 0; i < READ_BUFFERS; i++) 625 624 buffer_blocknr[i] = -1; 626 625 627 - err = cramfs_read_super(sb, &super, silent); 626 + err = cramfs_read_super(sb, fc, &super); 628 627 if (err) 629 628 return err; 630 629 return cramfs_finalize_super(sb, &super.root); 631 630 } 632 631 633 - static int cramfs_mtd_fill_super(struct super_block *sb, void *data, 634 - int silent) 632 + static int cramfs_mtd_fill_super(struct super_block *sb, struct fs_context *fc) 635 633 { 636 634 struct cramfs_sb_info *sbi; 637 635 struct cramfs_super super; ··· 652 652 653 653 pr_info("checking physical address %pap for linear cramfs image\n", 654 654 &sbi->linear_phys_addr); 655 - err = cramfs_read_super(sb, &super, silent); 655 + err = cramfs_read_super(sb, fc, &super); 656 656 if (err) 657 657 return err; 658 658 ··· 947 947 }; 948 948 949 949 static const struct super_operations cramfs_ops = { 950 - .remount_fs = cramfs_remount, 951 950 .statfs = cramfs_statfs, 952 951 }; 953 952 954 - static struct dentry *cramfs_mount(struct file_system_type *fs_type, int flags, 955 - const char *dev_name, void *data) 953 + static int cramfs_get_tree(struct fs_context *fc) 956 954 { 957 - struct dentry *ret = ERR_PTR(-ENOPROTOOPT); 955 + int ret = -ENOPROTOOPT; 958 956 959 957 if (IS_ENABLED(CONFIG_CRAMFS_MTD)) { 960 - ret = mount_mtd(fs_type, flags, dev_name, data, 961 - cramfs_mtd_fill_super); 962 - if (!IS_ERR(ret)) 958 + ret = get_tree_mtd(fc, cramfs_mtd_fill_super); 959 + if (ret < 0) 963 960 return ret; 964 961 } 965 - if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV)) { 966 - ret = mount_bdev(fs_type, flags, dev_name, data, 967 - cramfs_blkdev_fill_super); 968 - } 962 + if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV)) 963 + ret = get_tree_bdev(fc, cramfs_blkdev_fill_super); 969 964 return ret; 965 + } 966 + 967 + static const struct fs_context_operations cramfs_context_ops = { 968 + .get_tree = cramfs_get_tree, 969 + .reconfigure = cramfs_reconfigure, 970 + }; 971 + 972 + /* 973 + * Set up the filesystem mount context. 974 + */ 975 + static int cramfs_init_fs_context(struct fs_context *fc) 976 + { 977 + fc->ops = &cramfs_context_ops; 978 + return 0; 970 979 } 971 980 972 981 static struct file_system_type cramfs_fs_type = { 973 982 .owner = THIS_MODULE, 974 983 .name = "cramfs", 975 - .mount = cramfs_mount, 984 + .init_fs_context = cramfs_init_fs_context, 976 985 .kill_sb = cramfs_kill_sb, 977 986 .fs_flags = FS_REQUIRES_DEV, 978 987 };