vfs-6.13.mount.api

-----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCZzcTJQAKCRCRxhvAZXjc
 orndAP4gmY0BHtvXZoZiArqjvFIn5lELcRCPoXzYTlVlb2IQFQD9Gi3kMv5QUZBj
 bKCKNJb1MaXknT/psytR9llWlDTMeQw=
 =0/q1
 -----END PGP SIGNATURE-----

Merge tag 'vfs-6.13.mount.api' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull vfs mount api conversions from Christian Brauner:
 "Convert adfs, affs, befs, hfs, hfsplus, jfs, and hpfs to the new mount
  api"

* tag 'vfs-6.13.mount.api' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
  efs: fix the efs new mount api implementation
  ubifs: Convert ubifs to use the new mount API
  hpfs: convert hpfs to use the new mount api
  jfs: convert jfs to use the new mount api
  hfsplus: convert hfsplus to use the new mount api
  hfs: convert hfs to use the new mount api
  befs: convert befs to use the new mount api
  affs: convert affs to use the new mount api
  adfs: convert adfs to use the new mount api
This commit is contained in:
Linus Torvalds 2024-11-18 09:33:34 -08:00
commit 4eb98b7760
12 changed files with 1331 additions and 1417 deletions

View File

@ -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];
int token;
if (!*p)
continue;
token = match_token(p, tokens, args);
switch (token) {
case Opt_uid: case Opt_uid:
if (match_int(args, &option)) asb->s_uid = result.uid;
return -EINVAL;
asb->s_uid = make_kuid(current_user_ns(), option);
if (!uid_valid(asb->s_uid))
return -EINVAL;
break; break;
case Opt_gid: case Opt_gid:
if (match_int(args, &option)) asb->s_gid = result.gid;
return -EINVAL;
asb->s_gid = make_kgid(current_user_ns(), option);
if (!gid_valid(asb->s_gid))
return -EINVAL;
break; break;
case Opt_ownmask: case Opt_ownmask:
if (match_octal(args, &option)) asb->s_owner_mask = result.uint_32;
return -EINVAL;
asb->s_owner_mask = option;
break; break;
case Opt_othmask: case Opt_othmask:
if (match_octal(args, &option)) asb->s_other_mask = result.uint_32;
return -EINVAL;
asb->s_other_mask = option;
break; break;
case Opt_ftsuffix: case Opt_ftsuffix:
if (match_int(args, &option)) asb->s_ftsuffix = result.uint_32;
return -EINVAL;
asb->s_ftsuffix = option;
break; break;
default: default:
adfs_msg(sb, KERN_ERR,
"unrecognised mount option \"%s\" or missing value",
p);
return -EINVAL; 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 @@ error:
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");

View File

@ -14,7 +14,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/statfs.h> #include <linux/statfs.h>
#include <linux/parser.h> #include <linux/fs_parser.h>
#include <linux/fs_context.h>
#include <linux/magic.h> #include <linux/magic.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/cred.h> #include <linux/cred.h>
@ -27,7 +28,6 @@
static int affs_statfs(struct dentry *dentry, struct kstatfs *buf); static int affs_statfs(struct dentry *dentry, struct kstatfs *buf);
static int affs_show_options(struct seq_file *m, struct dentry *root); static int affs_show_options(struct seq_file *m, struct dentry *root);
static int affs_remount (struct super_block *sb, int *flags, char *data);
static void static void
affs_commit_super(struct super_block *sb, int wait) affs_commit_super(struct super_block *sb, int wait)
@ -155,141 +155,115 @@ static const struct super_operations affs_sops = {
.put_super = affs_put_super, .put_super = affs_put_super,
.sync_fs = affs_sync_fs, .sync_fs = affs_sync_fs,
.statfs = affs_statfs, .statfs = affs_statfs,
.remount_fs = affs_remount,
.show_options = affs_show_options, .show_options = affs_show_options,
}; };
enum { enum {
Opt_bs, Opt_mode, Opt_mufs, Opt_notruncate, Opt_prefix, Opt_protect, Opt_bs, Opt_mode, Opt_mufs, Opt_notruncate, Opt_prefix, Opt_protect,
Opt_reserved, Opt_root, Opt_setgid, Opt_setuid, Opt_reserved, Opt_root, Opt_setgid, Opt_setuid,
Opt_verbose, Opt_volume, Opt_ignore, Opt_err, Opt_verbose, Opt_volume, Opt_ignore,
}; };
static const match_table_t tokens = { struct affs_context {
{Opt_bs, "bs=%u"}, kuid_t uid; /* uid to override */
{Opt_mode, "mode=%o"}, kgid_t gid; /* gid to override */
{Opt_mufs, "mufs"}, unsigned int mode; /* mode to override */
{Opt_notruncate, "nofilenametruncate"}, unsigned int reserved; /* Number of reserved blocks */
{Opt_prefix, "prefix=%s"}, int root_block; /* FFS root block number */
{Opt_protect, "protect"}, int blocksize; /* Initial device blksize */
{Opt_reserved, "reserved=%u"}, char *prefix; /* Prefix for volumes and assigns */
{Opt_root, "root=%u"}, char volume[32]; /* Vol. prefix for absolute symlinks */
{Opt_setgid, "setgid=%u"}, unsigned long mount_flags; /* Options */
{Opt_setuid, "setuid=%u"},
{Opt_verbose, "verbose"},
{Opt_volume, "volume=%s"},
{Opt_ignore, "grpquota"},
{Opt_ignore, "noquota"},
{Opt_ignore, "quota"},
{Opt_ignore, "usrquota"},
{Opt_err, NULL},
}; };
static int static const struct fs_parameter_spec affs_param_spec[] = {
parse_options(char *options, kuid_t *uid, kgid_t *gid, int *mode, int *reserved, s32 *root, fsparam_u32 ("bs", Opt_bs),
int *blocksize, char **prefix, char *volume, unsigned long *mount_opts) fsparam_u32oct ("mode", Opt_mode),
fsparam_flag ("mufs", Opt_mufs),
fsparam_flag ("nofilenametruncate", Opt_notruncate),
fsparam_string ("prefix", Opt_prefix),
fsparam_flag ("protect", Opt_protect),
fsparam_u32 ("reserved", Opt_reserved),
fsparam_u32 ("root", Opt_root),
fsparam_gid ("setgid", Opt_setgid),
fsparam_uid ("setuid", Opt_setuid),
fsparam_flag ("verbose", Opt_verbose),
fsparam_string ("volume", Opt_volume),
fsparam_flag ("grpquota", Opt_ignore),
fsparam_flag ("noquota", Opt_ignore),
fsparam_flag ("quota", Opt_ignore),
fsparam_flag ("usrquota", Opt_ignore),
{},
};
static int affs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{ {
char *p; struct affs_context *ctx = fc->fs_private;
substring_t args[MAX_OPT_ARGS]; struct fs_parse_result result;
int n;
int opt;
/* Fill in defaults */ opt = fs_parse(fc, affs_param_spec, param, &result);
if (opt < 0)
return opt;
*uid = current_uid(); switch (opt) {
*gid = current_gid();
*reserved = 2;
*root = -1;
*blocksize = -1;
volume[0] = ':';
volume[1] = 0;
*mount_opts = 0;
if (!options)
return 1;
while ((p = strsep(&options, ",")) != NULL) {
int token, n, option;
if (!*p)
continue;
token = match_token(p, tokens, args);
switch (token) {
case Opt_bs: case Opt_bs:
if (match_int(&args[0], &n)) n = result.uint_32;
return 0;
if (n != 512 && n != 1024 && n != 2048 if (n != 512 && n != 1024 && n != 2048
&& n != 4096) { && n != 4096) {
pr_warn("Invalid blocksize (512, 1024, 2048, 4096 allowed)\n"); pr_warn("Invalid blocksize (512, 1024, 2048, 4096 allowed)\n");
return 0; return -EINVAL;
} }
*blocksize = n; ctx->blocksize = n;
break; break;
case Opt_mode: case Opt_mode:
if (match_octal(&args[0], &option)) ctx->mode = result.uint_32 & 0777;
return 0; affs_set_opt(ctx->mount_flags, SF_SETMODE);
*mode = option & 0777;
affs_set_opt(*mount_opts, SF_SETMODE);
break; break;
case Opt_mufs: case Opt_mufs:
affs_set_opt(*mount_opts, SF_MUFS); affs_set_opt(ctx->mount_flags, SF_MUFS);
break; break;
case Opt_notruncate: case Opt_notruncate:
affs_set_opt(*mount_opts, SF_NO_TRUNCATE); affs_set_opt(ctx->mount_flags, SF_NO_TRUNCATE);
break; break;
case Opt_prefix: case Opt_prefix:
kfree(*prefix); kfree(ctx->prefix);
*prefix = match_strdup(&args[0]); ctx->prefix = param->string;
if (!*prefix) param->string = NULL;
return 0; affs_set_opt(ctx->mount_flags, SF_PREFIX);
affs_set_opt(*mount_opts, SF_PREFIX);
break; break;
case Opt_protect: case Opt_protect:
affs_set_opt(*mount_opts, SF_IMMUTABLE); affs_set_opt(ctx->mount_flags, SF_IMMUTABLE);
break; break;
case Opt_reserved: case Opt_reserved:
if (match_int(&args[0], reserved)) ctx->reserved = result.uint_32;
return 0;
break; break;
case Opt_root: case Opt_root:
if (match_int(&args[0], root)) ctx->root_block = result.uint_32;
return 0;
break; break;
case Opt_setgid: case Opt_setgid:
if (match_int(&args[0], &option)) ctx->gid = result.gid;
return 0; affs_set_opt(ctx->mount_flags, SF_SETGID);
*gid = make_kgid(current_user_ns(), option);
if (!gid_valid(*gid))
return 0;
affs_set_opt(*mount_opts, SF_SETGID);
break; break;
case Opt_setuid: case Opt_setuid:
if (match_int(&args[0], &option)) ctx->uid = result.uid;
return 0; affs_set_opt(ctx->mount_flags, SF_SETUID);
*uid = make_kuid(current_user_ns(), option);
if (!uid_valid(*uid))
return 0;
affs_set_opt(*mount_opts, SF_SETUID);
break; break;
case Opt_verbose: case Opt_verbose:
affs_set_opt(*mount_opts, SF_VERBOSE); affs_set_opt(ctx->mount_flags, SF_VERBOSE);
break; break;
case Opt_volume: { case Opt_volume:
char *vol = match_strdup(&args[0]); strscpy(ctx->volume, param->string, 32);
if (!vol)
return 0;
strscpy(volume, vol, 32);
kfree(vol);
break; break;
}
case Opt_ignore: case Opt_ignore:
/* Silently ignore the quota options */ /* Silently ignore the quota options */
break; break;
default: default:
pr_warn("Unrecognized mount option \"%s\" or missing value\n", return -EINVAL;
p); }
return 0; return 0;
} }
}
return 1;
}
static int affs_show_options(struct seq_file *m, struct dentry *root) static int affs_show_options(struct seq_file *m, struct dentry *root)
{ {
@ -329,27 +303,22 @@ static int affs_show_options(struct seq_file *m, struct dentry *root)
* hopefully have the guts to do so. Until then: sorry for the mess. * hopefully have the guts to do so. Until then: sorry for the mess.
*/ */
static int affs_fill_super(struct super_block *sb, void *data, int silent) static int affs_fill_super(struct super_block *sb, struct fs_context *fc)
{ {
struct affs_sb_info *sbi; struct affs_sb_info *sbi;
struct affs_context *ctx = fc->fs_private;
struct buffer_head *root_bh = NULL; struct buffer_head *root_bh = NULL;
struct buffer_head *boot_bh; struct buffer_head *boot_bh;
struct inode *root_inode = NULL; struct inode *root_inode = NULL;
s32 root_block; int silent = fc->sb_flags & SB_SILENT;
int size, blocksize; int size, blocksize;
u32 chksum; u32 chksum;
int num_bm; int num_bm;
int i, j; int i, j;
kuid_t uid;
kgid_t gid;
int reserved;
unsigned long mount_flags;
int tmp_flags; /* fix remount prototype... */ int tmp_flags; /* fix remount prototype... */
u8 sig[4]; u8 sig[4];
int ret; int ret;
pr_debug("read_super(%s)\n", data ? (const char *)data : "no options");
sb->s_magic = AFFS_SUPER_MAGIC; sb->s_magic = AFFS_SUPER_MAGIC;
sb->s_op = &affs_sops; sb->s_op = &affs_sops;
sb->s_flags |= SB_NODIRATIME; sb->s_flags |= SB_NODIRATIME;
@ -369,19 +338,16 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
spin_lock_init(&sbi->work_lock); spin_lock_init(&sbi->work_lock);
INIT_DELAYED_WORK(&sbi->sb_work, flush_superblock); INIT_DELAYED_WORK(&sbi->sb_work, flush_superblock);
if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block, sbi->s_flags = ctx->mount_flags;
&blocksize,&sbi->s_prefix, sbi->s_mode = ctx->mode;
sbi->s_volume, &mount_flags)) { sbi->s_uid = ctx->uid;
pr_err("Error parsing options\n"); sbi->s_gid = ctx->gid;
return -EINVAL; sbi->s_reserved = ctx->reserved;
} sbi->s_prefix = ctx->prefix;
/* N.B. after this point s_prefix must be released */ ctx->prefix = NULL;
memcpy(sbi->s_volume, ctx->volume, 32);
sbi->s_flags = mount_flags; /* N.B. after this point s_prefix must be released */
sbi->s_mode = i;
sbi->s_uid = uid;
sbi->s_gid = gid;
sbi->s_reserved= reserved;
/* Get the size of the device in 512-byte blocks. /* Get the size of the device in 512-byte blocks.
* If we later see that the partition uses bigger * If we later see that the partition uses bigger
@ -396,15 +362,16 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
i = bdev_logical_block_size(sb->s_bdev); i = bdev_logical_block_size(sb->s_bdev);
j = PAGE_SIZE; j = PAGE_SIZE;
blocksize = ctx->blocksize;
if (blocksize > 0) { if (blocksize > 0) {
i = j = blocksize; i = j = blocksize;
size = size / (blocksize / 512); size = size / (blocksize / 512);
} }
for (blocksize = i; blocksize <= j; blocksize <<= 1, size >>= 1) { for (blocksize = i; blocksize <= j; blocksize <<= 1, size >>= 1) {
sbi->s_root_block = root_block; sbi->s_root_block = ctx->root_block;
if (root_block < 0) if (ctx->root_block < 0)
sbi->s_root_block = (reserved + size - 1) / 2; sbi->s_root_block = (ctx->reserved + size - 1) / 2;
pr_debug("setting blocksize to %d\n", blocksize); pr_debug("setting blocksize to %d\n", blocksize);
affs_set_blocksize(sb, blocksize); affs_set_blocksize(sb, blocksize);
sbi->s_partition_size = size; sbi->s_partition_size = size;
@ -424,7 +391,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
"size=%d, reserved=%d\n", "size=%d, reserved=%d\n",
sb->s_id, sb->s_id,
sbi->s_root_block + num_bm, sbi->s_root_block + num_bm,
blocksize, size, reserved); ctx->blocksize, size, ctx->reserved);
root_bh = affs_bread(sb, sbi->s_root_block + num_bm); root_bh = affs_bread(sb, sbi->s_root_block + num_bm);
if (!root_bh) if (!root_bh)
continue; continue;
@ -447,7 +414,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
got_root: got_root:
/* Keep super block in cache */ /* Keep super block in cache */
sbi->s_root_bh = root_bh; sbi->s_root_bh = root_bh;
root_block = sbi->s_root_block; ctx->root_block = sbi->s_root_block;
/* Find out which kind of FS we have */ /* Find out which kind of FS we have */
boot_bh = sb_bread(sb, 0); boot_bh = sb_bread(sb, 0);
@ -506,7 +473,7 @@ got_root:
return -EINVAL; return -EINVAL;
} }
if (affs_test_opt(mount_flags, SF_VERBOSE)) { if (affs_test_opt(ctx->mount_flags, SF_VERBOSE)) {
u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0]; u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0];
pr_notice("Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n", pr_notice("Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n",
len > 31 ? 31 : len, len > 31 ? 31 : len,
@ -528,7 +495,7 @@ got_root:
/* set up enough so that it can read an inode */ /* set up enough so that it can read an inode */
root_inode = affs_iget(sb, root_block); root_inode = affs_iget(sb, ctx->root_block);
if (IS_ERR(root_inode)) if (IS_ERR(root_inode))
return PTR_ERR(root_inode); return PTR_ERR(root_inode);
@ -548,56 +515,43 @@ got_root:
return 0; return 0;
} }
static int static int affs_reconfigure(struct fs_context *fc)
affs_remount(struct super_block *sb, int *flags, char *data)
{ {
struct super_block *sb = fc->root->d_sb;
struct affs_context *ctx = fc->fs_private;
struct affs_sb_info *sbi = AFFS_SB(sb); struct affs_sb_info *sbi = AFFS_SB(sb);
int blocksize;
kuid_t uid;
kgid_t gid;
int mode;
int reserved;
int root_block;
unsigned long mount_flags;
int res = 0; int res = 0;
char volume[32];
char *prefix = NULL;
pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data);
sync_filesystem(sb); sync_filesystem(sb);
*flags |= SB_NODIRATIME; fc->sb_flags |= SB_NODIRATIME;
memcpy(volume, sbi->s_volume, 32);
if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block,
&blocksize, &prefix, volume,
&mount_flags)) {
kfree(prefix);
return -EINVAL;
}
flush_delayed_work(&sbi->sb_work); flush_delayed_work(&sbi->sb_work);
sbi->s_flags = mount_flags; /*
sbi->s_mode = mode; * NB: Historically, only mount_flags, mode, uid, gic, prefix,
sbi->s_uid = uid; * and volume are accepted during remount.
sbi->s_gid = gid; */
sbi->s_flags = ctx->mount_flags;
sbi->s_mode = ctx->mode;
sbi->s_uid = ctx->uid;
sbi->s_gid = ctx->gid;
/* protect against readers */ /* protect against readers */
spin_lock(&sbi->symlink_lock); spin_lock(&sbi->symlink_lock);
if (prefix) { if (ctx->prefix) {
kfree(sbi->s_prefix); kfree(sbi->s_prefix);
sbi->s_prefix = prefix; sbi->s_prefix = ctx->prefix;
ctx->prefix = NULL;
} }
memcpy(sbi->s_volume, volume, 32); memcpy(sbi->s_volume, ctx->volume, 32);
spin_unlock(&sbi->symlink_lock); spin_unlock(&sbi->symlink_lock);
if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb)) if ((bool)(fc->sb_flags & SB_RDONLY) == sb_rdonly(sb))
return 0; return 0;
if (*flags & SB_RDONLY) if (fc->sb_flags & SB_RDONLY)
affs_free_bitmap(sb); affs_free_bitmap(sb);
else else
res = affs_init_bitmap(sb, flags); res = affs_init_bitmap(sb, &fc->sb_flags);
return res; return res;
} }
@ -624,10 +578,9 @@ affs_statfs(struct dentry *dentry, struct kstatfs *buf)
return 0; return 0;
} }
static struct dentry *affs_mount(struct file_system_type *fs_type, static int affs_get_tree(struct fs_context *fc)
int flags, const char *dev_name, void *data)
{ {
return mount_bdev(fs_type, flags, dev_name, data, affs_fill_super); return get_tree_bdev(fc, affs_fill_super);
} }
static void affs_kill_sb(struct super_block *sb) static void affs_kill_sb(struct super_block *sb)
@ -643,12 +596,61 @@ static void affs_kill_sb(struct super_block *sb)
} }
} }
static void affs_free_fc(struct fs_context *fc)
{
struct affs_context *ctx = fc->fs_private;
kfree(ctx->prefix);
kfree(ctx);
}
static const struct fs_context_operations affs_context_ops = {
.parse_param = affs_parse_param,
.get_tree = affs_get_tree,
.reconfigure = affs_reconfigure,
.free = affs_free_fc,
};
static int affs_init_fs_context(struct fs_context *fc)
{
struct affs_context *ctx;
ctx = kzalloc(sizeof(struct affs_context), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
struct super_block *sb = fc->root->d_sb;
struct affs_sb_info *sbi = AFFS_SB(sb);
/*
* NB: historically, no options other than volume were
* preserved across a remount unless they were explicitly
* passed in.
*/
memcpy(ctx->volume, sbi->s_volume, 32);
} else {
ctx->uid = current_uid();
ctx->gid = current_gid();
ctx->reserved = 2;
ctx->root_block = -1;
ctx->blocksize = -1;
ctx->volume[0] = ':';
}
fc->ops = &affs_context_ops;
fc->fs_private = ctx;
return 0;
}
static struct file_system_type affs_fs_type = { static struct file_system_type affs_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "affs", .name = "affs",
.mount = affs_mount,
.kill_sb = affs_kill_sb, .kill_sb = affs_kill_sb,
.fs_flags = FS_REQUIRES_DEV, .fs_flags = FS_REQUIRES_DEV,
.init_fs_context = affs_init_fs_context,
.parameters = affs_param_spec,
}; };
MODULE_ALIAS_FS("affs"); MODULE_ALIAS_FS("affs");

View File

@ -11,12 +11,13 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/nls.h> #include <linux/nls.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/vfs.h> #include <linux/vfs.h>
#include <linux/parser.h>
#include <linux/namei.h> #include <linux/namei.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/cred.h> #include <linux/cred.h>
@ -54,22 +55,20 @@ static int befs_utf2nls(struct super_block *sb, const char *in, int in_len,
static int befs_nls2utf(struct super_block *sb, const char *in, int in_len, static int befs_nls2utf(struct super_block *sb, const char *in, int in_len,
char **out, int *out_len); char **out, int *out_len);
static void befs_put_super(struct super_block *); static void befs_put_super(struct super_block *);
static int befs_remount(struct super_block *, int *, char *);
static int befs_statfs(struct dentry *, struct kstatfs *); static int befs_statfs(struct dentry *, struct kstatfs *);
static int befs_show_options(struct seq_file *, struct dentry *); static int befs_show_options(struct seq_file *, struct dentry *);
static int parse_options(char *, struct befs_mount_options *);
static struct dentry *befs_fh_to_dentry(struct super_block *sb, static struct dentry *befs_fh_to_dentry(struct super_block *sb,
struct fid *fid, int fh_len, int fh_type); struct fid *fid, int fh_len, int fh_type);
static struct dentry *befs_fh_to_parent(struct super_block *sb, static struct dentry *befs_fh_to_parent(struct super_block *sb,
struct fid *fid, int fh_len, int fh_type); struct fid *fid, int fh_len, int fh_type);
static struct dentry *befs_get_parent(struct dentry *child); static struct dentry *befs_get_parent(struct dentry *child);
static void befs_free_fc(struct fs_context *fc);
static const struct super_operations befs_sops = { static const struct super_operations befs_sops = {
.alloc_inode = befs_alloc_inode, /* allocate a new inode */ .alloc_inode = befs_alloc_inode, /* allocate a new inode */
.free_inode = befs_free_inode, /* deallocate an inode */ .free_inode = befs_free_inode, /* deallocate an inode */
.put_super = befs_put_super, /* uninit super */ .put_super = befs_put_super, /* uninit super */
.statfs = befs_statfs, /* statfs */ .statfs = befs_statfs, /* statfs */
.remount_fs = befs_remount,
.show_options = befs_show_options, .show_options = befs_show_options,
}; };
@ -672,93 +671,54 @@ static struct dentry *befs_get_parent(struct dentry *child)
} }
enum { enum {
Opt_uid, Opt_gid, Opt_charset, Opt_debug, Opt_err, Opt_uid, Opt_gid, Opt_charset, Opt_debug,
}; };
static const match_table_t befs_tokens = { static const struct fs_parameter_spec befs_param_spec[] = {
{Opt_uid, "uid=%d"}, fsparam_uid ("uid", Opt_uid),
{Opt_gid, "gid=%d"}, fsparam_gid ("gid", Opt_gid),
{Opt_charset, "iocharset=%s"}, fsparam_string ("iocharset", Opt_charset),
{Opt_debug, "debug"}, fsparam_flag ("debug", Opt_debug),
{Opt_err, NULL} {}
}; };
static int static int
parse_options(char *options, struct befs_mount_options *opts) befs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{ {
char *p; struct befs_mount_options *opts = fc->fs_private;
substring_t args[MAX_OPT_ARGS];
int option;
kuid_t uid;
kgid_t gid;
/* Initialize options */
opts->uid = GLOBAL_ROOT_UID;
opts->gid = GLOBAL_ROOT_GID;
opts->use_uid = 0;
opts->use_gid = 0;
opts->iocharset = NULL;
opts->debug = 0;
if (!options)
return 1;
while ((p = strsep(&options, ",")) != NULL) {
int token; int token;
struct fs_parse_result result;
if (!*p) /* befs ignores all options on remount */
continue; if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE)
return 0;
token = fs_parse(fc, befs_param_spec, param, &result);
if (token < 0)
return token;
token = match_token(p, befs_tokens, args);
switch (token) { switch (token) {
case Opt_uid: case Opt_uid:
if (match_int(&args[0], &option)) opts->uid = result.uid;
return 0;
uid = INVALID_UID;
if (option >= 0)
uid = make_kuid(current_user_ns(), option);
if (!uid_valid(uid)) {
pr_err("Invalid uid %d, "
"using default\n", option);
break;
}
opts->uid = uid;
opts->use_uid = 1; opts->use_uid = 1;
break; break;
case Opt_gid: case Opt_gid:
if (match_int(&args[0], &option)) opts->gid = result.gid;
return 0;
gid = INVALID_GID;
if (option >= 0)
gid = make_kgid(current_user_ns(), option);
if (!gid_valid(gid)) {
pr_err("Invalid gid %d, "
"using default\n", option);
break;
}
opts->gid = gid;
opts->use_gid = 1; opts->use_gid = 1;
break; break;
case Opt_charset: case Opt_charset:
kfree(opts->iocharset); kfree(opts->iocharset);
opts->iocharset = match_strdup(&args[0]); opts->iocharset = param->string;
if (!opts->iocharset) { param->string = NULL;
pr_err("allocation failure for "
"iocharset string\n");
return 0;
}
break; break;
case Opt_debug: case Opt_debug:
opts->debug = 1; opts->debug = 1;
break; break;
default: default:
pr_err("Unrecognized mount option \"%s\" " return -EINVAL;
"or missing value\n", p); }
return 0; return 0;
} }
}
return 1;
}
static int befs_show_options(struct seq_file *m, struct dentry *root) static int befs_show_options(struct seq_file *m, struct dentry *root)
{ {
@ -793,6 +753,21 @@ befs_put_super(struct super_block *sb)
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
} }
/*
* Copy the parsed options into the sbi mount_options member
*/
static void
befs_set_options(struct befs_sb_info *sbi, struct befs_mount_options *opts)
{
sbi->mount_opts.uid = opts->uid;
sbi->mount_opts.gid = opts->gid;
sbi->mount_opts.use_uid = opts->use_uid;
sbi->mount_opts.use_gid = opts->use_gid;
sbi->mount_opts.debug = opts->debug;
sbi->mount_opts.iocharset = opts->iocharset;
opts->iocharset = NULL;
}
/* Allocate private field of the superblock, fill it. /* Allocate private field of the superblock, fill it.
* *
* Finish filling the public superblock fields * Finish filling the public superblock fields
@ -800,7 +775,7 @@ befs_put_super(struct super_block *sb)
* Load a set of NLS translations if needed. * Load a set of NLS translations if needed.
*/ */
static int static int
befs_fill_super(struct super_block *sb, void *data, int silent) befs_fill_super(struct super_block *sb, struct fs_context *fc)
{ {
struct buffer_head *bh; struct buffer_head *bh;
struct befs_sb_info *befs_sb; struct befs_sb_info *befs_sb;
@ -810,6 +785,8 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
const unsigned long sb_block = 0; const unsigned long sb_block = 0;
const off_t x86_sb_off = 512; const off_t x86_sb_off = 512;
int blocksize; int blocksize;
struct befs_mount_options *parsed_opts = fc->fs_private;
int silent = fc->sb_flags & SB_SILENT;
sb->s_fs_info = kzalloc(sizeof(*befs_sb), GFP_KERNEL); sb->s_fs_info = kzalloc(sizeof(*befs_sb), GFP_KERNEL);
if (sb->s_fs_info == NULL) if (sb->s_fs_info == NULL)
@ -817,11 +794,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
befs_sb = BEFS_SB(sb); befs_sb = BEFS_SB(sb);
if (!parse_options((char *) data, &befs_sb->mount_opts)) { befs_set_options(befs_sb, parsed_opts);
if (!silent)
befs_error(sb, "cannot parse mount options");
goto unacquire_priv_sbp;
}
befs_debug(sb, "---> %s", __func__); befs_debug(sb, "---> %s", __func__);
@ -934,10 +907,10 @@ unacquire_none:
} }
static int static int
befs_remount(struct super_block *sb, int *flags, char *data) befs_reconfigure(struct fs_context *fc)
{ {
sync_filesystem(sb); sync_filesystem(fc->root->d_sb);
if (!(*flags & SB_RDONLY)) if (!(fc->sb_flags & SB_RDONLY))
return -EINVAL; return -EINVAL;
return 0; return 0;
} }
@ -965,19 +938,51 @@ befs_statfs(struct dentry *dentry, struct kstatfs *buf)
return 0; return 0;
} }
static struct dentry * static int befs_get_tree(struct fs_context *fc)
befs_mount(struct file_system_type *fs_type, int flags, const char *dev_name,
void *data)
{ {
return mount_bdev(fs_type, flags, dev_name, data, befs_fill_super); return get_tree_bdev(fc, befs_fill_super);
}
static const struct fs_context_operations befs_context_ops = {
.parse_param = befs_parse_param,
.get_tree = befs_get_tree,
.reconfigure = befs_reconfigure,
.free = befs_free_fc,
};
static int befs_init_fs_context(struct fs_context *fc)
{
struct befs_mount_options *opts;
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
if (!opts)
return -ENOMEM;
/* Initialize options */
opts->uid = GLOBAL_ROOT_UID;
opts->gid = GLOBAL_ROOT_GID;
fc->fs_private = opts;
fc->ops = &befs_context_ops;
return 0;
}
static void befs_free_fc(struct fs_context *fc)
{
struct befs_mount_options *opts = fc->fs_private;
kfree(opts->iocharset);
kfree(fc->fs_private);
} }
static struct file_system_type befs_fs_type = { static struct file_system_type befs_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "befs", .name = "befs",
.mount = befs_mount,
.kill_sb = kill_block_super, .kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV, .fs_flags = FS_REQUIRES_DEV,
.init_fs_context = befs_init_fs_context,
.parameters = befs_param_spec,
}; };
MODULE_ALIAS_FS("befs"); MODULE_ALIAS_FS("befs");

View File

@ -15,7 +15,6 @@
#include <linux/vfs.h> #include <linux/vfs.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/fs_context.h> #include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include "efs.h" #include "efs.h"
#include <linux/efs_vh.h> #include <linux/efs_vh.h>
#include <linux/efs_fs_sb.h> #include <linux/efs_fs_sb.h>
@ -49,15 +48,6 @@ static struct pt_types sgi_pt_types[] = {
{0, NULL} {0, NULL}
}; };
enum {
Opt_explicit_open,
};
static const struct fs_parameter_spec efs_param_spec[] = {
fsparam_flag ("explicit-open", Opt_explicit_open),
{}
};
/* /*
* File system definition and registration. * File system definition and registration.
*/ */
@ -67,7 +57,6 @@ static struct file_system_type efs_fs_type = {
.kill_sb = efs_kill_sb, .kill_sb = efs_kill_sb,
.fs_flags = FS_REQUIRES_DEV, .fs_flags = FS_REQUIRES_DEV,
.init_fs_context = efs_init_fs_context, .init_fs_context = efs_init_fs_context,
.parameters = efs_param_spec,
}; };
MODULE_ALIAS_FS("efs"); MODULE_ALIAS_FS("efs");
@ -265,7 +254,8 @@ static int efs_fill_super(struct super_block *s, struct fs_context *fc)
if (!sb_set_blocksize(s, EFS_BLOCKSIZE)) { if (!sb_set_blocksize(s, EFS_BLOCKSIZE)) {
pr_err("device does not support %d byte blocks\n", pr_err("device does not support %d byte blocks\n",
EFS_BLOCKSIZE); EFS_BLOCKSIZE);
return -EINVAL; return invalf(fc, "device does not support %d byte blocks\n",
EFS_BLOCKSIZE);
} }
/* read the vh (volume header) block */ /* read the vh (volume header) block */
@ -327,43 +317,22 @@ static int efs_fill_super(struct super_block *s, struct fs_context *fc)
return 0; return 0;
} }
static void efs_free_fc(struct fs_context *fc)
{
kfree(fc->fs_private);
}
static int efs_get_tree(struct fs_context *fc) static int efs_get_tree(struct fs_context *fc)
{ {
return get_tree_bdev(fc, efs_fill_super); return get_tree_bdev(fc, efs_fill_super);
} }
static int efs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{
int token;
struct fs_parse_result result;
token = fs_parse(fc, efs_param_spec, param, &result);
if (token < 0)
return token;
return 0;
}
static int efs_reconfigure(struct fs_context *fc) static int efs_reconfigure(struct fs_context *fc)
{ {
sync_filesystem(fc->root->d_sb); sync_filesystem(fc->root->d_sb);
fc->sb_flags |= SB_RDONLY;
return 0; return 0;
} }
struct efs_context {
unsigned long s_mount_opts;
};
static const struct fs_context_operations efs_context_opts = { static const struct fs_context_operations efs_context_opts = {
.parse_param = efs_parse_param,
.get_tree = efs_get_tree, .get_tree = efs_get_tree,
.reconfigure = efs_reconfigure, .reconfigure = efs_reconfigure,
.free = efs_free_fc,
}; };
/* /*
@ -371,12 +340,6 @@ static const struct fs_context_operations efs_context_opts = {
*/ */
static int efs_init_fs_context(struct fs_context *fc) static int efs_init_fs_context(struct fs_context *fc)
{ {
struct efs_context *ctx;
ctx = kzalloc(sizeof(struct efs_context), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
fc->fs_private = ctx;
fc->ops = &efs_context_opts; fc->ops = &efs_context_opts;
return 0; return 0;

View File

@ -15,10 +15,11 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/backing-dev.h> #include <linux/backing-dev.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/nls.h> #include <linux/nls.h>
#include <linux/parser.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/vfs.h> #include <linux/vfs.h>
@ -111,21 +112,24 @@ static int hfs_statfs(struct dentry *dentry, struct kstatfs *buf)
return 0; return 0;
} }
static int hfs_remount(struct super_block *sb, int *flags, char *data) static int hfs_reconfigure(struct fs_context *fc)
{ {
struct super_block *sb = fc->root->d_sb;
sync_filesystem(sb); sync_filesystem(sb);
*flags |= SB_NODIRATIME; fc->sb_flags |= SB_NODIRATIME;
if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb)) if ((bool)(fc->sb_flags & SB_RDONLY) == sb_rdonly(sb))
return 0; return 0;
if (!(*flags & SB_RDONLY)) {
if (!(fc->sb_flags & SB_RDONLY)) {
if (!(HFS_SB(sb)->mdb->drAtrb & cpu_to_be16(HFS_SB_ATTRIB_UNMNT))) { if (!(HFS_SB(sb)->mdb->drAtrb & cpu_to_be16(HFS_SB_ATTRIB_UNMNT))) {
pr_warn("filesystem was not cleanly unmounted, running fsck.hfs is recommended. leaving read-only.\n"); pr_warn("filesystem was not cleanly unmounted, running fsck.hfs is recommended. leaving read-only.\n");
sb->s_flags |= SB_RDONLY; sb->s_flags |= SB_RDONLY;
*flags |= SB_RDONLY; fc->sb_flags |= SB_RDONLY;
} else if (HFS_SB(sb)->mdb->drAtrb & cpu_to_be16(HFS_SB_ATTRIB_SLOCK)) { } else if (HFS_SB(sb)->mdb->drAtrb & cpu_to_be16(HFS_SB_ATTRIB_SLOCK)) {
pr_warn("filesystem is marked locked, leaving read-only.\n"); pr_warn("filesystem is marked locked, leaving read-only.\n");
sb->s_flags |= SB_RDONLY; sb->s_flags |= SB_RDONLY;
*flags |= SB_RDONLY; fc->sb_flags |= SB_RDONLY;
} }
} }
return 0; return 0;
@ -180,7 +184,6 @@ static const struct super_operations hfs_super_operations = {
.put_super = hfs_put_super, .put_super = hfs_put_super,
.sync_fs = hfs_sync_fs, .sync_fs = hfs_sync_fs,
.statfs = hfs_statfs, .statfs = hfs_statfs,
.remount_fs = hfs_remount,
.show_options = hfs_show_options, .show_options = hfs_show_options,
}; };
@ -188,131 +191,79 @@ enum {
opt_uid, opt_gid, opt_umask, opt_file_umask, opt_dir_umask, opt_uid, opt_gid, opt_umask, opt_file_umask, opt_dir_umask,
opt_part, opt_session, opt_type, opt_creator, opt_quiet, opt_part, opt_session, opt_type, opt_creator, opt_quiet,
opt_codepage, opt_iocharset, opt_codepage, opt_iocharset,
opt_err
}; };
static const match_table_t tokens = { static const struct fs_parameter_spec hfs_param_spec[] = {
{ opt_uid, "uid=%u" }, fsparam_u32 ("uid", opt_uid),
{ opt_gid, "gid=%u" }, fsparam_u32 ("gid", opt_gid),
{ opt_umask, "umask=%o" }, fsparam_u32oct ("umask", opt_umask),
{ opt_file_umask, "file_umask=%o" }, fsparam_u32oct ("file_umask", opt_file_umask),
{ opt_dir_umask, "dir_umask=%o" }, fsparam_u32oct ("dir_umask", opt_dir_umask),
{ opt_part, "part=%u" }, fsparam_u32 ("part", opt_part),
{ opt_session, "session=%u" }, fsparam_u32 ("session", opt_session),
{ opt_type, "type=%s" }, fsparam_string ("type", opt_type),
{ opt_creator, "creator=%s" }, fsparam_string ("creator", opt_creator),
{ opt_quiet, "quiet" }, fsparam_flag ("quiet", opt_quiet),
{ opt_codepage, "codepage=%s" }, fsparam_string ("codepage", opt_codepage),
{ opt_iocharset, "iocharset=%s" }, fsparam_string ("iocharset", opt_iocharset),
{ opt_err, NULL } {}
}; };
static inline int match_fourchar(substring_t *arg, u32 *result)
{
if (arg->to - arg->from != 4)
return -EINVAL;
memcpy(result, arg->from, 4);
return 0;
}
/* /*
* parse_options() * hfs_parse_param()
* *
* adapted from linux/fs/msdos/inode.c written 1992,93 by Werner Almesberger * This function is called by the vfs to parse the mount options.
* This function is called by hfs_read_super() to parse the mount options.
*/ */
static int parse_options(char *options, struct hfs_sb_info *hsb) static int hfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{ {
char *p; struct hfs_sb_info *hsb = fc->s_fs_info;
substring_t args[MAX_OPT_ARGS]; struct fs_parse_result result;
int tmp, token; int opt;
/* initialize the sb with defaults */ /* hfs does not honor any fs-specific options on remount */
hsb->s_uid = current_uid(); if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE)
hsb->s_gid = current_gid(); return 0;
hsb->s_file_umask = 0133;
hsb->s_dir_umask = 0022;
hsb->s_type = hsb->s_creator = cpu_to_be32(0x3f3f3f3f); /* == '????' */
hsb->s_quiet = 0;
hsb->part = -1;
hsb->session = -1;
if (!options) opt = fs_parse(fc, hfs_param_spec, param, &result);
return 1; if (opt < 0)
return opt;
while ((p = strsep(&options, ",")) != NULL) { switch (opt) {
if (!*p)
continue;
token = match_token(p, tokens, args);
switch (token) {
case opt_uid: case opt_uid:
if (match_int(&args[0], &tmp)) { hsb->s_uid = result.uid;
pr_err("uid requires an argument\n");
return 0;
}
hsb->s_uid = make_kuid(current_user_ns(), (uid_t)tmp);
if (!uid_valid(hsb->s_uid)) {
pr_err("invalid uid %d\n", tmp);
return 0;
}
break; break;
case opt_gid: case opt_gid:
if (match_int(&args[0], &tmp)) { hsb->s_gid = result.gid;
pr_err("gid requires an argument\n");
return 0;
}
hsb->s_gid = make_kgid(current_user_ns(), (gid_t)tmp);
if (!gid_valid(hsb->s_gid)) {
pr_err("invalid gid %d\n", tmp);
return 0;
}
break; break;
case opt_umask: case opt_umask:
if (match_octal(&args[0], &tmp)) { hsb->s_file_umask = (umode_t)result.uint_32;
pr_err("umask requires a value\n"); hsb->s_dir_umask = (umode_t)result.uint_32;
return 0;
}
hsb->s_file_umask = (umode_t)tmp;
hsb->s_dir_umask = (umode_t)tmp;
break; break;
case opt_file_umask: case opt_file_umask:
if (match_octal(&args[0], &tmp)) { hsb->s_file_umask = (umode_t)result.uint_32;
pr_err("file_umask requires a value\n");
return 0;
}
hsb->s_file_umask = (umode_t)tmp;
break; break;
case opt_dir_umask: case opt_dir_umask:
if (match_octal(&args[0], &tmp)) { hsb->s_dir_umask = (umode_t)result.uint_32;
pr_err("dir_umask requires a value\n");
return 0;
}
hsb->s_dir_umask = (umode_t)tmp;
break; break;
case opt_part: case opt_part:
if (match_int(&args[0], &hsb->part)) { hsb->part = result.uint_32;
pr_err("part requires an argument\n");
return 0;
}
break; break;
case opt_session: case opt_session:
if (match_int(&args[0], &hsb->session)) { hsb->session = result.uint_32;
pr_err("session requires an argument\n");
return 0;
}
break; break;
case opt_type: case opt_type:
if (match_fourchar(&args[0], &hsb->s_type)) { if (strlen(param->string) != 4) {
pr_err("type requires a 4 character value\n"); pr_err("type requires a 4 character value\n");
return 0; return -EINVAL;
} }
memcpy(&hsb->s_type, param->string, 4);
break; break;
case opt_creator: case opt_creator:
if (match_fourchar(&args[0], &hsb->s_creator)) { if (strlen(param->string) != 4) {
pr_err("creator requires a 4 character value\n"); pr_err("creator requires a 4 character value\n");
return 0; return -EINVAL;
} }
memcpy(&hsb->s_creator, param->string, 4);
break; break;
case opt_quiet: case opt_quiet:
hsb->s_quiet = 1; hsb->s_quiet = 1;
@ -320,50 +271,33 @@ static int parse_options(char *options, struct hfs_sb_info *hsb)
case opt_codepage: case opt_codepage:
if (hsb->nls_disk) { if (hsb->nls_disk) {
pr_err("unable to change codepage\n"); pr_err("unable to change codepage\n");
return 0; return -EINVAL;
} }
p = match_strdup(&args[0]); hsb->nls_disk = load_nls(param->string);
if (p)
hsb->nls_disk = load_nls(p);
if (!hsb->nls_disk) { if (!hsb->nls_disk) {
pr_err("unable to load codepage \"%s\"\n", p); pr_err("unable to load codepage \"%s\"\n",
kfree(p); param->string);
return 0; return -EINVAL;
} }
kfree(p);
break; break;
case opt_iocharset: case opt_iocharset:
if (hsb->nls_io) { if (hsb->nls_io) {
pr_err("unable to change iocharset\n"); pr_err("unable to change iocharset\n");
return 0; return -EINVAL;
} }
p = match_strdup(&args[0]); hsb->nls_io = load_nls(param->string);
if (p)
hsb->nls_io = load_nls(p);
if (!hsb->nls_io) { if (!hsb->nls_io) {
pr_err("unable to load iocharset \"%s\"\n", p); pr_err("unable to load iocharset \"%s\"\n",
kfree(p); param->string);
return 0; return -EINVAL;
} }
kfree(p);
break; break;
default: default:
return 0; return -EINVAL;
}
} }
if (hsb->nls_disk && !hsb->nls_io) {
hsb->nls_io = load_nls_default();
if (!hsb->nls_io) {
pr_err("unable to load default iocharset\n");
return 0; return 0;
} }
}
hsb->s_dir_umask &= 0777;
hsb->s_file_umask &= 0577;
return 1;
}
/* /*
* hfs_read_super() * hfs_read_super()
@ -376,29 +310,25 @@ static int parse_options(char *options, struct hfs_sb_info *hsb)
* hfs_btree_init() to get the necessary data about the extents and * hfs_btree_init() to get the necessary data about the extents and
* catalog B-trees and, finally, reading the root inode into memory. * catalog B-trees and, finally, reading the root inode into memory.
*/ */
static int hfs_fill_super(struct super_block *sb, void *data, int silent) static int hfs_fill_super(struct super_block *sb, struct fs_context *fc)
{ {
struct hfs_sb_info *sbi; struct hfs_sb_info *sbi = HFS_SB(sb);
struct hfs_find_data fd; struct hfs_find_data fd;
hfs_cat_rec rec; hfs_cat_rec rec;
struct inode *root_inode; struct inode *root_inode;
int silent = fc->sb_flags & SB_SILENT;
int res; int res;
sbi = kzalloc(sizeof(struct hfs_sb_info), GFP_KERNEL); /* load_nls_default does not fail */
if (!sbi) if (sbi->nls_disk && !sbi->nls_io)
return -ENOMEM; sbi->nls_io = load_nls_default();
sbi->s_dir_umask &= 0777;
sbi->s_file_umask &= 0577;
sbi->sb = sb;
sb->s_fs_info = sbi;
spin_lock_init(&sbi->work_lock); spin_lock_init(&sbi->work_lock);
INIT_DELAYED_WORK(&sbi->mdb_work, flush_mdb); INIT_DELAYED_WORK(&sbi->mdb_work, flush_mdb);
res = -EINVAL; sbi->sb = sb;
if (!parse_options((char *)data, sbi)) {
pr_err("unable to parse mount options\n");
goto bail;
}
sb->s_op = &hfs_super_operations; sb->s_op = &hfs_super_operations;
sb->s_xattr = hfs_xattr_handlers; sb->s_xattr = hfs_xattr_handlers;
sb->s_flags |= SB_NODIRATIME; sb->s_flags |= SB_NODIRATIME;
@ -451,18 +381,56 @@ bail:
return res; return res;
} }
static struct dentry *hfs_mount(struct file_system_type *fs_type, static int hfs_get_tree(struct fs_context *fc)
int flags, const char *dev_name, void *data)
{ {
return mount_bdev(fs_type, flags, dev_name, data, hfs_fill_super); return get_tree_bdev(fc, hfs_fill_super);
}
static void hfs_free_fc(struct fs_context *fc)
{
kfree(fc->s_fs_info);
}
static const struct fs_context_operations hfs_context_ops = {
.parse_param = hfs_parse_param,
.get_tree = hfs_get_tree,
.reconfigure = hfs_reconfigure,
.free = hfs_free_fc,
};
static int hfs_init_fs_context(struct fs_context *fc)
{
struct hfs_sb_info *hsb;
hsb = kzalloc(sizeof(struct hfs_sb_info), GFP_KERNEL);
if (!hsb)
return -ENOMEM;
fc->s_fs_info = hsb;
fc->ops = &hfs_context_ops;
if (fc->purpose != FS_CONTEXT_FOR_RECONFIGURE) {
/* initialize options with defaults */
hsb->s_uid = current_uid();
hsb->s_gid = current_gid();
hsb->s_file_umask = 0133;
hsb->s_dir_umask = 0022;
hsb->s_type = cpu_to_be32(0x3f3f3f3f); /* == '????' */
hsb->s_creator = cpu_to_be32(0x3f3f3f3f); /* == '????' */
hsb->s_quiet = 0;
hsb->part = -1;
hsb->session = -1;
}
return 0;
} }
static struct file_system_type hfs_fs_type = { static struct file_system_type hfs_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "hfs", .name = "hfs",
.mount = hfs_mount,
.kill_sb = kill_block_super, .kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV, .fs_flags = FS_REQUIRES_DEV,
.init_fs_context = hfs_init_fs_context,
}; };
MODULE_ALIAS_FS("hfs"); MODULE_ALIAS_FS("hfs");

View File

@ -21,6 +21,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/fs_context.h>
#include "hfsplus_raw.h" #include "hfsplus_raw.h"
#define DBG_BNODE_REFS 0x00000001 #define DBG_BNODE_REFS 0x00000001
@ -496,8 +497,7 @@ long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
/* options.c */ /* options.c */
void hfsplus_fill_defaults(struct hfsplus_sb_info *opts); void hfsplus_fill_defaults(struct hfsplus_sb_info *opts);
int hfsplus_parse_options_remount(char *input, int *force); int hfsplus_parse_param(struct fs_context *fc, struct fs_parameter *param);
int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi);
int hfsplus_show_options(struct seq_file *seq, struct dentry *root); int hfsplus_show_options(struct seq_file *seq, struct dentry *root);
/* part_tbl.c */ /* part_tbl.c */

View File

@ -12,7 +12,8 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/parser.h> #include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/nls.h> #include <linux/nls.h>
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
@ -23,26 +24,23 @@ enum {
opt_creator, opt_type, opt_creator, opt_type,
opt_umask, opt_uid, opt_gid, opt_umask, opt_uid, opt_gid,
opt_part, opt_session, opt_nls, opt_part, opt_session, opt_nls,
opt_nodecompose, opt_decompose, opt_decompose, opt_barrier,
opt_barrier, opt_nobarrier, opt_force,
opt_force, opt_err
}; };
static const match_table_t tokens = { static const struct fs_parameter_spec hfs_param_spec[] = {
{ opt_creator, "creator=%s" }, fsparam_string ("creator", opt_creator),
{ opt_type, "type=%s" }, fsparam_string ("type", opt_type),
{ opt_umask, "umask=%o" }, fsparam_u32oct ("umask", opt_umask),
{ opt_uid, "uid=%u" }, fsparam_u32 ("uid", opt_uid),
{ opt_gid, "gid=%u" }, fsparam_u32 ("gid", opt_gid),
{ opt_part, "part=%u" }, fsparam_u32 ("part", opt_part),
{ opt_session, "session=%u" }, fsparam_u32 ("session", opt_session),
{ opt_nls, "nls=%s" }, fsparam_string ("nls", opt_nls),
{ opt_decompose, "decompose" }, fsparam_flag_no ("decompose", opt_decompose),
{ opt_nodecompose, "nodecompose" }, fsparam_flag_no ("barrier", opt_barrier),
{ opt_barrier, "barrier" }, fsparam_flag ("force", opt_force),
{ opt_nobarrier, "nobarrier" }, {}
{ opt_force, "force" },
{ opt_err, NULL }
}; };
/* Initialize an options object to reasonable defaults */ /* Initialize an options object to reasonable defaults */
@ -60,164 +58,91 @@ void hfsplus_fill_defaults(struct hfsplus_sb_info *opts)
opts->session = -1; opts->session = -1;
} }
/* convert a "four byte character" to a 32 bit int with error checks */ /* Parse options from mount. Returns nonzero errno on failure */
static inline int match_fourchar(substring_t *arg, u32 *result) int hfsplus_parse_param(struct fs_context *fc, struct fs_parameter *param)
{ {
if (arg->to - arg->from != 4) struct hfsplus_sb_info *sbi = fc->s_fs_info;
return -EINVAL; struct fs_parse_result result;
memcpy(result, arg->from, 4); int opt;
/*
* Only the force option is examined during remount, all others
* are ignored.
*/
if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE &&
strncmp(param->key, "force", 5))
return 0; return 0;
}
int hfsplus_parse_options_remount(char *input, int *force) opt = fs_parse(fc, hfs_param_spec, param, &result);
{ if (opt < 0)
char *p; return opt;
substring_t args[MAX_OPT_ARGS];
int token;
if (!input) switch (opt) {
return 1;
while ((p = strsep(&input, ",")) != NULL) {
if (!*p)
continue;
token = match_token(p, tokens, args);
switch (token) {
case opt_force:
*force = 1;
break;
default:
break;
}
}
return 1;
}
/* Parse options from mount. Returns 0 on failure */
/* input is the options passed to mount() as a string */
int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi)
{
char *p;
substring_t args[MAX_OPT_ARGS];
int tmp, token;
if (!input)
goto done;
while ((p = strsep(&input, ",")) != NULL) {
if (!*p)
continue;
token = match_token(p, tokens, args);
switch (token) {
case opt_creator: case opt_creator:
if (match_fourchar(&args[0], &sbi->creator)) { if (strlen(param->string) != 4) {
pr_err("creator requires a 4 character value\n"); pr_err("creator requires a 4 character value\n");
return 0; return -EINVAL;
} }
memcpy(&sbi->creator, param->string, 4);
break; break;
case opt_type: case opt_type:
if (match_fourchar(&args[0], &sbi->type)) { if (strlen(param->string) != 4) {
pr_err("type requires a 4 character value\n"); pr_err("type requires a 4 character value\n");
return 0; return -EINVAL;
} }
memcpy(&sbi->type, param->string, 4);
break; break;
case opt_umask: case opt_umask:
if (match_octal(&args[0], &tmp)) { sbi->umask = (umode_t)result.uint_32;
pr_err("umask requires a value\n");
return 0;
}
sbi->umask = (umode_t)tmp;
break; break;
case opt_uid: case opt_uid:
if (match_int(&args[0], &tmp)) { sbi->uid = result.uid;
pr_err("uid requires an argument\n");
return 0;
}
sbi->uid = make_kuid(current_user_ns(), (uid_t)tmp);
if (!uid_valid(sbi->uid)) {
pr_err("invalid uid specified\n");
return 0;
} else {
set_bit(HFSPLUS_SB_UID, &sbi->flags); set_bit(HFSPLUS_SB_UID, &sbi->flags);
}
break; break;
case opt_gid: case opt_gid:
if (match_int(&args[0], &tmp)) { sbi->gid = result.gid;
pr_err("gid requires an argument\n");
return 0;
}
sbi->gid = make_kgid(current_user_ns(), (gid_t)tmp);
if (!gid_valid(sbi->gid)) {
pr_err("invalid gid specified\n");
return 0;
} else {
set_bit(HFSPLUS_SB_GID, &sbi->flags); set_bit(HFSPLUS_SB_GID, &sbi->flags);
}
break; break;
case opt_part: case opt_part:
if (match_int(&args[0], &sbi->part)) { sbi->part = result.uint_32;
pr_err("part requires an argument\n");
return 0;
}
break; break;
case opt_session: case opt_session:
if (match_int(&args[0], &sbi->session)) { sbi->session = result.uint_32;
pr_err("session requires an argument\n");
return 0;
}
break; break;
case opt_nls: case opt_nls:
if (sbi->nls) { if (sbi->nls) {
pr_err("unable to change nls mapping\n"); pr_err("unable to change nls mapping\n");
return 0; return -EINVAL;
} }
p = match_strdup(&args[0]); sbi->nls = load_nls(param->string);
if (p)
sbi->nls = load_nls(p);
if (!sbi->nls) { if (!sbi->nls) {
pr_err("unable to load nls mapping \"%s\"\n", pr_err("unable to load nls mapping \"%s\"\n",
p); param->string);
kfree(p); return -EINVAL;
return 0;
} }
kfree(p);
break; break;
case opt_decompose: case opt_decompose:
if (result.negated)
set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
else
clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags); clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
break; break;
case opt_nodecompose:
set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
break;
case opt_barrier: case opt_barrier:
clear_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags); if (result.negated)
break;
case opt_nobarrier:
set_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags); set_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
else
clear_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
break; break;
case opt_force: case opt_force:
set_bit(HFSPLUS_SB_FORCE, &sbi->flags); set_bit(HFSPLUS_SB_FORCE, &sbi->flags);
break; break;
default: default:
return 0; return -EINVAL;
}
} }
done:
if (!sbi->nls) {
/* try utf8 first, as this is the old default behaviour */
sbi->nls = load_nls("utf8");
if (!sbi->nls)
sbi->nls = load_nls_default();
if (!sbi->nls)
return 0; return 0;
} }
return 1;
}
int hfsplus_show_options(struct seq_file *seq, struct dentry *root) int hfsplus_show_options(struct seq_file *seq, struct dentry *root)
{ {
struct hfsplus_sb_info *sbi = HFSPLUS_SB(root->d_sb); struct hfsplus_sb_info *sbi = HFSPLUS_SB(root->d_sb);

View File

@ -14,6 +14,7 @@
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/backing-dev.h> #include <linux/backing-dev.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/fs_context.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/vfs.h> #include <linux/vfs.h>
#include <linux/nls.h> #include <linux/nls.h>
@ -332,34 +333,33 @@ static int hfsplus_statfs(struct dentry *dentry, struct kstatfs *buf)
return 0; return 0;
} }
static int hfsplus_remount(struct super_block *sb, int *flags, char *data) static int hfsplus_reconfigure(struct fs_context *fc)
{ {
sync_filesystem(sb); struct super_block *sb = fc->root->d_sb;
if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
return 0;
if (!(*flags & SB_RDONLY)) {
struct hfsplus_vh *vhdr = HFSPLUS_SB(sb)->s_vhdr;
int force = 0;
if (!hfsplus_parse_options_remount(data, &force)) sync_filesystem(sb);
return -EINVAL; if ((bool)(fc->sb_flags & SB_RDONLY) == sb_rdonly(sb))
return 0;
if (!(fc->sb_flags & SB_RDONLY)) {
struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
struct hfsplus_vh *vhdr = sbi->s_vhdr;
if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) { if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
pr_warn("filesystem was not cleanly unmounted, running fsck.hfsplus is recommended. leaving read-only.\n"); pr_warn("filesystem was not cleanly unmounted, running fsck.hfsplus is recommended. leaving read-only.\n");
sb->s_flags |= SB_RDONLY; sb->s_flags |= SB_RDONLY;
*flags |= SB_RDONLY; fc->sb_flags |= SB_RDONLY;
} else if (force) { } else if (test_bit(HFSPLUS_SB_FORCE, &sbi->flags)) {
/* nothing */ /* nothing */
} else if (vhdr->attributes & } else if (vhdr->attributes &
cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) { cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
pr_warn("filesystem is marked locked, leaving read-only.\n"); pr_warn("filesystem is marked locked, leaving read-only.\n");
sb->s_flags |= SB_RDONLY; sb->s_flags |= SB_RDONLY;
*flags |= SB_RDONLY; fc->sb_flags |= SB_RDONLY;
} else if (vhdr->attributes & } else if (vhdr->attributes &
cpu_to_be32(HFSPLUS_VOL_JOURNALED)) { cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
pr_warn("filesystem is marked journaled, leaving read-only.\n"); pr_warn("filesystem is marked journaled, leaving read-only.\n");
sb->s_flags |= SB_RDONLY; sb->s_flags |= SB_RDONLY;
*flags |= SB_RDONLY; fc->sb_flags |= SB_RDONLY;
} }
} }
return 0; return 0;
@ -373,38 +373,33 @@ static const struct super_operations hfsplus_sops = {
.put_super = hfsplus_put_super, .put_super = hfsplus_put_super,
.sync_fs = hfsplus_sync_fs, .sync_fs = hfsplus_sync_fs,
.statfs = hfsplus_statfs, .statfs = hfsplus_statfs,
.remount_fs = hfsplus_remount,
.show_options = hfsplus_show_options, .show_options = hfsplus_show_options,
}; };
static int hfsplus_fill_super(struct super_block *sb, void *data, int silent) static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
{ {
struct hfsplus_vh *vhdr; struct hfsplus_vh *vhdr;
struct hfsplus_sb_info *sbi; struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
hfsplus_cat_entry entry; hfsplus_cat_entry entry;
struct hfs_find_data fd; struct hfs_find_data fd;
struct inode *root, *inode; struct inode *root, *inode;
struct qstr str; struct qstr str;
struct nls_table *nls = NULL; struct nls_table *nls;
u64 last_fs_block, last_fs_page; u64 last_fs_block, last_fs_page;
int silent = fc->sb_flags & SB_SILENT;
int err; int err;
err = -ENOMEM;
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
if (!sbi)
goto out;
sb->s_fs_info = sbi;
mutex_init(&sbi->alloc_mutex); mutex_init(&sbi->alloc_mutex);
mutex_init(&sbi->vh_mutex); mutex_init(&sbi->vh_mutex);
spin_lock_init(&sbi->work_lock); spin_lock_init(&sbi->work_lock);
INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs); INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs);
hfsplus_fill_defaults(sbi);
err = -EINVAL; err = -EINVAL;
if (!hfsplus_parse_options(data, sbi)) { if (!sbi->nls) {
pr_err("unable to parse mount options\n"); /* try utf8 first, as this is the old default behaviour */
goto out_unload_nls; sbi->nls = load_nls("utf8");
if (!sbi->nls)
sbi->nls = load_nls_default();
} }
/* temporarily use utf8 to correctly find the hidden dir below */ /* temporarily use utf8 to correctly find the hidden dir below */
@ -616,7 +611,6 @@ out_unload_nls:
unload_nls(sbi->nls); unload_nls(sbi->nls);
unload_nls(nls); unload_nls(nls);
kfree(sbi); kfree(sbi);
out:
return err; return err;
} }
@ -641,18 +635,46 @@ static void hfsplus_free_inode(struct inode *inode)
#define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info) #define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)
static struct dentry *hfsplus_mount(struct file_system_type *fs_type, static int hfsplus_get_tree(struct fs_context *fc)
int flags, const char *dev_name, void *data)
{ {
return mount_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super); return get_tree_bdev(fc, hfsplus_fill_super);
}
static void hfsplus_free_fc(struct fs_context *fc)
{
kfree(fc->s_fs_info);
}
static const struct fs_context_operations hfsplus_context_ops = {
.parse_param = hfsplus_parse_param,
.get_tree = hfsplus_get_tree,
.reconfigure = hfsplus_reconfigure,
.free = hfsplus_free_fc,
};
static int hfsplus_init_fs_context(struct fs_context *fc)
{
struct hfsplus_sb_info *sbi;
sbi = kzalloc(sizeof(struct hfsplus_sb_info), GFP_KERNEL);
if (!sbi)
return -ENOMEM;
if (fc->purpose != FS_CONTEXT_FOR_RECONFIGURE)
hfsplus_fill_defaults(sbi);
fc->s_fs_info = sbi;
fc->ops = &hfsplus_context_ops;
return 0;
} }
static struct file_system_type hfsplus_fs_type = { static struct file_system_type hfsplus_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "hfsplus", .name = "hfsplus",
.mount = hfsplus_mount,
.kill_sb = kill_block_super, .kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV, .fs_flags = FS_REQUIRES_DEV,
.init_fs_context = hfsplus_init_fs_context,
}; };
MODULE_ALIAS_FS("hfsplus"); MODULE_ALIAS_FS("hfsplus");

View File

@ -9,7 +9,8 @@
#include "hpfs_fn.h" #include "hpfs_fn.h"
#include <linux/module.h> #include <linux/module.h>
#include <linux/parser.h> #include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/statfs.h> #include <linux/statfs.h>
#include <linux/magic.h> #include <linux/magic.h>
@ -272,146 +273,70 @@ static void destroy_inodecache(void)
kmem_cache_destroy(hpfs_inode_cachep); kmem_cache_destroy(hpfs_inode_cachep);
} }
/*
* A tiny parser for option strings, stolen from dosfs.
* Stolen again from read-only hpfs.
* And updated for table-driven option parsing.
*/
enum { enum {
Opt_help, Opt_uid, Opt_gid, Opt_umask, Opt_case_lower, Opt_case_asis, Opt_help, Opt_uid, Opt_gid, Opt_umask, Opt_case,
Opt_check_none, Opt_check_normal, Opt_check_strict, Opt_check, Opt_err, Opt_eas, Opt_chkdsk, Opt_timeshift,
Opt_err_cont, Opt_err_ro, Opt_err_panic,
Opt_eas_no, Opt_eas_ro, Opt_eas_rw,
Opt_chkdsk_no, Opt_chkdsk_errors, Opt_chkdsk_always,
Opt_timeshift, Opt_err,
}; };
static const match_table_t tokens = { static const struct constant_table hpfs_param_case[] = {
{Opt_help, "help"}, {"asis", 0},
{Opt_uid, "uid=%u"}, {"lower", 1},
{Opt_gid, "gid=%u"}, {}
{Opt_umask, "umask=%o"},
{Opt_case_lower, "case=lower"},
{Opt_case_asis, "case=asis"},
{Opt_check_none, "check=none"},
{Opt_check_normal, "check=normal"},
{Opt_check_strict, "check=strict"},
{Opt_err_cont, "errors=continue"},
{Opt_err_ro, "errors=remount-ro"},
{Opt_err_panic, "errors=panic"},
{Opt_eas_no, "eas=no"},
{Opt_eas_ro, "eas=ro"},
{Opt_eas_rw, "eas=rw"},
{Opt_chkdsk_no, "chkdsk=no"},
{Opt_chkdsk_errors, "chkdsk=errors"},
{Opt_chkdsk_always, "chkdsk=always"},
{Opt_timeshift, "timeshift=%d"},
{Opt_err, NULL},
}; };
static int parse_opts(char *opts, kuid_t *uid, kgid_t *gid, umode_t *umask, static const struct constant_table hpfs_param_check[] = {
int *lowercase, int *eas, int *chk, int *errs, {"none", 0},
int *chkdsk, int *timeshift) {"normal", 1},
{ {"strict", 2},
char *p; {}
int option; };
if (!opts) static const struct constant_table hpfs_param_err[] = {
return 1; {"continue", 0},
{"remount-ro", 1},
{"panic", 2},
{}
};
/*pr_info("Parsing opts: '%s'\n",opts);*/ static const struct constant_table hpfs_param_eas[] = {
{"no", 0},
{"ro", 1},
{"rw", 2},
{}
};
while ((p = strsep(&opts, ",")) != NULL) { static const struct constant_table hpfs_param_chkdsk[] = {
substring_t args[MAX_OPT_ARGS]; {"no", 0},
int token; {"errors", 1},
if (!*p) {"always", 2},
continue; {}
};
token = match_token(p, tokens, args); static const struct fs_parameter_spec hpfs_param_spec[] = {
switch (token) { fsparam_flag ("help", Opt_help),
case Opt_help: fsparam_uid ("uid", Opt_uid),
return 2; fsparam_gid ("gid", Opt_gid),
case Opt_uid: fsparam_u32oct ("umask", Opt_umask),
if (match_int(args, &option)) fsparam_enum ("case", Opt_case, hpfs_param_case),
return 0; fsparam_enum ("check", Opt_check, hpfs_param_check),
*uid = make_kuid(current_user_ns(), option); fsparam_enum ("errors", Opt_err, hpfs_param_err),
if (!uid_valid(*uid)) fsparam_enum ("eas", Opt_eas, hpfs_param_eas),
return 0; fsparam_enum ("chkdsk", Opt_chkdsk, hpfs_param_chkdsk),
break; fsparam_s32 ("timeshift", Opt_timeshift),
case Opt_gid: {}
if (match_int(args, &option)) };
return 0;
*gid = make_kgid(current_user_ns(), option); struct hpfs_fc_context {
if (!gid_valid(*gid)) kuid_t uid;
return 0; kgid_t gid;
break; umode_t umask;
case Opt_umask: int lowercase;
if (match_octal(args, &option)) int eas;
return 0; int chk;
*umask = option; int errs;
break; int chkdsk;
case Opt_case_lower: int timeshift;
*lowercase = 1; };
break;
case Opt_case_asis:
*lowercase = 0;
break;
case Opt_check_none:
*chk = 0;
break;
case Opt_check_normal:
*chk = 1;
break;
case Opt_check_strict:
*chk = 2;
break;
case Opt_err_cont:
*errs = 0;
break;
case Opt_err_ro:
*errs = 1;
break;
case Opt_err_panic:
*errs = 2;
break;
case Opt_eas_no:
*eas = 0;
break;
case Opt_eas_ro:
*eas = 1;
break;
case Opt_eas_rw:
*eas = 2;
break;
case Opt_chkdsk_no:
*chkdsk = 0;
break;
case Opt_chkdsk_errors:
*chkdsk = 1;
break;
case Opt_chkdsk_always:
*chkdsk = 2;
break;
case Opt_timeshift:
{
int m = 1;
char *rhs = args[0].from;
if (!rhs || !*rhs)
return 0;
if (*rhs == '-') m = -1;
if (*rhs == '+' || *rhs == '-') rhs++;
*timeshift = simple_strtoul(rhs, &rhs, 0) * m;
if (*rhs)
return 0;
break;
}
default:
return 0;
}
}
return 1;
}
static inline void hpfs_help(void) static inline void hpfs_help(void)
{ {
@ -439,49 +364,92 @@ HPFS filesystem options:\n\
\n"); \n");
} }
static int hpfs_remount_fs(struct super_block *s, int *flags, char *data) static int hpfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{ {
kuid_t uid; struct hpfs_fc_context *ctx = fc->fs_private;
kgid_t gid; struct fs_parse_result result;
umode_t umask; int opt;
int lowercase, eas, chk, errs, chkdsk, timeshift;
int o; opt = fs_parse(fc, hpfs_param_spec, param, &result);
if (opt < 0)
return opt;
switch (opt) {
case Opt_help:
hpfs_help();
return -EINVAL;
case Opt_uid:
ctx->uid = result.uid;
break;
case Opt_gid:
ctx->gid = result.gid;
break;
case Opt_umask:
ctx->umask = result.uint_32;
break;
case Opt_case:
ctx->lowercase = result.uint_32;
break;
case Opt_check:
ctx->chk = result.uint_32;
break;
case Opt_err:
ctx->errs = result.uint_32;
break;
case Opt_eas:
ctx->eas = result.uint_32;
break;
case Opt_chkdsk:
ctx->chkdsk = result.uint_32;
break;
case Opt_timeshift:
{
int m = 1;
char *rhs = param->string;
int timeshift;
if (*rhs == '-') m = -1;
if (*rhs == '+' || *rhs == '-') rhs++;
timeshift = simple_strtoul(rhs, &rhs, 0) * m;
if (*rhs)
return -EINVAL;
ctx->timeshift = timeshift;
break;
}
default:
return -EINVAL;
}
return 0;
}
static int hpfs_reconfigure(struct fs_context *fc)
{
struct hpfs_fc_context *ctx = fc->fs_private;
struct super_block *s = fc->root->d_sb;
struct hpfs_sb_info *sbi = hpfs_sb(s); struct hpfs_sb_info *sbi = hpfs_sb(s);
sync_filesystem(s); sync_filesystem(s);
*flags |= SB_NOATIME; fc->sb_flags |= SB_NOATIME;
hpfs_lock(s); hpfs_lock(s);
uid = sbi->sb_uid; gid = sbi->sb_gid;
umask = 0777 & ~sbi->sb_mode;
lowercase = sbi->sb_lowercase;
eas = sbi->sb_eas; chk = sbi->sb_chk; chkdsk = sbi->sb_chkdsk;
errs = sbi->sb_err; timeshift = sbi->sb_timeshift;
if (!(o = parse_opts(data, &uid, &gid, &umask, &lowercase, if (ctx->timeshift != sbi->sb_timeshift) {
&eas, &chk, &errs, &chkdsk, &timeshift))) {
pr_err("bad mount options.\n");
goto out_err;
}
if (o == 2) {
hpfs_help();
goto out_err;
}
if (timeshift != sbi->sb_timeshift) {
pr_err("timeshift can't be changed using remount.\n"); pr_err("timeshift can't be changed using remount.\n");
goto out_err; goto out_err;
} }
unmark_dirty(s); unmark_dirty(s);
sbi->sb_uid = uid; sbi->sb_gid = gid; sbi->sb_uid = ctx->uid; sbi->sb_gid = ctx->gid;
sbi->sb_mode = 0777 & ~umask; sbi->sb_mode = 0777 & ~ctx->umask;
sbi->sb_lowercase = lowercase; sbi->sb_lowercase = ctx->lowercase;
sbi->sb_eas = eas; sbi->sb_chk = chk; sbi->sb_chkdsk = chkdsk; sbi->sb_eas = ctx->eas; sbi->sb_chk = ctx->chk;
sbi->sb_err = errs; sbi->sb_timeshift = timeshift; sbi->sb_chkdsk = ctx->chkdsk;
sbi->sb_err = ctx->errs; sbi->sb_timeshift = ctx->timeshift;
if (!(*flags & SB_RDONLY)) mark_dirty(s, 1); if (!(fc->sb_flags & SB_RDONLY)) mark_dirty(s, 1);
hpfs_unlock(s); hpfs_unlock(s);
return 0; return 0;
@ -530,30 +498,24 @@ static const struct super_operations hpfs_sops =
.evict_inode = hpfs_evict_inode, .evict_inode = hpfs_evict_inode,
.put_super = hpfs_put_super, .put_super = hpfs_put_super,
.statfs = hpfs_statfs, .statfs = hpfs_statfs,
.remount_fs = hpfs_remount_fs,
.show_options = hpfs_show_options, .show_options = hpfs_show_options,
}; };
static int hpfs_fill_super(struct super_block *s, void *options, int silent) static int hpfs_fill_super(struct super_block *s, struct fs_context *fc)
{ {
struct hpfs_fc_context *ctx = fc->fs_private;
struct buffer_head *bh0, *bh1, *bh2; struct buffer_head *bh0, *bh1, *bh2;
struct hpfs_boot_block *bootblock; struct hpfs_boot_block *bootblock;
struct hpfs_super_block *superblock; struct hpfs_super_block *superblock;
struct hpfs_spare_block *spareblock; struct hpfs_spare_block *spareblock;
struct hpfs_sb_info *sbi; struct hpfs_sb_info *sbi;
struct inode *root; struct inode *root;
int silent = fc->sb_flags & SB_SILENT;
kuid_t uid;
kgid_t gid;
umode_t umask;
int lowercase, eas, chk, errs, chkdsk, timeshift;
dnode_secno root_dno; dnode_secno root_dno;
struct hpfs_dirent *de = NULL; struct hpfs_dirent *de = NULL;
struct quad_buffer_head qbh; struct quad_buffer_head qbh;
int o;
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
if (!sbi) { if (!sbi) {
return -ENOMEM; return -ENOMEM;
@ -563,26 +525,6 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
mutex_init(&sbi->hpfs_mutex); mutex_init(&sbi->hpfs_mutex);
hpfs_lock(s); hpfs_lock(s);
uid = current_uid();
gid = current_gid();
umask = current_umask();
lowercase = 0;
eas = 2;
chk = 1;
errs = 1;
chkdsk = 1;
timeshift = 0;
if (!(o = parse_opts(options, &uid, &gid, &umask, &lowercase,
&eas, &chk, &errs, &chkdsk, &timeshift))) {
pr_err("bad mount options.\n");
goto bail0;
}
if (o==2) {
hpfs_help();
goto bail0;
}
/*sbi->sb_mounting = 1;*/ /*sbi->sb_mounting = 1;*/
sb_set_blocksize(s, 512); sb_set_blocksize(s, 512);
sbi->sb_fs_size = -1; sbi->sb_fs_size = -1;
@ -622,17 +564,17 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
sbi->sb_dirband_start = le32_to_cpu(superblock->dir_band_start); sbi->sb_dirband_start = le32_to_cpu(superblock->dir_band_start);
sbi->sb_dirband_size = le32_to_cpu(superblock->n_dir_band); sbi->sb_dirband_size = le32_to_cpu(superblock->n_dir_band);
sbi->sb_dmap = le32_to_cpu(superblock->dir_band_bitmap); sbi->sb_dmap = le32_to_cpu(superblock->dir_band_bitmap);
sbi->sb_uid = uid; sbi->sb_uid = ctx->uid;
sbi->sb_gid = gid; sbi->sb_gid = ctx->gid;
sbi->sb_mode = 0777 & ~umask; sbi->sb_mode = 0777 & ~ctx->umask;
sbi->sb_n_free = -1; sbi->sb_n_free = -1;
sbi->sb_n_free_dnodes = -1; sbi->sb_n_free_dnodes = -1;
sbi->sb_lowercase = lowercase; sbi->sb_lowercase = ctx->lowercase;
sbi->sb_eas = eas; sbi->sb_eas = ctx->eas;
sbi->sb_chk = chk; sbi->sb_chk = ctx->chk;
sbi->sb_chkdsk = chkdsk; sbi->sb_chkdsk = ctx->chkdsk;
sbi->sb_err = errs; sbi->sb_err = ctx->errs;
sbi->sb_timeshift = timeshift; sbi->sb_timeshift = ctx->timeshift;
sbi->sb_was_error = 0; sbi->sb_was_error = 0;
sbi->sb_cp_table = NULL; sbi->sb_cp_table = NULL;
sbi->sb_c_bitmap = -1; sbi->sb_c_bitmap = -1;
@ -653,7 +595,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
/* Check for general fs errors*/ /* Check for general fs errors*/
if (spareblock->dirty && !spareblock->old_wrote) { if (spareblock->dirty && !spareblock->old_wrote) {
if (errs == 2) { if (sbi->sb_err == 2) {
pr_err("Improperly stopped, not mounted\n"); pr_err("Improperly stopped, not mounted\n");
goto bail4; goto bail4;
} }
@ -667,16 +609,16 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
} }
if (le32_to_cpu(spareblock->n_dnode_spares) != le32_to_cpu(spareblock->n_dnode_spares_free)) { if (le32_to_cpu(spareblock->n_dnode_spares) != le32_to_cpu(spareblock->n_dnode_spares_free)) {
if (errs >= 2) { if (sbi->sb_err >= 2) {
pr_err("Spare dnodes used, try chkdsk\n"); pr_err("Spare dnodes used, try chkdsk\n");
mark_dirty(s, 0); mark_dirty(s, 0);
goto bail4; goto bail4;
} }
hpfs_error(s, "warning: spare dnodes used, try chkdsk"); hpfs_error(s, "warning: spare dnodes used, try chkdsk");
if (errs == 0) if (sbi->sb_err == 0)
pr_err("Proceeding, but your filesystem could be corrupted if you delete files or directories\n"); pr_err("Proceeding, but your filesystem could be corrupted if you delete files or directories\n");
} }
if (chk) { if (sbi->sb_chk) {
unsigned a; unsigned a;
if (le32_to_cpu(superblock->dir_band_end) - le32_to_cpu(superblock->dir_band_start) + 1 != le32_to_cpu(superblock->n_dir_band) || if (le32_to_cpu(superblock->dir_band_end) - le32_to_cpu(superblock->dir_band_start) + 1 != le32_to_cpu(superblock->n_dir_band) ||
le32_to_cpu(superblock->dir_band_end) < le32_to_cpu(superblock->dir_band_start) || le32_to_cpu(superblock->n_dir_band) > 0x4000) { le32_to_cpu(superblock->dir_band_end) < le32_to_cpu(superblock->dir_band_start) || le32_to_cpu(superblock->n_dir_band) > 0x4000) {
@ -755,18 +697,70 @@ bail0:
return -EINVAL; return -EINVAL;
} }
static struct dentry *hpfs_mount(struct file_system_type *fs_type, static int hpfs_get_tree(struct fs_context *fc)
int flags, const char *dev_name, void *data)
{ {
return mount_bdev(fs_type, flags, dev_name, data, hpfs_fill_super); return get_tree_bdev(fc, hpfs_fill_super);
} }
static void hpfs_free_fc(struct fs_context *fc)
{
kfree(fc->fs_private);
}
static const struct fs_context_operations hpfs_fc_context_ops = {
.parse_param = hpfs_parse_param,
.get_tree = hpfs_get_tree,
.reconfigure = hpfs_reconfigure,
.free = hpfs_free_fc,
};
static int hpfs_init_fs_context(struct fs_context *fc)
{
struct hpfs_fc_context *ctx;
ctx = kzalloc(sizeof(struct hpfs_fc_context), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
struct super_block *sb = fc->root->d_sb;
struct hpfs_sb_info *sbi = hpfs_sb(sb);
ctx->uid = sbi->sb_uid;
ctx->gid = sbi->sb_gid;
ctx->umask = 0777 & ~sbi->sb_mode;
ctx->lowercase = sbi->sb_lowercase;
ctx->eas = sbi->sb_eas;
ctx->chk = sbi->sb_chk;
ctx->chkdsk = sbi->sb_chkdsk;
ctx->errs = sbi->sb_err;
ctx->timeshift = sbi->sb_timeshift;
} else {
ctx->uid = current_uid();
ctx->gid = current_gid();
ctx->umask = current_umask();
ctx->lowercase = 0;
ctx->eas = 2;
ctx->chk = 1;
ctx->errs = 1;
ctx->chkdsk = 1;
ctx->timeshift = 0;
}
fc->fs_private = ctx;
fc->ops = &hpfs_fc_context_ops;
return 0;
};
static struct file_system_type hpfs_fs_type = { static struct file_system_type hpfs_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "hpfs", .name = "hpfs",
.mount = hpfs_mount,
.kill_sb = kill_block_super, .kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV, .fs_flags = FS_REQUIRES_DEV,
.init_fs_context = hpfs_init_fs_context,
.parameters = hpfs_param_spec,
}; };
MODULE_ALIAS_FS("hpfs"); MODULE_ALIAS_FS("hpfs");

View File

@ -24,6 +24,7 @@
#define JFS_ERR_REMOUNT_RO 0x00000002 /* remount read-only */ #define JFS_ERR_REMOUNT_RO 0x00000002 /* remount read-only */
#define JFS_ERR_CONTINUE 0x00000004 /* continue */ #define JFS_ERR_CONTINUE 0x00000004 /* continue */
#define JFS_ERR_PANIC 0x00000008 /* panic */ #define JFS_ERR_PANIC 0x00000008 /* panic */
#define JFS_ERR_MASK (JFS_ERR_REMOUNT_RO|JFS_ERR_CONTINUE|JFS_ERR_PANIC)
/* Quota support */ /* Quota support */
#define JFS_USRQUOTA 0x00000010 #define JFS_USRQUOTA 0x00000010

View File

@ -6,11 +6,11 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/parser.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/vfs.h> #include <linux/vfs.h>
#include <linux/quotaops.h> #include <linux/quotaops.h>
#include <linux/mount.h> #include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/kthread.h> #include <linux/kthread.h>
#include <linux/posix_acl.h> #include <linux/posix_acl.h>
@ -210,117 +210,105 @@ enum {
Opt_discard, Opt_nodiscard, Opt_discard_minblk Opt_discard, Opt_nodiscard, Opt_discard_minblk
}; };
static const match_table_t tokens = { static const struct constant_table jfs_param_errors[] = {
{Opt_integrity, "integrity"}, {"continue", JFS_ERR_CONTINUE},
{Opt_nointegrity, "nointegrity"}, {"remount-ro", JFS_ERR_REMOUNT_RO},
{Opt_iocharset, "iocharset=%s"}, {"panic", JFS_ERR_PANIC},
{Opt_resize, "resize=%u"}, {}
{Opt_resize_nosize, "resize"},
{Opt_errors, "errors=%s"},
{Opt_ignore, "noquota"},
{Opt_quota, "quota"},
{Opt_usrquota, "usrquota"},
{Opt_grpquota, "grpquota"},
{Opt_uid, "uid=%u"},
{Opt_gid, "gid=%u"},
{Opt_umask, "umask=%u"},
{Opt_discard, "discard"},
{Opt_nodiscard, "nodiscard"},
{Opt_discard_minblk, "discard=%u"},
{Opt_err, NULL}
}; };
static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, static const struct fs_parameter_spec jfs_param_spec[] = {
int *flag) fsparam_flag_no ("integrity", Opt_integrity),
fsparam_string ("iocharset", Opt_iocharset),
fsparam_u64 ("resize", Opt_resize),
fsparam_flag ("resize", Opt_resize_nosize),
fsparam_enum ("errors", Opt_errors, jfs_param_errors),
fsparam_flag ("quota", Opt_quota),
fsparam_flag ("noquota", Opt_ignore),
fsparam_flag ("usrquota", Opt_usrquota),
fsparam_flag ("grpquota", Opt_grpquota),
fsparam_uid ("uid", Opt_uid),
fsparam_gid ("gid", Opt_gid),
fsparam_u32oct ("umask", Opt_umask),
fsparam_flag ("discard", Opt_discard),
fsparam_u32 ("discard", Opt_discard_minblk),
fsparam_flag ("nodiscard", Opt_nodiscard),
{}
};
struct jfs_context {
int flag;
kuid_t uid;
kgid_t gid;
uint umask;
uint minblks_trim;
void *nls_map;
bool resize;
s64 newLVSize;
};
static int jfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{ {
void *nls_map = (void *)-1; /* -1: no change; NULL: none */ struct jfs_context *ctx = fc->fs_private;
char *p; int reconfigure = (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE);
struct jfs_sb_info *sbi = JFS_SBI(sb); struct fs_parse_result result;
struct nls_table *nls_map;
int opt;
*newLVSize = 0; opt = fs_parse(fc, jfs_param_spec, param, &result);
if (opt < 0)
return opt;
if (!options) switch (opt) {
return 1;
while ((p = strsep(&options, ",")) != NULL) {
substring_t args[MAX_OPT_ARGS];
int token;
if (!*p)
continue;
token = match_token(p, tokens, args);
switch (token) {
case Opt_integrity: case Opt_integrity:
*flag &= ~JFS_NOINTEGRITY; if (result.negated)
break; ctx->flag |= JFS_NOINTEGRITY;
case Opt_nointegrity: else
*flag |= JFS_NOINTEGRITY; ctx->flag &= ~JFS_NOINTEGRITY;
break; break;
case Opt_ignore: case Opt_ignore:
/* Silently ignore the quota options */ /* Silently ignore the quota options */
/* Don't do anything ;-) */ /* Don't do anything ;-) */
break; break;
case Opt_iocharset: case Opt_iocharset:
if (nls_map && nls_map != (void *) -1) if (ctx->nls_map && ctx->nls_map != (void *) -1) {
unload_nls(nls_map); unload_nls(ctx->nls_map);
if (!strcmp(args[0].from, "none")) ctx->nls_map = NULL;
nls_map = NULL; }
if (!strcmp(param->string, "none"))
ctx->nls_map = NULL;
else { else {
nls_map = load_nls(args[0].from); nls_map = load_nls(param->string);
if (!nls_map) { if (!nls_map) {
pr_err("JFS: charset not found\n"); pr_err("JFS: charset not found\n");
goto cleanup; return -EINVAL;
} }
ctx->nls_map = nls_map;
} }
break; break;
case Opt_resize: case Opt_resize:
{ if (!reconfigure)
char *resize = args[0].from; return -EINVAL;
int rc = kstrtoll(resize, 0, newLVSize); ctx->resize = true;
ctx->newLVSize = result.uint_64;
if (rc)
goto cleanup;
break; break;
}
case Opt_resize_nosize: case Opt_resize_nosize:
{ if (!reconfigure)
*newLVSize = sb_bdev_nr_blocks(sb); return -EINVAL;
if (*newLVSize == 0) ctx->resize = true;
pr_err("JFS: Cannot determine volume size\n");
break; break;
}
case Opt_errors: case Opt_errors:
{ ctx->flag &= ~JFS_ERR_MASK;
char *errors = args[0].from; ctx->flag |= result.uint_32;
if (!errors || !*errors)
goto cleanup;
if (!strcmp(errors, "continue")) {
*flag &= ~JFS_ERR_REMOUNT_RO;
*flag &= ~JFS_ERR_PANIC;
*flag |= JFS_ERR_CONTINUE;
} else if (!strcmp(errors, "remount-ro")) {
*flag &= ~JFS_ERR_CONTINUE;
*flag &= ~JFS_ERR_PANIC;
*flag |= JFS_ERR_REMOUNT_RO;
} else if (!strcmp(errors, "panic")) {
*flag &= ~JFS_ERR_CONTINUE;
*flag &= ~JFS_ERR_REMOUNT_RO;
*flag |= JFS_ERR_PANIC;
} else {
pr_err("JFS: %s is an invalid error handler\n",
errors);
goto cleanup;
}
break; break;
}
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
case Opt_quota: case Opt_quota:
case Opt_usrquota: case Opt_usrquota:
*flag |= JFS_USRQUOTA; ctx->flag |= JFS_USRQUOTA;
break; break;
case Opt_grpquota: case Opt_grpquota:
*flag |= JFS_GRPQUOTA; ctx->flag |= JFS_GRPQUOTA;
break; break;
#else #else
case Opt_usrquota: case Opt_usrquota:
@ -330,120 +318,87 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
break; break;
#endif #endif
case Opt_uid: case Opt_uid:
{ ctx->uid = result.uid;
char *uid = args[0].from;
uid_t val;
int rc = kstrtouint(uid, 0, &val);
if (rc)
goto cleanup;
sbi->uid = make_kuid(current_user_ns(), val);
if (!uid_valid(sbi->uid))
goto cleanup;
break; break;
}
case Opt_gid: case Opt_gid:
{ ctx->gid = result.gid;
char *gid = args[0].from;
gid_t val;
int rc = kstrtouint(gid, 0, &val);
if (rc)
goto cleanup;
sbi->gid = make_kgid(current_user_ns(), val);
if (!gid_valid(sbi->gid))
goto cleanup;
break; break;
}
case Opt_umask: case Opt_umask:
{ if (result.uint_32 & ~0777) {
char *umask = args[0].from;
int rc = kstrtouint(umask, 8, &sbi->umask);
if (rc)
goto cleanup;
if (sbi->umask & ~0777) {
pr_err("JFS: Invalid value of umask\n"); pr_err("JFS: Invalid value of umask\n");
goto cleanup; return -EINVAL;
} }
ctx->umask = result.uint_32;
break; break;
}
case Opt_discard: case Opt_discard:
/* if set to 1, even copying files will cause /* if set to 1, even copying files will cause
* trimming :O * trimming :O
* -> user has more control over the online trimming * -> user has more control over the online trimming
*/ */
sbi->minblks_trim = 64; ctx->minblks_trim = 64;
if (bdev_max_discard_sectors(sb->s_bdev)) ctx->flag |= JFS_DISCARD;
*flag |= JFS_DISCARD;
else
pr_err("JFS: discard option not supported on device\n");
break; break;
case Opt_nodiscard: case Opt_nodiscard:
*flag &= ~JFS_DISCARD; ctx->flag &= ~JFS_DISCARD;
break; break;
case Opt_discard_minblk: case Opt_discard_minblk:
{ ctx->minblks_trim = result.uint_32;
char *minblks_trim = args[0].from; ctx->flag |= JFS_DISCARD;
int rc;
if (bdev_max_discard_sectors(sb->s_bdev)) {
*flag |= JFS_DISCARD;
rc = kstrtouint(minblks_trim, 0,
&sbi->minblks_trim);
if (rc)
goto cleanup;
} else
pr_err("JFS: discard option not supported on device\n");
break; break;
}
default: default:
printk("jfs: Unrecognized mount option \"%s\" or missing value\n", return -EINVAL;
p);
goto cleanup;
}
} }
if (nls_map != (void *) -1) {
/* Discard old (if remount) */
unload_nls(sbi->nls_tab);
sbi->nls_tab = nls_map;
}
return 1;
cleanup:
if (nls_map && nls_map != (void *) -1)
unload_nls(nls_map);
return 0; return 0;
} }
static int jfs_remount(struct super_block *sb, int *flags, char *data) static int jfs_reconfigure(struct fs_context *fc)
{ {
s64 newLVSize = 0; struct jfs_context *ctx = fc->fs_private;
struct super_block *sb = fc->root->d_sb;
int readonly = fc->sb_flags & SB_RDONLY;
int rc = 0; int rc = 0;
int flag = JFS_SBI(sb)->flag; int flag = ctx->flag;
int ret; int ret;
sync_filesystem(sb); sync_filesystem(sb);
if (!parse_options(data, sb, &newLVSize, &flag))
return -EINVAL;
if (newLVSize) { /* Transfer results of parsing to the sbi */
JFS_SBI(sb)->flag = ctx->flag;
JFS_SBI(sb)->uid = ctx->uid;
JFS_SBI(sb)->gid = ctx->gid;
JFS_SBI(sb)->umask = ctx->umask;
JFS_SBI(sb)->minblks_trim = ctx->minblks_trim;
if (ctx->nls_map != (void *) -1) {
unload_nls(JFS_SBI(sb)->nls_tab);
JFS_SBI(sb)->nls_tab = ctx->nls_map;
}
ctx->nls_map = NULL;
if (ctx->resize) {
if (sb_rdonly(sb)) { if (sb_rdonly(sb)) {
pr_err("JFS: resize requires volume to be mounted read-write\n"); pr_err("JFS: resize requires volume to be mounted read-write\n");
return -EROFS; return -EROFS;
} }
rc = jfs_extendfs(sb, newLVSize, 0);
if (!ctx->newLVSize) {
ctx->newLVSize = sb_bdev_nr_blocks(sb);
if (ctx->newLVSize == 0)
pr_err("JFS: Cannot determine volume size\n");
}
rc = jfs_extendfs(sb, ctx->newLVSize, 0);
if (rc) if (rc)
return rc; return rc;
} }
if (sb_rdonly(sb) && !(*flags & SB_RDONLY)) { if (sb_rdonly(sb) && !readonly) {
/* /*
* Invalidate any previously read metadata. fsck may have * Invalidate any previously read metadata. fsck may have
* changed the on-disk data since we mounted r/o * changed the on-disk data since we mounted r/o
@ -459,7 +414,7 @@ static int jfs_remount(struct super_block *sb, int *flags, char *data)
dquot_resume(sb, -1); dquot_resume(sb, -1);
return ret; return ret;
} }
if (!sb_rdonly(sb) && (*flags & SB_RDONLY)) { if (!sb_rdonly(sb) && readonly) {
rc = dquot_suspend(sb, -1); rc = dquot_suspend(sb, -1);
if (rc < 0) if (rc < 0)
return rc; return rc;
@ -467,7 +422,7 @@ static int jfs_remount(struct super_block *sb, int *flags, char *data)
JFS_SBI(sb)->flag = flag; JFS_SBI(sb)->flag = flag;
return rc; return rc;
} }
if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY)) if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY)) {
if (!sb_rdonly(sb)) { if (!sb_rdonly(sb)) {
rc = jfs_umount_rw(sb); rc = jfs_umount_rw(sb);
if (rc) if (rc)
@ -477,18 +432,20 @@ static int jfs_remount(struct super_block *sb, int *flags, char *data)
ret = jfs_mount_rw(sb, 1); ret = jfs_mount_rw(sb, 1);
return ret; return ret;
} }
}
JFS_SBI(sb)->flag = flag; JFS_SBI(sb)->flag = flag;
return 0; return 0;
} }
static int jfs_fill_super(struct super_block *sb, void *data, int silent) static int jfs_fill_super(struct super_block *sb, struct fs_context *fc)
{ {
struct jfs_context *ctx = fc->fs_private;
int silent = fc->sb_flags & SB_SILENT;
struct jfs_sb_info *sbi; struct jfs_sb_info *sbi;
struct inode *inode; struct inode *inode;
int rc; int rc;
s64 newLVSize = 0; int ret = -EINVAL;
int flag, ret = -EINVAL;
jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags); jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
@ -501,24 +458,34 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
sb->s_time_min = 0; sb->s_time_min = 0;
sb->s_time_max = U32_MAX; sb->s_time_max = U32_MAX;
sbi->sb = sb; sbi->sb = sb;
sbi->uid = INVALID_UID;
sbi->gid = INVALID_GID;
sbi->umask = -1;
/* initialize the mount flag and determine the default error handler */ /* Transfer results of parsing to the sbi */
flag = JFS_ERR_REMOUNT_RO; sbi->flag = ctx->flag;
sbi->uid = ctx->uid;
sbi->gid = ctx->gid;
sbi->umask = ctx->umask;
if (ctx->nls_map != (void *) -1) {
unload_nls(sbi->nls_tab);
sbi->nls_tab = ctx->nls_map;
}
ctx->nls_map = NULL;
if (!parse_options((char *) data, sb, &newLVSize, &flag)) if (sbi->flag & JFS_DISCARD) {
goto out_kfree; if (!bdev_max_discard_sectors(sb->s_bdev)) {
sbi->flag = flag; pr_err("JFS: discard option not supported on device\n");
sbi->flag &= ~JFS_DISCARD;
} else {
sbi->minblks_trim = ctx->minblks_trim;
}
}
#ifdef CONFIG_JFS_POSIX_ACL #ifdef CONFIG_JFS_POSIX_ACL
sb->s_flags |= SB_POSIXACL; sb->s_flags |= SB_POSIXACL;
#endif #endif
if (newLVSize) { if (ctx->resize) {
pr_err("resize option for remount only\n"); pr_err("resize option for remount only\n");
goto out_kfree; goto out_unload;
} }
/* /*
@ -608,7 +575,6 @@ out_mount_failed:
sbi->direct_inode = NULL; sbi->direct_inode = NULL;
out_unload: out_unload:
unload_nls(sbi->nls_tab); unload_nls(sbi->nls_tab);
out_kfree:
kfree(sbi); kfree(sbi);
return ret; return ret;
} }
@ -664,10 +630,9 @@ out:
return rc; return rc;
} }
static struct dentry *jfs_do_mount(struct file_system_type *fs_type, static int jfs_get_tree(struct fs_context *fc)
int flags, const char *dev_name, void *data)
{ {
return mount_bdev(fs_type, flags, dev_name, data, jfs_fill_super); return get_tree_bdev(fc, jfs_fill_super);
} }
static int jfs_sync_fs(struct super_block *sb, int wait) static int jfs_sync_fs(struct super_block *sb, int wait)
@ -886,7 +851,6 @@ static const struct super_operations jfs_super_operations = {
.freeze_fs = jfs_freeze, .freeze_fs = jfs_freeze,
.unfreeze_fs = jfs_unfreeze, .unfreeze_fs = jfs_unfreeze,
.statfs = jfs_statfs, .statfs = jfs_statfs,
.remount_fs = jfs_remount,
.show_options = jfs_show_options, .show_options = jfs_show_options,
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
.quota_read = jfs_quota_read, .quota_read = jfs_quota_read,
@ -902,12 +866,71 @@ static const struct export_operations jfs_export_operations = {
.get_parent = jfs_get_parent, .get_parent = jfs_get_parent,
}; };
static void jfs_init_options(struct fs_context *fc, struct jfs_context *ctx)
{
if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
struct super_block *sb = fc->root->d_sb;
/* Copy over current option values and mount flags */
ctx->uid = JFS_SBI(sb)->uid;
ctx->gid = JFS_SBI(sb)->gid;
ctx->umask = JFS_SBI(sb)->umask;
ctx->nls_map = (void *)-1;
ctx->minblks_trim = JFS_SBI(sb)->minblks_trim;
ctx->flag = JFS_SBI(sb)->flag;
} else {
/*
* Initialize the mount flag and determine the default
* error handler
*/
ctx->flag = JFS_ERR_REMOUNT_RO;
ctx->uid = INVALID_UID;
ctx->gid = INVALID_GID;
ctx->umask = -1;
ctx->nls_map = (void *)-1;
}
}
static void jfs_free_fc(struct fs_context *fc)
{
struct jfs_context *ctx = fc->fs_private;
if (ctx->nls_map != (void *) -1)
unload_nls(ctx->nls_map);
kfree(ctx);
}
static const struct fs_context_operations jfs_context_ops = {
.parse_param = jfs_parse_param,
.get_tree = jfs_get_tree,
.reconfigure = jfs_reconfigure,
.free = jfs_free_fc,
};
static int jfs_init_fs_context(struct fs_context *fc)
{
struct jfs_context *ctx;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
jfs_init_options(fc, ctx);
fc->fs_private = ctx;
fc->ops = &jfs_context_ops;
return 0;
}
static struct file_system_type jfs_fs_type = { static struct file_system_type jfs_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "jfs", .name = "jfs",
.mount = jfs_do_mount,
.kill_sb = kill_block_super, .kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV, .fs_flags = FS_REQUIRES_DEV,
.init_fs_context = jfs_init_fs_context,
.parameters = jfs_param_spec,
}; };
MODULE_ALIAS_FS("jfs"); MODULE_ALIAS_FS("jfs");

View File

@ -19,9 +19,9 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/kthread.h> #include <linux/kthread.h>
#include <linux/parser.h> #include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/mount.h>
#include <linux/math64.h> #include <linux/math64.h>
#include <linux/writeback.h> #include <linux/writeback.h>
#include "ubifs.h" #include "ubifs.h"
@ -981,177 +981,120 @@ enum {
Opt_auth_key, Opt_auth_key,
Opt_auth_hash_name, Opt_auth_hash_name,
Opt_ignore, Opt_ignore,
Opt_err,
}; };
static const match_table_t tokens = { static const struct constant_table ubifs_param_compr[] = {
{Opt_fast_unmount, "fast_unmount"}, { "none", UBIFS_COMPR_NONE },
{Opt_norm_unmount, "norm_unmount"}, { "lzo", UBIFS_COMPR_LZO },
{Opt_bulk_read, "bulk_read"}, { "zlib", UBIFS_COMPR_ZLIB },
{Opt_no_bulk_read, "no_bulk_read"}, { "zstd", UBIFS_COMPR_ZSTD },
{Opt_chk_data_crc, "chk_data_crc"}, {}
{Opt_no_chk_data_crc, "no_chk_data_crc"}, };
{Opt_override_compr, "compr=%s"},
{Opt_auth_key, "auth_key=%s"}, static const struct constant_table ubifs_param_assert[] = {
{Opt_auth_hash_name, "auth_hash_name=%s"}, { "report", ASSACT_REPORT },
{Opt_ignore, "ubi=%s"}, { "read-only", ASSACT_RO },
{Opt_ignore, "vol=%s"}, { "panic", ASSACT_PANIC },
{Opt_assert, "assert=%s"}, {}
{Opt_err, NULL}, };
static const struct fs_parameter_spec ubifs_fs_param_spec[] = {
fsparam_flag ("fast_unmount", Opt_fast_unmount),
fsparam_flag ("norm_unmount", Opt_norm_unmount),
fsparam_flag ("bulk_read", Opt_bulk_read),
fsparam_flag ("no_bulk_read", Opt_no_bulk_read),
fsparam_flag ("chk_data_crc", Opt_chk_data_crc),
fsparam_flag ("no_chk_data_crc", Opt_no_chk_data_crc),
fsparam_enum ("compr", Opt_override_compr, ubifs_param_compr),
fsparam_enum ("assert", Opt_assert, ubifs_param_assert),
fsparam_string ("auth_key", Opt_auth_key),
fsparam_string ("auth_hash_name", Opt_auth_hash_name),
fsparam_string ("ubi", Opt_ignore),
fsparam_string ("vol", Opt_ignore),
{}
};
struct ubifs_fs_context {
struct ubifs_mount_opts mount_opts;
char *auth_key_name;
char *auth_hash_name;
unsigned int no_chk_data_crc:1;
unsigned int bulk_read:1;
unsigned int default_compr:2;
unsigned int assert_action:2;
}; };
/** /**
* parse_standard_option - parse a standard mount option. * ubifs_parse_param - parse a parameter.
* @option: the option to parse * @fc: the filesystem context
* * @param: the parameter to parse
* Normally, standard mount options like "sync" are passed to file-systems as
* flags. However, when a "rootflags=" kernel boot parameter is used, they may
* be present in the options string. This function tries to deal with this
* situation and parse standard options. Returns 0 if the option was not
* recognized, and the corresponding integer flag if it was.
*
* UBIFS is only interested in the "sync" option, so do not check for anything
* else.
*/
static int parse_standard_option(const char *option)
{
pr_notice("UBIFS: parse %s\n", option);
if (!strcmp(option, "sync"))
return SB_SYNCHRONOUS;
return 0;
}
/**
* ubifs_parse_options - parse mount parameters.
* @c: UBIFS file-system description object
* @options: parameters to parse
* @is_remount: non-zero if this is FS re-mount
* *
* This function parses UBIFS mount options and returns zero in case success * This function parses UBIFS mount options and returns zero in case success
* and a negative error code in case of failure. * and a negative error code in case of failure.
*/ */
static int ubifs_parse_options(struct ubifs_info *c, char *options, static int ubifs_parse_param(struct fs_context *fc, struct fs_parameter *param)
int is_remount)
{ {
char *p; struct ubifs_fs_context *ctx = fc->fs_private;
substring_t args[MAX_OPT_ARGS]; struct fs_parse_result result;
bool is_remount = (fc->purpose & FS_CONTEXT_FOR_RECONFIGURE);
int opt;
if (!options) opt = fs_parse(fc, ubifs_fs_param_spec, param, &result);
return 0; if (opt < 0)
return opt;
while ((p = strsep(&options, ","))) { switch (opt) {
int token;
if (!*p)
continue;
token = match_token(p, tokens, args);
switch (token) {
/* /*
* %Opt_fast_unmount and %Opt_norm_unmount options are ignored. * %Opt_fast_unmount and %Opt_norm_unmount options are ignored.
* We accept them in order to be backward-compatible. But this * We accept them in order to be backward-compatible. But this
* should be removed at some point. * should be removed at some point.
*/ */
case Opt_fast_unmount: case Opt_fast_unmount:
c->mount_opts.unmount_mode = 2; ctx->mount_opts.unmount_mode = 2;
break; break;
case Opt_norm_unmount: case Opt_norm_unmount:
c->mount_opts.unmount_mode = 1; ctx->mount_opts.unmount_mode = 1;
break; break;
case Opt_bulk_read: case Opt_bulk_read:
c->mount_opts.bulk_read = 2; ctx->mount_opts.bulk_read = 2;
c->bulk_read = 1; ctx->bulk_read = 1;
break; break;
case Opt_no_bulk_read: case Opt_no_bulk_read:
c->mount_opts.bulk_read = 1; ctx->mount_opts.bulk_read = 1;
c->bulk_read = 0; ctx->bulk_read = 0;
break; break;
case Opt_chk_data_crc: case Opt_chk_data_crc:
c->mount_opts.chk_data_crc = 2; ctx->mount_opts.chk_data_crc = 2;
c->no_chk_data_crc = 0; ctx->no_chk_data_crc = 0;
break; break;
case Opt_no_chk_data_crc: case Opt_no_chk_data_crc:
c->mount_opts.chk_data_crc = 1; ctx->mount_opts.chk_data_crc = 1;
c->no_chk_data_crc = 1; ctx->no_chk_data_crc = 1;
break; break;
case Opt_override_compr: case Opt_override_compr:
{ ctx->mount_opts.compr_type = result.uint_32;
char *name = match_strdup(&args[0]); ctx->mount_opts.override_compr = 1;
ctx->default_compr = ctx->mount_opts.compr_type;
if (!name)
return -ENOMEM;
if (!strcmp(name, "none"))
c->mount_opts.compr_type = UBIFS_COMPR_NONE;
else if (!strcmp(name, "lzo"))
c->mount_opts.compr_type = UBIFS_COMPR_LZO;
else if (!strcmp(name, "zlib"))
c->mount_opts.compr_type = UBIFS_COMPR_ZLIB;
else if (!strcmp(name, "zstd"))
c->mount_opts.compr_type = UBIFS_COMPR_ZSTD;
else {
ubifs_err(c, "unknown compressor \"%s\"", name); //FIXME: is c ready?
kfree(name);
return -EINVAL;
}
kfree(name);
c->mount_opts.override_compr = 1;
c->default_compr = c->mount_opts.compr_type;
break; break;
}
case Opt_assert: case Opt_assert:
{ ctx->assert_action = result.uint_32;
char *act = match_strdup(&args[0]);
if (!act)
return -ENOMEM;
if (!strcmp(act, "report"))
c->assert_action = ASSACT_REPORT;
else if (!strcmp(act, "read-only"))
c->assert_action = ASSACT_RO;
else if (!strcmp(act, "panic"))
c->assert_action = ASSACT_PANIC;
else {
ubifs_err(c, "unknown assert action \"%s\"", act);
kfree(act);
return -EINVAL;
}
kfree(act);
break; break;
}
case Opt_auth_key: case Opt_auth_key:
if (!is_remount) { if (!is_remount) {
c->auth_key_name = kstrdup(args[0].from, kfree(ctx->auth_key_name);
GFP_KERNEL); ctx->auth_key_name = param->string;
if (!c->auth_key_name) param->string = NULL;
return -ENOMEM;
} }
break; break;
case Opt_auth_hash_name: case Opt_auth_hash_name:
if (!is_remount) { if (!is_remount) {
c->auth_hash_name = kstrdup(args[0].from, kfree(ctx->auth_hash_name);
GFP_KERNEL); ctx->auth_hash_name = param->string;
if (!c->auth_hash_name) param->string = NULL;
return -ENOMEM;
} }
break; break;
case Opt_ignore: case Opt_ignore:
break; break;
default:
{
unsigned long flag;
struct super_block *sb = c->vfs_sb;
flag = parse_standard_option(p);
if (!flag) {
ubifs_err(c, "unrecognized mount option \"%s\" or missing value",
p);
return -EINVAL;
}
sb->s_flags |= flag;
break;
}
}
} }
return 0; return 0;
@ -2003,21 +1946,27 @@ static void ubifs_put_super(struct super_block *sb)
mutex_unlock(&c->umount_mutex); mutex_unlock(&c->umount_mutex);
} }
static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data) static int ubifs_reconfigure(struct fs_context *fc)
{ {
struct ubifs_fs_context *ctx = fc->fs_private;
struct super_block *sb = fc->root->d_sb;
int err; int err;
struct ubifs_info *c = sb->s_fs_info; struct ubifs_info *c = sb->s_fs_info;
sync_filesystem(sb); sync_filesystem(sb);
dbg_gen("old flags %#lx, new flags %#x", sb->s_flags, *flags); dbg_gen("old flags %#lx, new flags %#x", sb->s_flags, fc->sb_flags);
err = ubifs_parse_options(c, data, 1); /*
if (err) { * Apply the mount option changes.
ubifs_err(c, "invalid or unknown remount parameter"); * auth_key_name and auth_hash_name are ignored on remount.
return err; */
} c->mount_opts = ctx->mount_opts;
c->bulk_read = ctx->bulk_read;
c->no_chk_data_crc = ctx->no_chk_data_crc;
c->default_compr = ctx->default_compr;
c->assert_action = ctx->assert_action;
if (c->ro_mount && !(*flags & SB_RDONLY)) { if (c->ro_mount && !(fc->sb_flags & SB_RDONLY)) {
if (c->ro_error) { if (c->ro_error) {
ubifs_msg(c, "cannot re-mount R/W due to prior errors"); ubifs_msg(c, "cannot re-mount R/W due to prior errors");
return -EROFS; return -EROFS;
@ -2029,7 +1978,7 @@ static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data)
err = ubifs_remount_rw(c); err = ubifs_remount_rw(c);
if (err) if (err)
return err; return err;
} else if (!c->ro_mount && (*flags & SB_RDONLY)) { } else if (!c->ro_mount && (fc->sb_flags & SB_RDONLY)) {
if (c->ro_error) { if (c->ro_error) {
ubifs_msg(c, "cannot re-mount R/O due to prior errors"); ubifs_msg(c, "cannot re-mount R/O due to prior errors");
return -EROFS; return -EROFS;
@ -2062,14 +2011,13 @@ const struct super_operations ubifs_super_operations = {
.evict_inode = ubifs_evict_inode, .evict_inode = ubifs_evict_inode,
.statfs = ubifs_statfs, .statfs = ubifs_statfs,
.dirty_inode = ubifs_dirty_inode, .dirty_inode = ubifs_dirty_inode,
.remount_fs = ubifs_remount_fs,
.show_options = ubifs_show_options, .show_options = ubifs_show_options,
.sync_fs = ubifs_sync_fs, .sync_fs = ubifs_sync_fs,
}; };
/** /**
* open_ubi - parse UBI device name string and open the UBI device. * open_ubi - parse UBI device name string and open the UBI device.
* @name: UBI volume name * @fc: The filesystem context
* @mode: UBI volume open mode * @mode: UBI volume open mode
* *
* The primary method of mounting UBIFS is by specifying the UBI volume * The primary method of mounting UBIFS is by specifying the UBI volume
@ -2086,15 +2034,13 @@ const struct super_operations ubifs_super_operations = {
* returns UBI volume description object in case of success and a negative * returns UBI volume description object in case of success and a negative
* error code in case of failure. * error code in case of failure.
*/ */
static struct ubi_volume_desc *open_ubi(const char *name, int mode) static struct ubi_volume_desc *open_ubi(struct fs_context *fc, int mode)
{ {
struct ubi_volume_desc *ubi; struct ubi_volume_desc *ubi;
const char *name = fc->source;
int dev, vol; int dev, vol;
char *endptr; char *endptr;
if (!name || !*name)
return ERR_PTR(-EINVAL);
/* First, try to open using the device node path method */ /* First, try to open using the device node path method */
ubi = ubi_open_volume_path(name, mode); ubi = ubi_open_volume_path(name, mode);
if (!IS_ERR(ubi)) if (!IS_ERR(ubi))
@ -2102,14 +2048,14 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
/* Try the "nodev" method */ /* Try the "nodev" method */
if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i') if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
return ERR_PTR(-EINVAL); goto invalid_source;
/* ubi:NAME method */ /* ubi:NAME method */
if ((name[3] == ':' || name[3] == '!') && name[4] != '\0') if ((name[3] == ':' || name[3] == '!') && name[4] != '\0')
return ubi_open_volume_nm(0, name + 4, mode); return ubi_open_volume_nm(0, name + 4, mode);
if (!isdigit(name[3])) if (!isdigit(name[3]))
return ERR_PTR(-EINVAL); goto invalid_source;
dev = simple_strtoul(name + 3, &endptr, 0); dev = simple_strtoul(name + 3, &endptr, 0);
@ -2121,7 +2067,7 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
if (*endptr == '_' && isdigit(endptr[1])) { if (*endptr == '_' && isdigit(endptr[1])) {
vol = simple_strtoul(endptr + 1, &endptr, 0); vol = simple_strtoul(endptr + 1, &endptr, 0);
if (*endptr != '\0') if (*endptr != '\0')
return ERR_PTR(-EINVAL); goto invalid_source;
return ubi_open_volume(dev, vol, mode); return ubi_open_volume(dev, vol, mode);
} }
@ -2129,7 +2075,8 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
if ((*endptr == ':' || *endptr == '!') && endptr[1] != '\0') if ((*endptr == ':' || *endptr == '!') && endptr[1] != '\0')
return ubi_open_volume_nm(dev, ++endptr, mode); return ubi_open_volume_nm(dev, ++endptr, mode);
return ERR_PTR(-EINVAL); invalid_source:
return ERR_PTR(invalf(fc, "Invalid source name"));
} }
static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi) static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi)
@ -2181,9 +2128,10 @@ static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi)
return c; return c;
} }
static int ubifs_fill_super(struct super_block *sb, void *data, int silent) static int ubifs_fill_super(struct super_block *sb, struct fs_context *fc)
{ {
struct ubifs_info *c = sb->s_fs_info; struct ubifs_info *c = sb->s_fs_info;
struct ubifs_fs_context *ctx = fc->fs_private;
struct inode *root; struct inode *root;
int err; int err;
@ -2195,9 +2143,18 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
goto out; goto out;
} }
err = ubifs_parse_options(c, data, 0); /* Copy in parsed mount options */
if (err) c->mount_opts = ctx->mount_opts;
goto out_close; c->auth_key_name = ctx->auth_key_name;
c->auth_hash_name = ctx->auth_hash_name;
c->no_chk_data_crc = ctx->no_chk_data_crc;
c->bulk_read = ctx->bulk_read;
c->default_compr = ctx->default_compr;
c->assert_action = ctx->assert_action;
/* ubifs_info owns auth strings now */
ctx->auth_key_name = NULL;
ctx->auth_hash_name = NULL;
/* /*
* UBIFS provides 'backing_dev_info' in order to disable read-ahead. For * UBIFS provides 'backing_dev_info' in order to disable read-ahead. For
@ -2264,41 +2221,38 @@ out:
return err; return err;
} }
static int sb_test(struct super_block *sb, void *data) static int sb_test(struct super_block *sb, struct fs_context *fc)
{ {
struct ubifs_info *c1 = data; struct ubifs_info *c1 = fc->s_fs_info;
struct ubifs_info *c = sb->s_fs_info; struct ubifs_info *c = sb->s_fs_info;
return c->vi.cdev == c1->vi.cdev; return c->vi.cdev == c1->vi.cdev;
} }
static int sb_set(struct super_block *sb, void *data) static int ubifs_get_tree(struct fs_context *fc)
{
sb->s_fs_info = data;
return set_anon_super(sb, NULL);
}
static struct dentry *ubifs_mount(struct file_system_type *fs_type, int flags,
const char *name, void *data)
{ {
struct ubi_volume_desc *ubi; struct ubi_volume_desc *ubi;
struct ubifs_info *c; struct ubifs_info *c;
struct super_block *sb; struct super_block *sb;
int err; int err;
dbg_gen("name %s, flags %#x", name, flags); if (!fc->source || !*fc->source)
return invalf(fc, "No source specified");
dbg_gen("name %s, flags %#x", fc->source, fc->sb_flags);
/* /*
* Get UBI device number and volume ID. Mount it read-only so far * Get UBI device number and volume ID. Mount it read-only so far
* because this might be a new mount point, and UBI allows only one * because this might be a new mount point, and UBI allows only one
* read-write user at a time. * read-write user at a time.
*/ */
ubi = open_ubi(name, UBI_READONLY); ubi = open_ubi(fc, UBI_READONLY);
if (IS_ERR(ubi)) { if (IS_ERR(ubi)) {
if (!(flags & SB_SILENT)) err = PTR_ERR(ubi);
if (!(fc->sb_flags & SB_SILENT))
pr_err("UBIFS error (pid: %d): cannot open \"%s\", error %d", pr_err("UBIFS error (pid: %d): cannot open \"%s\", error %d",
current->pid, name, (int)PTR_ERR(ubi)); current->pid, fc->source, err);
return ERR_CAST(ubi); return err;
} }
c = alloc_ubifs_info(ubi); c = alloc_ubifs_info(ubi);
@ -2306,10 +2260,11 @@ static struct dentry *ubifs_mount(struct file_system_type *fs_type, int flags,
err = -ENOMEM; err = -ENOMEM;
goto out_close; goto out_close;
} }
fc->s_fs_info = c;
dbg_gen("opened ubi%d_%d", c->vi.ubi_num, c->vi.vol_id); dbg_gen("opened ubi%d_%d", c->vi.ubi_num, c->vi.vol_id);
sb = sget(fs_type, sb_test, sb_set, flags, c); sb = sget_fc(fc, sb_test, set_anon_super_fc);
if (IS_ERR(sb)) { if (IS_ERR(sb)) {
err = PTR_ERR(sb); err = PTR_ERR(sb);
kfree(c); kfree(c);
@ -2321,12 +2276,12 @@ static struct dentry *ubifs_mount(struct file_system_type *fs_type, int flags,
kfree(c); kfree(c);
/* A new mount point for already mounted UBIFS */ /* A new mount point for already mounted UBIFS */
dbg_gen("this ubi volume is already mounted"); dbg_gen("this ubi volume is already mounted");
if (!!(flags & SB_RDONLY) != c1->ro_mount) { if (!!(fc->sb_flags & SB_RDONLY) != c1->ro_mount) {
err = -EBUSY; err = -EBUSY;
goto out_deact; goto out_deact;
} }
} else { } else {
err = ubifs_fill_super(sb, data, flags & SB_SILENT ? 1 : 0); err = ubifs_fill_super(sb, fc);
if (err) if (err)
goto out_deact; goto out_deact;
/* We do not support atime */ /* We do not support atime */
@ -2340,13 +2295,14 @@ static struct dentry *ubifs_mount(struct file_system_type *fs_type, int flags,
/* 'fill_super()' opens ubi again so we must close it here */ /* 'fill_super()' opens ubi again so we must close it here */
ubi_close_volume(ubi); ubi_close_volume(ubi);
return dget(sb->s_root); fc->root = dget(sb->s_root);
return 0;
out_deact: out_deact:
deactivate_locked_super(sb); deactivate_locked_super(sb);
out_close: out_close:
ubi_close_volume(ubi); ubi_close_volume(ubi);
return ERR_PTR(err); return err;
} }
static void kill_ubifs_super(struct super_block *s) static void kill_ubifs_super(struct super_block *s)
@ -2356,10 +2312,61 @@ static void kill_ubifs_super(struct super_block *s)
kfree(c); kfree(c);
} }
static void ubifs_free_fc(struct fs_context *fc)
{
struct ubifs_fs_context *ctx = fc->fs_private;
if (ctx) {
kfree(ctx->auth_key_name);
kfree(ctx->auth_hash_name);
kfree(ctx);
}
}
static const struct fs_context_operations ubifs_context_ops = {
.free = ubifs_free_fc,
.parse_param = ubifs_parse_param,
.get_tree = ubifs_get_tree,
.reconfigure = ubifs_reconfigure,
};
static int ubifs_init_fs_context(struct fs_context *fc)
{
struct ubifs_fs_context *ctx;
ctx = kzalloc(sizeof(struct ubifs_fs_context), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
if (fc->purpose != FS_CONTEXT_FOR_RECONFIGURE) {
/* Iniitialize for first mount */
ctx->no_chk_data_crc = 1;
ctx->assert_action = ASSACT_RO;
} else {
struct ubifs_info *c = fc->root->d_sb->s_fs_info;
/*
* Preserve existing options across remounts.
* auth_key_name and auth_hash_name are not remountable.
*/
ctx->mount_opts = c->mount_opts;
ctx->bulk_read = c->bulk_read;
ctx->no_chk_data_crc = c->no_chk_data_crc;
ctx->default_compr = c->default_compr;
ctx->assert_action = c->assert_action;
}
fc->ops = &ubifs_context_ops;
fc->fs_private = ctx;
return 0;
}
static struct file_system_type ubifs_fs_type = { static struct file_system_type ubifs_fs_type = {
.name = "ubifs", .name = "ubifs",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.mount = ubifs_mount, .init_fs_context = ubifs_init_fs_context,
.parameters = ubifs_fs_param_spec,
.kill_sb = kill_ubifs_super, .kill_sb = kill_ubifs_super,
}; };
MODULE_ALIAS_FS("ubifs"); MODULE_ALIAS_FS("ubifs");