Skip to contentSkip to conversation

fat: convert to the new mount API

PATCH Superseded Eric Sandeen 3 participants 9 messages Jun 29, 2024 – Jul 2, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover fat: convert to the new mount API

This short series converts the fat/vfat/msdos filesystem to use the new mount API.

I've tested it with a hacky shell script found at

https://gist.github.com/sandeen/3492a39c3f2bf16d1ccdd2cd1c681ccd

which tries every possible option, including some with invalid values, on both vfat and msdos mounts. It then tests random combinations of 2, 3, and 4 options, including possibly invalid options.

I captured stdout from two runs with and without these modifications, and the results are identical.

As patch 2 notes, I left codepage loading to fill_super(), rather than validating codepage options as they are parsed. This is because i.e.

mount -o "iocharset=nope,iocharset=iso8859-1"

passes today, due to the last iocharset option being the only one that is loaded. It might be nice to validate such options as they are parsed, but doing so would make the above command line fail, so I'm not sure if it's a good idea. I do have a patch to validate as we parse, if that's desired.

Lastly, this does not yet use the proposed uid/gid parsing helpers, since that is not yet merged.

Thanks,
-Eric

#1 lore raw

PATCH 1/2 fat: move debug into fat_mount_options

Move the debug variable into fat_mount_options for consistency and to facilitate conversion to the new mount API.

---
 fs/fat/fat.h   | 3 ++-
 fs/fat/inode.c | 9 ++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)
fs/fat/fat.h +2 -1
index 66cf4778cf3b..37ced7bb06d5 100644
@@ -51,7 +51,8 @@ struct fat_mount_options {
 		 tz_set:1,	   /* Filesystem timestamps' offset set */
 		 rodir:1,	   /* allow ATTR_RO for directory */
 		 discard:1,	   /* Issue discard requests on deletions */
-		 dos1xfloppy:1;	   /* Assume default BPB for DOS 1.x floppies */
+		 dos1xfloppy:1,	   /* Assume default BPB for DOS 1.x floppies */
+		 debug:1;	   /* Not currently used */
 };
 
 #define FAT_HASH_BITS	8
fs/fat/inode.c +4 -5
index d9e6fbb6f246..2a6537ba0d49 100644
@@ -1132,7 +1132,7 @@ static const match_table_t vfat_tokens = {
 };
 
 static int parse_options(struct super_block *sb, char *options, int is_vfat,
-			 int silent, int *debug, struct fat_mount_options *opts)
+			 int silent, struct fat_mount_options *opts)
 {
 	char *p;
 	substring_t args[MAX_OPT_ARGS];
@@ -1162,7 +1162,7 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat,
 	opts->tz_set = 0;
 	opts->nfs = 0;
 	opts->errors = FAT_ERRORS_RO;
-	*debug = 0;
+	opts->debug = 0;
 
 	opts->utf8 = IS_ENABLED(CONFIG_FAT_DEFAULT_UTF8) && is_vfat;
 
@@ -1210,7 +1210,7 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat,
 			opts->showexec = 1;
 			break;
 		case Opt_debug:
-			*debug = 1;
+			opts->debug = 1;
 			break;
 		case Opt_immutable:
 			opts->sys_immutable = 1;
@@ -1614,7 +1614,6 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
 	struct msdos_sb_info *sbi;
 	u16 logical_sector_size;
 	u32 total_sectors, total_clusters, fat_clusters, rootdir_sectors;
-	int debug;
 	long error;
 	char buf[50];
 	struct timespec64 ts;
@@ -1643,7 +1642,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
 	ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
 			     DEFAULT_RATELIMIT_BURST);
 
-	error = parse_options(sb, data, isvfat, silent, &debug, &sbi->options);
+	error = parse_options(sb, data, isvfat, silent, &sbi->options);
 	if (error)
 		goto out_fail;
 
Signature · 1 line
2.45.2
#2 lore raw

PATCH 2/2 fat: Convert to new mount api

In reply to Eric Sandeen

vfat and msdos share a common set of options, with additional unique options for each filesystem.

Each filesystem calls common fc initializization and parsing routines, with an "is_vfat" parameter. For parsing, if the option is not found in the common parameter_spec, parsing is retried with the fs-specific parameter_spec.

This patch leaves nls loading to fill_super, so the codepage and charset options are not validated as they are requested. This matches current behavior. It would be possible to test-load as each option is parsed, but that would make i.e.

mount -o "iocharset=nope,iocharset=iso8859-1"

fail, where it does not fail today because only the last iocharset option is considered.

The obsolete "conv=" option is set up with an enum of acceptable values; currently invalid "conv=" options are rejected as such, even though the option is obsolete, so this patch preserves that behavior.

---
 fs/fat/fat.h         |  15 +-
 fs/fat/inode.c       | 680 +++++++++++++++++++++----------------------
 fs/fat/namei_msdos.c |  38 ++-
 fs/fat/namei_vfat.c  |  38 ++-
 4 files changed, 413 insertions(+), 358 deletions(-)
fs/fat/fat.h +13 -2
index 37ced7bb06d5..fe41584ecaf3 100644
@@ -7,6 +7,8 @@
 #include <linux/hash.h>
 #include <linux/ratelimit.h>
 #include <linux/msdos_fs.h>
+#include <linux/fs_context.h>
+#include <linux/fs_parser.h>
 
 /*
  * vfat shortname flags
@@ -416,12 +418,21 @@ extern struct inode *fat_iget(struct super_block *sb, loff_t i_pos);
 extern struct inode *fat_build_inode(struct super_block *sb,
 			struct msdos_dir_entry *de, loff_t i_pos);
 extern int fat_sync_inode(struct inode *inode);
-extern int fat_fill_super(struct super_block *sb, void *data, int silent,
-			  int isvfat, void (*setup)(struct super_block *));
+extern int fat_fill_super(struct super_block *sb, struct fs_context *fc,
+			  void (*setup)(struct super_block *));
 extern int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de);
 
 extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,
 			    struct inode *i2);
+
+extern const struct fs_parameter_spec fat_param_spec[];
+extern int fat_init_fs_context(struct fs_context *fc, bool is_vfat);
+extern void fat_free_fc(struct fs_context *fc);
+
+int fat_parse_param(struct fs_context *fc, struct fs_parameter *param,
+		    int is_vfat);
+extern int fat_reconfigure(struct fs_context *fc);
+
 static inline unsigned long fat_dir_hash(int logstart)
 {
 	return hash_32(logstart, FAT_HASH_BITS);
fs/fat/inode.c +338 -342

772 lines not on this page · raw message

fs/fat/namei_msdos.c +31 -7
index 2116c486843b..b7f462fb9a40 100644
@@ -650,24 +650,48 @@ static void setup(struct super_block *sb)
 	sb->s_flags |= SB_NOATIME;
 }
 
-static int msdos_fill_super(struct super_block *sb, void *data, int silent)
+static int msdos_fill_super(struct super_block *sb, struct fs_context *fc)
 {
-	return fat_fill_super(sb, data, silent, 0, setup);
+	return fat_fill_super(sb, fc, setup);
 }
 
-static struct dentry *msdos_mount(struct file_system_type *fs_type,
-			int flags, const char *dev_name,
-			void *data)
+static int msdos_get_tree(struct fs_context *fc)
 {
-	return mount_bdev(fs_type, flags, dev_name, data, msdos_fill_super);
+	return get_tree_bdev(fc, msdos_fill_super);
+}
+
+static int msdos_parse_param(struct fs_context *fc, struct fs_parameter *param)
+{
+	return fat_parse_param(fc, param, 0);
+}
+
+static const struct fs_context_operations msdos_context_ops = {
+	.parse_param	= msdos_parse_param,
+	.get_tree	= msdos_get_tree,
+	.reconfigure	= fat_reconfigure,
+	.free		= fat_free_fc,
+};
+
+static int msdos_init_fs_context(struct fs_context *fc)
+{
+	int err;
+
+	/* Initialize with isvfat == 0 */
+	err = fat_init_fs_context(fc, 0);
+	if (err)
+		return err;
+
+	fc->ops = &msdos_context_ops;
+	return 0;
 }
 
 static struct file_system_type msdos_fs_type = {
 	.owner		= THIS_MODULE,
 	.name		= "msdos",
-	.mount		= msdos_mount,
 	.kill_sb	= kill_block_super,
 	.fs_flags	= FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
+	.init_fs_context = msdos_init_fs_context,
+	.parameters	= fat_param_spec,
 };
 MODULE_ALIAS_FS("msdos");
 
fs/fat/namei_vfat.c +31 -7
index c4d00999a433..8f1913dd0c83 100644
@@ -1195,24 +1195,48 @@ static void setup(struct super_block *sb)
 		sb->s_d_op = &vfat_dentry_ops;
 }
 
-static int vfat_fill_super(struct super_block *sb, void *data, int silent)
+static int vfat_fill_super(struct super_block *sb, struct fs_context *fc)
 {
-	return fat_fill_super(sb, data, silent, 1, setup);
+	return fat_fill_super(sb, fc, setup);
 }
 
-static struct dentry *vfat_mount(struct file_system_type *fs_type,
-		       int flags, const char *dev_name,
-		       void *data)
+static int vfat_get_tree(struct fs_context *fc)
 {
-	return mount_bdev(fs_type, flags, dev_name, data, vfat_fill_super);
+	return get_tree_bdev(fc, vfat_fill_super);
+}
+
+static int vfat_parse_param(struct fs_context *fc, struct fs_parameter *param)
+{
+	return fat_parse_param(fc, param, 1);
+}
+
+static const struct fs_context_operations vfat_context_ops = {
+	.parse_param	= vfat_parse_param,
+	.get_tree	= vfat_get_tree,
+	.reconfigure	= fat_reconfigure,
+	.free		= fat_free_fc,
+};
+
+static int vfat_init_fs_context(struct fs_context *fc)
+{
+	int err;
+
+	/* Initialize with isvfat == 1 */
+	err = fat_init_fs_context(fc, 1);
+	if (err)
+		return err;
+
+	fc->ops = &vfat_context_ops;
+	return 0;
 }
 
 static struct file_system_type vfat_fs_type = {
 	.owner		= THIS_MODULE,
 	.name		= "vfat",
-	.mount		= vfat_mount,
 	.kill_sb	= kill_block_super,
 	.fs_flags	= FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
+	.init_fs_context = vfat_init_fs_context,
+	.parameters     = fat_param_spec,
 };
 MODULE_ALIAS_FS("vfat");
 
Signature · 1 line
2.45.2
#3 lore raw

PATCH v2 2/2 fat: Convert to new mount api

vfat and msdos share a common set of options, with additional, unique options for each filesystem.

Each filesystem calls common fc initializization and parsing routines, with an "is_vfat" parameter. For parsing, if the option is not found in the common parameter_spec, parsing is retried with the fs-specific parameter_spec.

This patch leaves nls loading to fill_super, so the codepage and charset options are not validated as they are requested. This matches current behavior. It would be possible to test-load as each option is parsed, but that would make i.e.

mount -o "iocharset=nope,iocharset=iso8859-1"

fail, where it does not fail today because only the last iocharset option is considered.

The obsolete "conv=" option is set up with an enum of acceptable values; currently invalid "conv=" options are rejected as such, even though the option is obsolete, so this patch preserves that behavior.

---

V2: Ignore all options during remount via

	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE)
		return 0;
 fs/fat/fat.h         |  15 +-
 fs/fat/inode.c       | 682 +++++++++++++++++++++----------------------
 fs/fat/namei_msdos.c |  38 ++-
 fs/fat/namei_vfat.c  |  38 ++-
 4 files changed, 416 insertions(+), 357 deletions(-)
fs/fat/fat.h +13 -2
index 37ced7bb06d5..fe41584ecaf3 100644
@@ -7,6 +7,8 @@
 #include <linux/hash.h>
 #include <linux/ratelimit.h>
 #include <linux/msdos_fs.h>
+#include <linux/fs_context.h>
+#include <linux/fs_parser.h>
 
 /*
  * vfat shortname flags
@@ -416,12 +418,21 @@ extern struct inode *fat_iget(struct super_block *sb, loff_t i_pos);
 extern struct inode *fat_build_inode(struct super_block *sb,
 			struct msdos_dir_entry *de, loff_t i_pos);
 extern int fat_sync_inode(struct inode *inode);
-extern int fat_fill_super(struct super_block *sb, void *data, int silent,
-			  int isvfat, void (*setup)(struct super_block *));
+extern int fat_fill_super(struct super_block *sb, struct fs_context *fc,
+			  void (*setup)(struct super_block *));
 extern int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de);
 
 extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,
 			    struct inode *i2);
+
+extern const struct fs_parameter_spec fat_param_spec[];
+extern int fat_init_fs_context(struct fs_context *fc, bool is_vfat);
+extern void fat_free_fc(struct fs_context *fc);
+
+int fat_parse_param(struct fs_context *fc, struct fs_parameter *param,
+		    int is_vfat);
+extern int fat_reconfigure(struct fs_context *fc);
+
 static inline unsigned long fat_dir_hash(int logstart)
 {
 	return hash_32(logstart, FAT_HASH_BITS);
fs/fat/inode.c +341 -341

775 lines not on this page · raw message

fs/fat/namei_msdos.c +31 -7
index 2116c486843b..b7f462fb9a40 100644
@@ -650,24 +650,48 @@ static void setup(struct super_block *sb)
 	sb->s_flags |= SB_NOATIME;
 }
 
-static int msdos_fill_super(struct super_block *sb, void *data, int silent)
+static int msdos_fill_super(struct super_block *sb, struct fs_context *fc)
 {
-	return fat_fill_super(sb, data, silent, 0, setup);
+	return fat_fill_super(sb, fc, setup);
 }
 
-static struct dentry *msdos_mount(struct file_system_type *fs_type,
-			int flags, const char *dev_name,
-			void *data)
+static int msdos_get_tree(struct fs_context *fc)
 {
-	return mount_bdev(fs_type, flags, dev_name, data, msdos_fill_super);
+	return get_tree_bdev(fc, msdos_fill_super);
+}
+
+static int msdos_parse_param(struct fs_context *fc, struct fs_parameter *param)
+{
+	return fat_parse_param(fc, param, 0);
+}
+
+static const struct fs_context_operations msdos_context_ops = {
+	.parse_param	= msdos_parse_param,
+	.get_tree	= msdos_get_tree,
+	.reconfigure	= fat_reconfigure,
+	.free		= fat_free_fc,
+};
+
+static int msdos_init_fs_context(struct fs_context *fc)
+{
+	int err;
+
+	/* Initialize with isvfat == 0 */
+	err = fat_init_fs_context(fc, 0);
+	if (err)
+		return err;
+
+	fc->ops = &msdos_context_ops;
+	return 0;
 }
 
 static struct file_system_type msdos_fs_type = {
 	.owner		= THIS_MODULE,
 	.name		= "msdos",
-	.mount		= msdos_mount,
 	.kill_sb	= kill_block_super,
 	.fs_flags	= FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
+	.init_fs_context = msdos_init_fs_context,
+	.parameters	= fat_param_spec,
 };
 MODULE_ALIAS_FS("msdos");
 
fs/fat/namei_vfat.c +31 -7
index c4d00999a433..8f1913dd0c83 100644
@@ -1195,24 +1195,48 @@ static void setup(struct super_block *sb)
 		sb->s_d_op = &vfat_dentry_ops;
 }
 
-static int vfat_fill_super(struct super_block *sb, void *data, int silent)
+static int vfat_fill_super(struct super_block *sb, struct fs_context *fc)
 {
-	return fat_fill_super(sb, data, silent, 1, setup);
+	return fat_fill_super(sb, fc, setup);
 }
 
-static struct dentry *vfat_mount(struct file_system_type *fs_type,
-		       int flags, const char *dev_name,
-		       void *data)
+static int vfat_get_tree(struct fs_context *fc)
 {
-	return mount_bdev(fs_type, flags, dev_name, data, vfat_fill_super);
+	return get_tree_bdev(fc, vfat_fill_super);
+}
+
+static int vfat_parse_param(struct fs_context *fc, struct fs_parameter *param)
+{
+	return fat_parse_param(fc, param, 1);
+}
+
+static const struct fs_context_operations vfat_context_ops = {
+	.parse_param	= vfat_parse_param,
+	.get_tree	= vfat_get_tree,
+	.reconfigure	= fat_reconfigure,
+	.free		= fat_free_fc,
+};
+
+static int vfat_init_fs_context(struct fs_context *fc)
+{
+	int err;
+
+	/* Initialize with isvfat == 1 */
+	err = fat_init_fs_context(fc, 1);
+	if (err)
+		return err;
+
+	fc->ops = &vfat_context_ops;
+	return 0;
 }
 
 static struct file_system_type vfat_fs_type = {
 	.owner		= THIS_MODULE,
 	.name		= "vfat",
-	.mount		= vfat_mount,
 	.kill_sb	= kill_block_super,
 	.fs_flags	= FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
+	.init_fs_context = vfat_init_fs_context,
+	.parameters     = fat_param_spec,
 };
 MODULE_ALIAS_FS("vfat");
 
Signature · 1 line
2.45.2
maintainer
#4 lore raw

Re: [PATCH 2/2 V2] fat: Convert to new mount api

Eric Sandeen <[email protected]> writes:

[...]

Quoted 7 lines

---

V2: Ignore all options during remount via

	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE)
		return 0;

Thanks, basically looks good. However I tested a bit and found a bug, and small comments.

fs/fat/fat.h extern struct inode *fat_iget(struct super_block *sb, loff_t i_pos); · line 434

Quoted 7 lines
fs/fat/fat.h +7 -0
+extern const struct fs_parameter_spec fat_param_spec[];
+extern int fat_init_fs_context(struct fs_context *fc, bool is_vfat);
+extern void fat_free_fc(struct fs_context *fc);
+
+int fat_parse_param(struct fs_context *fc, struct fs_parameter *param,
+		    int is_vfat);
+extern int fat_reconfigure(struct fs_context *fc);

Let's remove extern from new one.

fs/fat/inode.c static int fat_show_options(struct seq_file *m, struct dentry *root) · line 1153

Quoted 2 lines
fs/fat/inode.c +2 -0
+int fat_parse_param(struct fs_context *fc, struct fs_parameter *param,
+			   int is_vfat)

Maybe better to use bool (and true/false) instead of int for is_vfat?

Quoted 5 lines
fs/fat/inode.c +5 -0
+{
+	struct fat_mount_options *opts = fc->fs_private;
+	struct fs_parse_result result;
+	int opt;
+	char buf[50];

[...]

fs/fat/inode.c static int fat_show_options(struct seq_file *m, struct dentry *root) · line 1231

Quoted 2 lines
fs/fat/inode.c +2 -0
+	case Opt_codepage:
+		sprintf(buf, "cp%d", result.uint_32);

"buf" is unused.

fs/fat/inode.c static int fat_show_options(struct seq_file *m, struct dentry *root) · line 1311

Quoted 5 lines
fs/fat/inode.c +5 -0
+	/* obsolete mount options */
+	case Opt_obsolete:
+		infof(fc, "\"%s\" option is obsolete, not supported now",
+		      param->key);
+		break;

I'm not sure though, "Opt_obsolete" should use fs_param_deprecated?

fs/fat/inode.c static int fat_show_options(struct seq_file *m, struct dentry *root) · line 1313

Quoted 2 lines
fs/fat/inode.c +2 -0
+	default:
+		return -EINVAL;

I'm not sure though, "default:" should not happen anymore?

Quoted 5 lines
fs/fat/inode.c +1 -0
 	}
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(fat_parse_param);

[...]

fs/fat/inode.c int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, · line 1590

Quoted 5 lines
fs/fat/inode.c +5 -0
+	/* If user doesn't specify allow_utime, it's initialized from dmask. */
+	if (opts->allow_utime == (unsigned short)-1)
+		opts->allow_utime = ~opts->fs_dmask & (S_IWGRP | S_IWOTH);
+	if (opts->unicode_xlate)
+		opts->utf8 = 0;

Probably, this should move to fat_parse_param()?

fs/fat/inode.c int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, · line 1597

Quoted 2 lines
fs/fat/inode.c +2 -0
+	/* Apply pparsed options to sbi */
+	sbi->options = *opts;
	/* Transfer ownership of iocharset to sbi->options */
	opts->iocharset = NULL;
	opts = &sbi->options;

opts->iocharset is freed by both of opts and sbi->options, we should fix it like above or such.

Quoted 2 lines
fs/fat/inode.c +1 -1
-	sprintf(buf, "cp%d", sbi->options.codepage);
+	sprintf(buf, "cp%d", opts->codepage);

[...]

fs/fat/inode.c int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, · line 1796

Quoted 9 lines
fs/fat/inode.c +2 -2
 	/* FIXME: utf8 is using iocharset for upper/lower conversion */
 	if (sbi->options.isvfat) {
-		sbi->nls_io = load_nls(sbi->options.iocharset);
+		sbi->nls_io = load_nls(opts->iocharset);
 		if (!sbi->nls_io) {
 			fat_msg(sb, KERN_ERR, "IO charset %s not found",
-			       sbi->options.iocharset);
+			       opts->iocharset);
 			goto out_fail;

Revert above to remove opts usage to not touch after ownership transfer if we fix the bug like that way.

fs/fat/namei_msdos.c static void setup(struct super_block *sb) · line 665

Quoted 3 lines
fs/fat/namei_msdos.c +3 -0
+static int msdos_parse_param(struct fs_context *fc, struct fs_parameter *param)
+{
+	return fat_parse_param(fc, param, 0);

If we changed int to bool, 0 to false.

fs/fat/namei_msdos.c static void setup(struct super_block *sb) · line 680

Quoted 6 lines
fs/fat/namei_msdos.c +6 -0
+static int msdos_init_fs_context(struct fs_context *fc)
+{
+	int err;
+
+	/* Initialize with isvfat == 0 */
+	err = fat_init_fs_context(fc, 0);

If we changed int to bool, 0 to false.

fs/fat/namei_vfat.c static void setup(struct super_block *sb) · line 1210

Quoted 3 lines
fs/fat/namei_vfat.c +3 -0
+static int vfat_parse_param(struct fs_context *fc, struct fs_parameter *param)
+{
+	return fat_parse_param(fc, param, 1);

If we changed int to bool, 0 to true.

fs/fat/namei_vfat.c static void setup(struct super_block *sb) · line 1225

Quoted 6 lines
fs/fat/namei_vfat.c +6 -0
+static int vfat_init_fs_context(struct fs_context *fc)
+{
+	int err;
+
+	/* Initialize with isvfat == 1 */
+	err = fat_init_fs_context(fc, 1);

If we changed int to bool, 0 to true.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#5 lore raw

Re: [PATCH 2/2 V2] fat: Convert to new mount api

Quoted 7 lines · OGAWA Hirofumi

Eric Sandeen <[email protected]> writes:

[...]

Quoted 3 lines

---

Quoted 7 lines
Quoted 4 lines

V2: Ignore all options during remount via

	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE)
		return 0;

Thanks, basically looks good. However I tested a bit and found a bug, and small comments.

Thanks!

Quoted 9 lines

fs/fat/fat.h extern struct inode *fat_iget(struct super_block *sb, loff_t i_pos); · line 434

Quoted 7 lines
fs/fat/fat.h +7 -0
+extern const struct fs_parameter_spec fat_param_spec[];
+extern int fat_init_fs_context(struct fs_context *fc, bool is_vfat);
+extern void fat_free_fc(struct fs_context *fc);
+
+int fat_parse_param(struct fs_context *fc, struct fs_parameter *param,
+		    int is_vfat);
+extern int fat_reconfigure(struct fs_context *fc);

Let's remove extern from new one.

ok

Quoted 4 lines

fs/fat/inode.c static int fat_show_options(struct seq_file *m, struct dentry *root) · line 1153

Quoted 2 lines
fs/fat/inode.c +2 -0
+int fat_parse_param(struct fs_context *fc, struct fs_parameter *param,
+			   int is_vfat)

Maybe better to use bool (and true/false) instead of int for is_vfat?

Ok - I think I just followed the lead of the ints in parse_options() today but bool does make more sense.

Quoted 8 lines
Quoted 5 lines
fs/fat/inode.c +5 -0
+{
+	struct fat_mount_options *opts = fc->fs_private;
+	struct fs_parse_result result;
+	int opt;
+	char buf[50];

[...]

Quoted 4 lines

fs/fat/inode.c static int fat_show_options(struct seq_file *m, struct dentry *root) · line 1231

Quoted 2 lines
fs/fat/inode.c +2 -0
+	case Opt_codepage:
+		sprintf(buf, "cp%d", result.uint_32);

"buf" is unused.

whoops, you are right. thanks.

Quoted 7 lines

fs/fat/inode.c static int fat_show_options(struct seq_file *m, struct dentry *root) · line 1311

Quoted 5 lines
fs/fat/inode.c +5 -0
+	/* obsolete mount options */
+	case Opt_obsolete:
+		infof(fc, "\"%s\" option is obsolete, not supported now",
+		      param->key);
+		break;

I'm not sure though, "Opt_obsolete" should use fs_param_deprecated?

Ah, that's probably smart. And I will switch this back to fat_msg() so that it's logged in dmesg as it was before.

Quoted 4 lines

fs/fat/inode.c static int fat_show_options(struct seq_file *m, struct dentry *root) · line 1313

Quoted 2 lines
fs/fat/inode.c +2 -0
+	default:
+		return -EINVAL;

I'm not sure though, "default:" should not happen anymore?

That's right. However, even conversions done by dhowells (for example ec10a24f10c8 vfs: Convert jffs2 to use the new mount API) retain the
default: case. Happy to do this however you like, though keeping the default:
seems reasonably defensive?

Quoted 8 lines
Quoted 5 lines
fs/fat/inode.c +1 -0
 	}
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(fat_parse_param);

[...]

Quoted 7 lines

fs/fat/inode.c int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, · line 1590

Quoted 5 lines
fs/fat/inode.c +5 -0
+	/* If user doesn't specify allow_utime, it's initialized from dmask. */
+	if (opts->allow_utime == (unsigned short)-1)
+		opts->allow_utime = ~opts->fs_dmask & (S_IWGRP | S_IWOTH);
+	if (opts->unicode_xlate)
+		opts->utf8 = 0;

Probably, this should move to fat_parse_param()?

In my conversions, I have treated parse_param as simply handling one option at a time, and not dealing with combinations, because we don't have the "full view" of all options until we are done (previously we parsed everything, and then could "clean up" at the bottom of the function). So now, I was handling this sort of checking after parsing was complete, and fill_super seemed an OK place to do it.

But sure - I will look at whether doing it in fat_parse_param makes sense.

Quoted 1 line

fs/fat/inode.c int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, · line 1596

Quoted 1 line
fs/fat/inode.c +1 -0
+	/* Apply pparsed options to sbi */

<typo here too>

Quoted 8 lines

fs/fat/inode.c int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, · line 1597

Quoted 1 line
fs/fat/inode.c +1 -0
+	sbi->options = *opts;
	/* Transfer ownership of iocharset to sbi->options */
	opts->iocharset = NULL;
	opts = &sbi->options;

opts->iocharset is freed by both of opts and sbi->options, we should fix it like above or such.

Ah, good catch.

Quoted 5 lines
Quoted 2 lines
fs/fat/inode.c +1 -1
-	sprintf(buf, "cp%d", sbi->options.codepage);
+	sprintf(buf, "cp%d", opts->codepage);

[...]

Quoted 12 lines

fs/fat/inode.c int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, · line 1796

Quoted 9 lines
fs/fat/inode.c +2 -2
 	/* FIXME: utf8 is using iocharset for upper/lower conversion */
 	if (sbi->options.isvfat) {
-		sbi->nls_io = load_nls(sbi->options.iocharset);
+		sbi->nls_io = load_nls(opts->iocharset);
 		if (!sbi->nls_io) {
 			fat_msg(sb, KERN_ERR, "IO charset %s not found",
-			       sbi->options.iocharset);
+			       opts->iocharset);
 			goto out_fail;

Revert above to remove opts usage to not touch after ownership transfer if we fix the bug like that way.

ok

Quoted 5 lines

fs/fat/namei_msdos.c static void setup(struct super_block *sb) · line 665

Quoted 3 lines
fs/fat/namei_msdos.c +3 -0
+static int msdos_parse_param(struct fs_context *fc, struct fs_parameter *param)
+{
+	return fat_parse_param(fc, param, 0);

If we changed int to bool, 0 to false.

*nod*

Quoted 8 lines

fs/fat/namei_msdos.c static void setup(struct super_block *sb) · line 680

Quoted 6 lines
fs/fat/namei_msdos.c +6 -0
+static int msdos_init_fs_context(struct fs_context *fc)
+{
+	int err;
+
+	/* Initialize with isvfat == 0 */
+	err = fat_init_fs_context(fc, 0);

If we changed int to bool, 0 to false.

*nod*

Quoted 5 lines

fs/fat/namei_vfat.c static void setup(struct super_block *sb) · line 1210

Quoted 3 lines
fs/fat/namei_vfat.c +3 -0
+static int vfat_parse_param(struct fs_context *fc, struct fs_parameter *param)
+{
+	return fat_parse_param(fc, param, 1);

If we changed int to bool, 0 to true.

*nod*

Quoted 8 lines

fs/fat/namei_vfat.c static void setup(struct super_block *sb) · line 1225

Quoted 6 lines
fs/fat/namei_vfat.c +6 -0
+static int vfat_init_fs_context(struct fs_context *fc)
+{
+	int err;
+
+	/* Initialize with isvfat == 1 */
+	err = fat_init_fs_context(fc, 1);

If we changed int to bool, 0 to true.

*nod* :)

Thanks for the review, and sorry for the errors.

-Eric

Quoted 1 line

Thanks.

#6 lore raw

Re: [PATCH 2/2 V2] fat: Convert to new mount api

Quoted 2 lines · Eric Sandeen
Quoted 1 line · OGAWA Hirofumi

Eric Sandeen <[email protected]> writes:

[...]

Quoted 10 lines
Quoted 9 lines

[...]

fs/fat/inode.c int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, · line 1590

Quoted 5 lines
fs/fat/inode.c +5 -0
+	/* If user doesn't specify allow_utime, it's initialized from dmask. */
+	if (opts->allow_utime == (unsigned short)-1)
+		opts->allow_utime = ~opts->fs_dmask & (S_IWGRP | S_IWOTH);
+	if (opts->unicode_xlate)
+		opts->utf8 = 0;

Probably, this should move to fat_parse_param()?

Quoted 8 lines

In my conversions, I have treated parse_param as simply handling one option at a time, and not dealing with combinations, because we don't have the "full view" of all options until we are done (previously we parsed everything, and then could "clean up" at the bottom of the function). So now, I was handling this sort of checking after parsing was complete, and fill_super seemed an OK place to do it.

But sure - I will look at whether doing it in fat_parse_param makes sense.

I don't think that will work.

For example, for the allow_utime adjustment...

Before parsing begins, allow_utime is defaulted to -1 (unset) and fs_dmask is defaulted to current_umask()

If we put the

+ if (opts->allow_utime == (unsigned short)-1)
+ opts->allow_utime = ~opts->fs_dmask & (S_IWGRP | S_IWOTH);

test at the bottom of parse_param, then this sequence of parsing:

("mount -o fs_uid=42,fs_dmask=0XYZ")

fs_uid=42
--> sets opts->allow_utime to (~opts->fs_dmask & (S_IWGRP | S_IWOTH))
where fs_dmask is default / current_umask()
fs_dmask=0XYZ
--> changes fs_dmask from default, but does not update allow_utime which
was set based on the old fs_dmask

leads to different results than:

("mount -o fs_dmask=0XYZ",fs_uid=42)

fs_dmask=0XYZ
--> changes fs_dmask from the default
updates allow_utime based on this user-specified fs_dmask rather than default
fs_uid=42
--> allow_utime is now set, so no further changes are made

IOWS, the final allow_utime value may differ depending on the order of option parsing, unless we wait until parsing is complete before we inspect and adjust it.

dhowells did, however, suggest that perhaps these adjustments should generally be done in get_tree rather than fill_super, so I'll give that a shot.

Sound ok?

-Eric

maintainer
#7 lore raw

Re: [PATCH 2/2 V2] fat: Convert to new mount api

Quoted 36 lines · Eric Sandeen
Quoted 2 lines · Eric Sandeen
Quoted 1 line · OGAWA Hirofumi

Eric Sandeen <[email protected]> writes:

I don't think that will work.

For example, for the allow_utime adjustment...

Before parsing begins, allow_utime is defaulted to -1 (unset) and fs_dmask is defaulted to current_umask()

If we put the

fs/fat/inode.c +2 -0
+	if (opts->allow_utime == (unsigned short)-1)
+		opts->allow_utime = ~opts->fs_dmask & (S_IWGRP | S_IWOTH);

test at the bottom of parse_param, then this sequence of parsing:

("mount -o fs_uid=42,fs_dmask=0XYZ")

fs_uid=42
--> sets opts->allow_utime to (~opts->fs_dmask & (S_IWGRP | S_IWOTH))
where fs_dmask is default / current_umask()
fs_dmask=0XYZ
--> changes fs_dmask from default, but does not update allow_utime which
was set based on the old fs_dmask

leads to different results than:

("mount -o fs_dmask=0XYZ",fs_uid=42)

fs_dmask=0XYZ
--> changes fs_dmask from the default
updates allow_utime based on this user-specified fs_dmask rather than default
fs_uid=42
--> allow_utime is now set, so no further changes are made

Quoted 7 lines

IOWS, the final allow_utime value may differ depending on the order of option parsing, unless we wait until parsing is complete before we inspect and adjust it.

dhowells did, however, suggest that perhaps these adjustments should generally be done in get_tree rather than fill_super, so I'll give that a shot.

Sound ok?

Ah, you are right. I was misread how parser works. And then your original may be readable than get_tree.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#8 lore raw
In reply to Eric Sandeen
Quoted 24 lines · Eric Sandeen

This short series converts the fat/vfat/msdos filesystem to use the new mount API.

I've tested it with a hacky shell script found at

https://gist.github.com/sandeen/3492a39c3f2bf16d1ccdd2cd1c681ccd

which tries every possible option, including some with invalid values, on both vfat and msdos mounts. It then tests random combinations of 2, 3, and 4 options, including possibly invalid options.

I captured stdout from two runs with and without these modifications, and the results are identical.

As patch 2 notes, I left codepage loading to fill_super(), rather than validating codepage options as they are parsed. This is because i.e.

mount -o "iocharset=nope,iocharset=iso8859-1"

passes today, due to the last iocharset option being the only one that is loaded. It might be nice to validate such options as they are parsed, but doing so would make the above command line fail, so I'm not sure if it's a good idea. I do have a patch to validate as we parse, if that's desired.

Quoted 5 lines

Lastly, this does not yet use the proposed uid/gid parsing helpers, since that is not yet merged.

Thanks,
-Eric

Just realized that one thing I missed is that in current code, fs-specific options are not parsed at all on remount. With this change, invalid options are rejected. I'll send a V2 of patch 2 which short-circuits option parsing for a remount and completely ignores options.

(Sorry, I'm famous for sitting on a patch for weeks, then realizing the one thing I forgot as soon as I send it.)

Thanks,
-Eric