From 61edcb8bfa316e3c091f71b1d73dd81a5359d965 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 3 Oct 2003 00:49:02 -0700 Subject: [PATCH] [PATCH] USB: convert usbfs to use new fs parser code. --- drivers/usb/core/inode.c | 143 +++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 67 deletions(-) diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c index 8474deb3f277b..ff34ed0135437 100644 --- a/drivers/usb/core/inode.c +++ b/drivers/usb/core/inode.c @@ -38,6 +38,7 @@ #include #include #include +#include #include static struct super_operations usbfs_ops; @@ -62,86 +63,94 @@ static umode_t devmode = S_IWUSR | S_IRUGO; static umode_t busmode = S_IXUGO | S_IRUGO; static umode_t listmode = S_IRUGO; +enum { + Opt_devuid, Opt_devgid, Opt_devmode, + Opt_busuid, Opt_busgid, Opt_busmode, + Opt_listuid, Opt_listgid, Opt_listmode, + Opt_err, +}; + +static match_table_t tokens = { + {Opt_devuid, "devuid=%u"}, + {Opt_devgid, "devgid=%u"}, + {Opt_devmode, "devmode=%o"}, + {Opt_busuid, "busuid=%u"}, + {Opt_busgid, "busgid=%u"}, + {Opt_busmode, "busmode=%o"}, + {Opt_listuid, "listuid=%u"}, + {Opt_listgid, "listgid=%u"}, + {Opt_listmode, "listmode=%o"}, + {Opt_err, NULL} +}; + static int parse_options(struct super_block *s, char *data) { - char *curopt = NULL, *value; + char *p; + int option; - while ((curopt = strsep(&data, ",")) != NULL) { - if (!*curopt) + while ((p = strsep(&data, ",")) != NULL) { + substring_t args[MAX_OPT_ARGS]; + int token; + if (!*p) continue; - if ((value = strchr(curopt, '=')) != NULL) - *value++ = 0; - if (!strcmp(curopt, "devuid")) { - if (!value || !value[0]) - return -EINVAL; - devuid = simple_strtoul(value, &value, 0); - if (*value) - return -EINVAL; - } - if (!strcmp(curopt, "devgid")) { - if (!value || !value[0]) - return -EINVAL; - devgid = simple_strtoul(value, &value, 0); - if (*value) - return -EINVAL; - } - if (!strcmp(curopt, "devmode")) { - if (!value || !value[0]) - return -EINVAL; - devmode = simple_strtoul(value, &value, 0) & S_IRWXUGO; - if (*value) - return -EINVAL; - } - if (!strcmp(curopt, "busuid")) { - if (!value || !value[0]) - return -EINVAL; - busuid = simple_strtoul(value, &value, 0); - if (*value) - return -EINVAL; - } - if (!strcmp(curopt, "busgid")) { - if (!value || !value[0]) - return -EINVAL; - busgid = simple_strtoul(value, &value, 0); - if (*value) - return -EINVAL; - } - if (!strcmp(curopt, "busmode")) { - if (!value || !value[0]) - return -EINVAL; - busmode = simple_strtoul(value, &value, 0) & S_IRWXUGO; - if (*value) - return -EINVAL; - } - if (!strcmp(curopt, "listuid")) { - if (!value || !value[0]) - return -EINVAL; - listuid = simple_strtoul(value, &value, 0); - if (*value) - return -EINVAL; - } - if (!strcmp(curopt, "listgid")) { - if (!value || !value[0]) - return -EINVAL; - listgid = simple_strtoul(value, &value, 0); - if (*value) + + token = match_token(p, tokens, args); + switch (token) { + case Opt_devuid: + if (match_int(&args[0], &option)) + return -EINVAL; + devuid = option; + break; + case Opt_devgid: + if (match_int(&args[0], &option)) + return -EINVAL; + devgid = option; + break; + case Opt_devmode: + if (match_octal(&args[0], &option)) return -EINVAL; - } - if (!strcmp(curopt, "listmode")) { - if (!value || !value[0]) + devmode = option & S_IRWXUGO; + break; + case Opt_busuid: + if (match_int(&args[0], &option)) + return -EINVAL; + busuid = option; + break; + case Opt_busgid: + if (match_int(&args[0], &option)) + return -EINVAL; + busgid = option; + break; + case Opt_busmode: + if (match_octal(&args[0], &option)) return -EINVAL; - listmode = simple_strtoul(value, &value, 0) & S_IRWXUGO; - if (*value) + busmode = option & S_IRWXUGO; + break; + case Opt_listuid: + if (match_int(&args[0], &option)) + return -EINVAL; + listuid = option; + break; + case Opt_listgid: + if (match_int(&args[0], &option)) + return -EINVAL; + listgid = option; + break; + case Opt_listmode: + if (match_octal(&args[0], &option)) return -EINVAL; + listmode = option & S_IRWXUGO; + break; + default: + err("usbfs: unrecognised mount option \"%s\" " + "or missing value\n", p); + return -EINVAL; } } return 0; } - -/* --------------------------------------------------------------------- */ - static struct inode *usbfs_get_inode (struct super_block *sb, int mode, dev_t dev) { struct inode *inode = new_inode(sb); -- 2.53.0