Commit 74f78fc5 authored by David Howells's avatar David Howells Committed by Al Viro

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: default avatarDavid Howells <dhowells@redhat.com>
Tested-by: default avatarNicolas Pitre <nico@fluxnic.net>
Acked-by: default avatarNicolas Pitre <nico@fluxnic.net>
cc: linux-mtd@lists.infradead.org
cc: linux-block@vger.kernel.org
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent b9417599
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#include <linux/mtd/super.h> #include <linux/mtd/super.h>
#include <linux/fs_context.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/vfs.h> #include <linux/vfs.h>
#include <linux/mutex.h> #include <linux/mutex.h>
...@@ -506,18 +507,19 @@ static void cramfs_kill_sb(struct super_block *sb) ...@@ -506,18 +507,19 @@ static void cramfs_kill_sb(struct super_block *sb)
kfree(sbi); kfree(sbi);
} }
static int cramfs_remount(struct super_block *sb, int *flags, char *data) static int cramfs_reconfigure(struct fs_context *fc)
{ {
sync_filesystem(sb); sync_filesystem(fc->root->d_sb);
*flags |= SB_RDONLY; fc->sb_flags |= SB_RDONLY;
return 0; return 0;
} }
static int cramfs_read_super(struct super_block *sb, static int cramfs_read_super(struct super_block *sb, struct fs_context *fc,
struct cramfs_super *super, int silent) struct cramfs_super *super)
{ {
struct cramfs_sb_info *sbi = CRAMFS_SB(sb); struct cramfs_sb_info *sbi = CRAMFS_SB(sb);
unsigned long root_offset; unsigned long root_offset;
bool silent = fc->sb_flags & SB_SILENT;
/* We don't know the real size yet */ /* We don't know the real size yet */
sbi->size = PAGE_SIZE; sbi->size = PAGE_SIZE;
...@@ -532,7 +534,7 @@ static int cramfs_read_super(struct super_block *sb, ...@@ -532,7 +534,7 @@ static int cramfs_read_super(struct super_block *sb,
/* check for wrong endianness */ /* check for wrong endianness */
if (super->magic == CRAMFS_MAGIC_WEND) { if (super->magic == CRAMFS_MAGIC_WEND) {
if (!silent) if (!silent)
pr_err("wrong endianness\n"); errorf(fc, "cramfs: wrong endianness");
return -EINVAL; return -EINVAL;
} }
...@@ -544,22 +546,22 @@ static int cramfs_read_super(struct super_block *sb, ...@@ -544,22 +546,22 @@ static int cramfs_read_super(struct super_block *sb,
mutex_unlock(&read_mutex); mutex_unlock(&read_mutex);
if (super->magic != CRAMFS_MAGIC) { if (super->magic != CRAMFS_MAGIC) {
if (super->magic == CRAMFS_MAGIC_WEND && !silent) if (super->magic == CRAMFS_MAGIC_WEND && !silent)
pr_err("wrong endianness\n"); errorf(fc, "cramfs: wrong endianness");
else if (!silent) else if (!silent)
pr_err("wrong magic\n"); errorf(fc, "cramfs: wrong magic");
return -EINVAL; return -EINVAL;
} }
} }
/* get feature flags first */ /* get feature flags first */
if (super->flags & ~CRAMFS_SUPPORTED_FLAGS) { if (super->flags & ~CRAMFS_SUPPORTED_FLAGS) {
pr_err("unsupported filesystem features\n"); errorf(fc, "cramfs: unsupported filesystem features");
return -EINVAL; return -EINVAL;
} }
/* Check that the root inode is in a sane state */ /* Check that the root inode is in a sane state */
if (!S_ISDIR(super->root.mode)) { if (!S_ISDIR(super->root.mode)) {
pr_err("root is not a directory\n"); errorf(fc, "cramfs: root is not a directory");
return -EINVAL; return -EINVAL;
} }
/* correct strange, hard-coded permissions of mkcramfs */ /* correct strange, hard-coded permissions of mkcramfs */
...@@ -578,12 +580,12 @@ static int cramfs_read_super(struct super_block *sb, ...@@ -578,12 +580,12 @@ static int cramfs_read_super(struct super_block *sb,
sbi->magic = super->magic; sbi->magic = super->magic;
sbi->flags = super->flags; sbi->flags = super->flags;
if (root_offset == 0) if (root_offset == 0)
pr_info("empty filesystem"); infof(fc, "cramfs: empty filesystem");
else if (!(super->flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) && else if (!(super->flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) &&
((root_offset != sizeof(struct cramfs_super)) && ((root_offset != sizeof(struct cramfs_super)) &&
(root_offset != 512 + sizeof(struct cramfs_super)))) (root_offset != 512 + sizeof(struct cramfs_super))))
{ {
pr_err("bad root offset %lu\n", root_offset); errorf(fc, "cramfs: bad root offset %lu", root_offset);
return -EINVAL; return -EINVAL;
} }
...@@ -607,8 +609,7 @@ static int cramfs_finalize_super(struct super_block *sb, ...@@ -607,8 +609,7 @@ static int cramfs_finalize_super(struct super_block *sb,
return 0; return 0;
} }
static int cramfs_blkdev_fill_super(struct super_block *sb, void *data, static int cramfs_blkdev_fill_super(struct super_block *sb, struct fs_context *fc)
int silent)
{ {
struct cramfs_sb_info *sbi; struct cramfs_sb_info *sbi;
struct cramfs_super super; struct cramfs_super super;
...@@ -623,14 +624,13 @@ static int cramfs_blkdev_fill_super(struct super_block *sb, void *data, ...@@ -623,14 +624,13 @@ static int cramfs_blkdev_fill_super(struct super_block *sb, void *data,
for (i = 0; i < READ_BUFFERS; i++) for (i = 0; i < READ_BUFFERS; i++)
buffer_blocknr[i] = -1; buffer_blocknr[i] = -1;
err = cramfs_read_super(sb, &super, silent); err = cramfs_read_super(sb, fc, &super);
if (err) if (err)
return err; return err;
return cramfs_finalize_super(sb, &super.root); return cramfs_finalize_super(sb, &super.root);
} }
static int cramfs_mtd_fill_super(struct super_block *sb, void *data, static int cramfs_mtd_fill_super(struct super_block *sb, struct fs_context *fc)
int silent)
{ {
struct cramfs_sb_info *sbi; struct cramfs_sb_info *sbi;
struct cramfs_super super; struct cramfs_super super;
...@@ -652,7 +652,7 @@ static int cramfs_mtd_fill_super(struct super_block *sb, void *data, ...@@ -652,7 +652,7 @@ static int cramfs_mtd_fill_super(struct super_block *sb, void *data,
pr_info("checking physical address %pap for linear cramfs image\n", pr_info("checking physical address %pap for linear cramfs image\n",
&sbi->linear_phys_addr); &sbi->linear_phys_addr);
err = cramfs_read_super(sb, &super, silent); err = cramfs_read_super(sb, fc, &super);
if (err) if (err)
return err; return err;
...@@ -947,32 +947,41 @@ static const struct inode_operations cramfs_dir_inode_operations = { ...@@ -947,32 +947,41 @@ static const struct inode_operations cramfs_dir_inode_operations = {
}; };
static const struct super_operations cramfs_ops = { static const struct super_operations cramfs_ops = {
.remount_fs = cramfs_remount,
.statfs = cramfs_statfs, .statfs = cramfs_statfs,
}; };
static struct dentry *cramfs_mount(struct file_system_type *fs_type, int flags, static int cramfs_get_tree(struct fs_context *fc)
const char *dev_name, void *data)
{ {
struct dentry *ret = ERR_PTR(-ENOPROTOOPT); int ret = -ENOPROTOOPT;
if (IS_ENABLED(CONFIG_CRAMFS_MTD)) { if (IS_ENABLED(CONFIG_CRAMFS_MTD)) {
ret = mount_mtd(fs_type, flags, dev_name, data, ret = get_tree_mtd(fc, cramfs_mtd_fill_super);
cramfs_mtd_fill_super); if (ret < 0)
if (!IS_ERR(ret))
return ret; return ret;
} }
if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV)) { if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV))
ret = mount_bdev(fs_type, flags, dev_name, data, ret = get_tree_bdev(fc, cramfs_blkdev_fill_super);
cramfs_blkdev_fill_super);
}
return ret; return ret;
} }
static const struct fs_context_operations cramfs_context_ops = {
.get_tree = cramfs_get_tree,
.reconfigure = cramfs_reconfigure,
};
/*
* Set up the filesystem mount context.
*/
static int cramfs_init_fs_context(struct fs_context *fc)
{
fc->ops = &cramfs_context_ops;
return 0;
}
static struct file_system_type cramfs_fs_type = { static struct file_system_type cramfs_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "cramfs", .name = "cramfs",
.mount = cramfs_mount, .init_fs_context = cramfs_init_fs_context,
.kill_sb = cramfs_kill_sb, .kill_sb = cramfs_kill_sb,
.fs_flags = FS_REQUIRES_DEV, .fs_flags = FS_REQUIRES_DEV,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment