Skip to contentSkip to conversation

adfs options parsing

PATCH In review Randy.Dunlap 1 participant 1 message Sep 5, 2003 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 2/15 adfs options parsing

fs/adfs/super.c +33 -35
diff -Naurp -X /home/rddunlap/doc/dontdiff-osdl linux-260-test4-pv/fs/adfs/super.c linux-260-test4-fs/fs/adfs/super.c
@@ -19,6 +19,7 @@
 #include <linux/init.h>
 #include <linux/buffer_head.h>
 #include <linux/vfs.h>
+#include <linux/parser.h>
 
 #include <asm/bitops.h>
 #include <asm/uaccess.h>
@@ -134,51 +135,48 @@ static void adfs_put_super(struct super_
 	sb->s_fs_info = NULL;
 }
 
+enum {Opt_uid, Opt_gid, Opt_ownmask, Opt_othmask, Opt_err};
+
+static match_table_t tokens = {
+	{Opt_uid, "uid=%u"},
+	{Opt_gid, "gid=%u"},
+	{Opt_ownmask, "ownmask=%o"},
+	{Opt_othmask, "othmask=%o"},
+	{Opt_err, NULL}
+};
+
 static int parse_options(struct super_block *sb, char *options)
 {
-	char *value, *opt;
+	char *p;
 	struct adfs_sb_info *asb = ADFS_SB(sb);
 
 	if (!options)
 		return 0;
 
-	while ((opt = strsep(&options, ",")) != NULL) {
-		if (!*opt)
+	while ((p = strsep(&options, ",")) != NULL) {
+		substring_t args[MAX_OPT_ARGS];
+		int token;
+		if (!*p)
 			continue;
-		value = strchr(opt, '=');
-		if (value)
-			*value++ = '\0';
 
-		if (!strcmp(opt, "uid")) {	/* owner of all files */
-			if (!value || !*value)
-				return -EINVAL;
-			asb->s_uid = simple_strtoul(value, &value, 0);
-			if (*value)
-				return -EINVAL;
-		} else
-		if (!strcmp(opt, "gid")) {	/* group owner of all files */
-			if (!value || !*value)
-				return -EINVAL;
-			asb->s_gid = simple_strtoul(value, &value, 0);
-			if (*value)
-				return -EINVAL;
-		} else
-		if (!strcmp(opt, "ownmask")) {	/* owner permission mask */
-			if (!value || !*value)
-				return -EINVAL;
-			asb->s_owner_mask = simple_strtoul(value, &value, 8);
-			if (*value)
-				return -EINVAL;
-		} else
-		if (!strcmp(opt, "othmask")) {	/* others permission mask */
-			if (!value || !*value)
-				return -EINVAL;
-			asb->s_other_mask = simple_strtoul(value, &value, 8);
-			if (*value)
+		token = match_token(p, tokens, args);
+		switch (token) {
+			case Opt_uid:
+				asb->s_uid = match_int(args);
+				break;
+			case Opt_gid:
+				asb->s_gid = match_int(args);
+				break;
+			case Opt_ownmask:
+				asb->s_owner_mask = match_octal(args);
+				break;
+			case Opt_othmask:
+				asb->s_other_mask = match_octal(args);
+				break;
+			default:
+				printk("ADFS-fs: unrecognised mount option \"%s\" "
+						"or missing value\n", p);
 				return -EINVAL;
-		} else {			/* eh? say again. */
-			printk("ADFS-fs: unrecognised mount option %s\n", opt);
-			return -EINVAL;
 		}
 	}
 	return 0;

--
~Randy