mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 17:25:38 +00:00
adfs: convert adfs to use the new mount api
Convert the adfs filesystem to use the new mount API. Tested by comparing random mount & remount options before and after the change. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Link: https://lore.kernel.org/r/20240916172735.866916-2-sandeen@redhat.com Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
9020d0d844
commit
5fadeed64d
182
fs/adfs/super.c
182
fs/adfs/super.c
@ -6,7 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/parser.h>
|
#include <linux/fs_parser.h>
|
||||||
|
#include <linux/fs_context.h>
|
||||||
#include <linux/mount.h>
|
#include <linux/mount.h>
|
||||||
#include <linux/seq_file.h>
|
#include <linux/seq_file.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
@ -115,87 +116,61 @@ static int adfs_show_options(struct seq_file *seq, struct dentry *root)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {Opt_uid, Opt_gid, Opt_ownmask, Opt_othmask, Opt_ftsuffix, Opt_err};
|
enum {Opt_uid, Opt_gid, Opt_ownmask, Opt_othmask, Opt_ftsuffix};
|
||||||
|
|
||||||
static const match_table_t tokens = {
|
static const struct fs_parameter_spec adfs_param_spec[] = {
|
||||||
{Opt_uid, "uid=%u"},
|
fsparam_uid ("uid", Opt_uid),
|
||||||
{Opt_gid, "gid=%u"},
|
fsparam_gid ("gid", Opt_gid),
|
||||||
{Opt_ownmask, "ownmask=%o"},
|
fsparam_u32oct ("ownmask", Opt_ownmask),
|
||||||
{Opt_othmask, "othmask=%o"},
|
fsparam_u32oct ("othmask", Opt_othmask),
|
||||||
{Opt_ftsuffix, "ftsuffix=%u"},
|
fsparam_u32 ("ftsuffix", Opt_ftsuffix),
|
||||||
{Opt_err, NULL}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int parse_options(struct super_block *sb, struct adfs_sb_info *asb,
|
static int adfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
||||||
char *options)
|
|
||||||
{
|
{
|
||||||
char *p;
|
struct adfs_sb_info *asb = fc->s_fs_info;
|
||||||
int option;
|
struct fs_parse_result result;
|
||||||
|
int opt;
|
||||||
|
|
||||||
if (!options)
|
opt = fs_parse(fc, adfs_param_spec, param, &result);
|
||||||
return 0;
|
if (opt < 0)
|
||||||
|
return opt;
|
||||||
|
|
||||||
while ((p = strsep(&options, ",")) != NULL) {
|
switch (opt) {
|
||||||
substring_t args[MAX_OPT_ARGS];
|
case Opt_uid:
|
||||||
int token;
|
asb->s_uid = result.uid;
|
||||||
if (!*p)
|
break;
|
||||||
continue;
|
case Opt_gid:
|
||||||
|
asb->s_gid = result.gid;
|
||||||
token = match_token(p, tokens, args);
|
break;
|
||||||
switch (token) {
|
case Opt_ownmask:
|
||||||
case Opt_uid:
|
asb->s_owner_mask = result.uint_32;
|
||||||
if (match_int(args, &option))
|
break;
|
||||||
return -EINVAL;
|
case Opt_othmask:
|
||||||
asb->s_uid = make_kuid(current_user_ns(), option);
|
asb->s_other_mask = result.uint_32;
|
||||||
if (!uid_valid(asb->s_uid))
|
break;
|
||||||
return -EINVAL;
|
case Opt_ftsuffix:
|
||||||
break;
|
asb->s_ftsuffix = result.uint_32;
|
||||||
case Opt_gid:
|
break;
|
||||||
if (match_int(args, &option))
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
asb->s_gid = make_kgid(current_user_ns(), option);
|
|
||||||
if (!gid_valid(asb->s_gid))
|
|
||||||
return -EINVAL;
|
|
||||||
break;
|
|
||||||
case Opt_ownmask:
|
|
||||||
if (match_octal(args, &option))
|
|
||||||
return -EINVAL;
|
|
||||||
asb->s_owner_mask = option;
|
|
||||||
break;
|
|
||||||
case Opt_othmask:
|
|
||||||
if (match_octal(args, &option))
|
|
||||||
return -EINVAL;
|
|
||||||
asb->s_other_mask = option;
|
|
||||||
break;
|
|
||||||
case Opt_ftsuffix:
|
|
||||||
if (match_int(args, &option))
|
|
||||||
return -EINVAL;
|
|
||||||
asb->s_ftsuffix = option;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
adfs_msg(sb, KERN_ERR,
|
|
||||||
"unrecognised mount option \"%s\" or missing value",
|
|
||||||
p);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int adfs_remount(struct super_block *sb, int *flags, char *data)
|
static int adfs_reconfigure(struct fs_context *fc)
|
||||||
{
|
{
|
||||||
struct adfs_sb_info temp_asb;
|
struct adfs_sb_info *new_asb = fc->s_fs_info;
|
||||||
int ret;
|
struct adfs_sb_info *asb = ADFS_SB(fc->root->d_sb);
|
||||||
|
|
||||||
sync_filesystem(sb);
|
sync_filesystem(fc->root->d_sb);
|
||||||
*flags |= ADFS_SB_FLAGS;
|
fc->sb_flags |= ADFS_SB_FLAGS;
|
||||||
|
|
||||||
temp_asb = *ADFS_SB(sb);
|
/* Structure copy newly parsed options */
|
||||||
ret = parse_options(sb, &temp_asb, data);
|
*asb = *new_asb;
|
||||||
if (ret == 0)
|
|
||||||
*ADFS_SB(sb) = temp_asb;
|
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int adfs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
static int adfs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
||||||
@ -273,7 +248,6 @@ static const struct super_operations adfs_sops = {
|
|||||||
.write_inode = adfs_write_inode,
|
.write_inode = adfs_write_inode,
|
||||||
.put_super = adfs_put_super,
|
.put_super = adfs_put_super,
|
||||||
.statfs = adfs_statfs,
|
.statfs = adfs_statfs,
|
||||||
.remount_fs = adfs_remount,
|
|
||||||
.show_options = adfs_show_options,
|
.show_options = adfs_show_options,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -361,34 +335,21 @@ static int adfs_validate_dr0(struct super_block *sb, struct buffer_head *bh,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int adfs_fill_super(struct super_block *sb, void *data, int silent)
|
static int adfs_fill_super(struct super_block *sb, struct fs_context *fc)
|
||||||
{
|
{
|
||||||
struct adfs_discrecord *dr;
|
struct adfs_discrecord *dr;
|
||||||
struct object_info root_obj;
|
struct object_info root_obj;
|
||||||
struct adfs_sb_info *asb;
|
struct adfs_sb_info *asb = sb->s_fs_info;
|
||||||
struct inode *root;
|
struct inode *root;
|
||||||
int ret = -EINVAL;
|
int ret = -EINVAL;
|
||||||
|
int silent = fc->sb_flags & SB_SILENT;
|
||||||
|
|
||||||
sb->s_flags |= ADFS_SB_FLAGS;
|
sb->s_flags |= ADFS_SB_FLAGS;
|
||||||
|
|
||||||
asb = kzalloc(sizeof(*asb), GFP_KERNEL);
|
|
||||||
if (!asb)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
sb->s_fs_info = asb;
|
sb->s_fs_info = asb;
|
||||||
sb->s_magic = ADFS_SUPER_MAGIC;
|
sb->s_magic = ADFS_SUPER_MAGIC;
|
||||||
sb->s_time_gran = 10000000;
|
sb->s_time_gran = 10000000;
|
||||||
|
|
||||||
/* set default options */
|
|
||||||
asb->s_uid = GLOBAL_ROOT_UID;
|
|
||||||
asb->s_gid = GLOBAL_ROOT_GID;
|
|
||||||
asb->s_owner_mask = ADFS_DEFAULT_OWNER_MASK;
|
|
||||||
asb->s_other_mask = ADFS_DEFAULT_OTHER_MASK;
|
|
||||||
asb->s_ftsuffix = 0;
|
|
||||||
|
|
||||||
if (parse_options(sb, asb, data))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
/* Try to probe the filesystem boot block */
|
/* Try to probe the filesystem boot block */
|
||||||
ret = adfs_probe(sb, ADFS_DISCRECORD, 1, adfs_validate_bblk);
|
ret = adfs_probe(sb, ADFS_DISCRECORD, 1, adfs_validate_bblk);
|
||||||
if (ret == -EILSEQ)
|
if (ret == -EILSEQ)
|
||||||
@ -453,18 +414,61 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dentry *adfs_mount(struct file_system_type *fs_type,
|
static int adfs_get_tree(struct fs_context *fc)
|
||||||
int flags, const char *dev_name, void *data)
|
|
||||||
{
|
{
|
||||||
return mount_bdev(fs_type, flags, dev_name, data, adfs_fill_super);
|
return get_tree_bdev(fc, adfs_fill_super);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void adfs_free_fc(struct fs_context *fc)
|
||||||
|
{
|
||||||
|
struct adfs_context *asb = fc->s_fs_info;
|
||||||
|
|
||||||
|
kfree(asb);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct fs_context_operations adfs_context_ops = {
|
||||||
|
.parse_param = adfs_parse_param,
|
||||||
|
.get_tree = adfs_get_tree,
|
||||||
|
.reconfigure = adfs_reconfigure,
|
||||||
|
.free = adfs_free_fc,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int adfs_init_fs_context(struct fs_context *fc)
|
||||||
|
{
|
||||||
|
struct adfs_sb_info *asb;
|
||||||
|
|
||||||
|
asb = kzalloc(sizeof(struct adfs_sb_info), GFP_KERNEL);
|
||||||
|
if (!asb)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
|
||||||
|
struct super_block *sb = fc->root->d_sb;
|
||||||
|
struct adfs_sb_info *old_asb = ADFS_SB(sb);
|
||||||
|
|
||||||
|
/* structure copy existing options before parsing */
|
||||||
|
*asb = *old_asb;
|
||||||
|
} else {
|
||||||
|
/* set default options */
|
||||||
|
asb->s_uid = GLOBAL_ROOT_UID;
|
||||||
|
asb->s_gid = GLOBAL_ROOT_GID;
|
||||||
|
asb->s_owner_mask = ADFS_DEFAULT_OWNER_MASK;
|
||||||
|
asb->s_other_mask = ADFS_DEFAULT_OTHER_MASK;
|
||||||
|
asb->s_ftsuffix = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fc->ops = &adfs_context_ops;
|
||||||
|
fc->s_fs_info = asb;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct file_system_type adfs_fs_type = {
|
static struct file_system_type adfs_fs_type = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.name = "adfs",
|
.name = "adfs",
|
||||||
.mount = adfs_mount,
|
|
||||||
.kill_sb = kill_block_super,
|
.kill_sb = kill_block_super,
|
||||||
.fs_flags = FS_REQUIRES_DEV,
|
.fs_flags = FS_REQUIRES_DEV,
|
||||||
|
.init_fs_context = adfs_init_fs_context,
|
||||||
|
.parameters = adfs_param_spec,
|
||||||
};
|
};
|
||||||
MODULE_ALIAS_FS("adfs");
|
MODULE_ALIAS_FS("adfs");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user