[CFT] [13/15] proc options parsing

From: Randy.Dunlap
Date: Fri Sep 05 2003 - 14:37:05 EST



diff -Naurp -X /home/rddunlap/doc/dontdiff-osdl linux-260-test4-pv/fs/proc/inode.c linux-260-test4-fs/fs/proc/inode.c
--- linux-260-test4-pv/fs/proc/inode.c 2003-08-22 16:59:37.000000000 -0700
+++ linux-260-test4-fs/fs/proc/inode.c 2003-08-27 11:19:07.000000000 -0700
@@ -14,6 +14,7 @@
#include <linux/limits.h>
#include <linux/init.h>
#include <linux/module.h>
+#include <linux/parser.h>
#include <linux/smp_lock.h>
#include <linux/init.h>

@@ -136,34 +137,42 @@ static struct super_operations proc_sops
.statfs = simple_statfs,
};

+enum {
+ Opt_uid, Opt_gid, Opt_err
+};
+
+static match_table_t tokens = {
+ {Opt_uid, "uid=%u"},
+ {Opt_gid, "gid=%u"},
+ {Opt_err, NULL}
+};
+
static int parse_options(char *options,uid_t *uid,gid_t *gid)
{
- char *this_char,*value;
+ char *p;

*uid = current->uid;
*gid = current->gid;
if (!options)
return 1;
- while ((this_char = strsep(&options,",")) != NULL) {
- if (!*this_char)
+
+ while ((p = strsep(&options, ",")) != NULL) {
+ substring_t args[MAX_OPT_ARGS];
+ int token;
+ if (!*p)
continue;
- if ((value = strchr(this_char,'=')) != NULL)
- *value++ = 0;
- if (!strcmp(this_char,"uid")) {
- if (!value || !*value)
- return 0;
- *uid = simple_strtoul(value,&value,0);
- if (*value)
- return 0;
- }
- else if (!strcmp(this_char,"gid")) {
- if (!value || !*value)
- return 0;
- *gid = simple_strtoul(value,&value,0);
- if (*value)
+
+ token = match_token(p, tokens, args);
+ switch (token) {
+ case Opt_uid:
+ *uid = match_int(args);
+ break;
+ case Opt_gid:
+ *gid = match_int(args);
+ break;
+ default:
return 0;
}
- else return 1;
}
return 1;
}


--
~Randy
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/