From: Will Dyson As a filesystem maintainer, I like the idea of this patch! However, I think it could use some comments on useage in the header file. There are already too many filesystem interfaces where the only documentation on how to use them is the way that existing filesystems use them. Below is a patch to convert befs to use parser.h. It kills some of my least favorite code (yay!). The patch is tested a certain minimal amount (booted, mounted a filesystem with options). 25-akpm/fs/befs/linuxvfs.c | 115 ++++++++++++++++++++++++--------------------- 1 files changed, 63 insertions(+), 52 deletions(-) diff -puN fs/befs/linuxvfs.c~befs-use-parser fs/befs/linuxvfs.c --- 25/fs/befs/linuxvfs.c~befs-use-parser Wed Sep 17 14:02:28 2003 +++ 25-akpm/fs/befs/linuxvfs.c Wed Sep 17 14:02:28 2003 @@ -13,6 +13,7 @@ #include #include #include +#include #include "befs.h" #include "btree.h" @@ -667,12 +668,26 @@ befs_nls2utf(struct super_block *sb, con return -EILSEQ; } +/** + * Use the + * + */ +enum { + Opt_uid, Opt_gid, Opt_charset, Opt_debug, +}; + +static match_table_t befs_tokens = { + {Opt_uid, "uid=%d"}, + {Opt_gid, "gid=%d"}, + {Opt_charset, "iocharset=%s"}, + {Opt_debug, "debug"} +}; + static int parse_options(char *options, befs_mount_options * opts) { - char *this_char; - char *value; - int ret = 1; + char *p; + substring_t args[MAX_OPT_ARGS]; /* Initialize options */ opts->uid = 0; @@ -683,64 +698,60 @@ parse_options(char *options, befs_mount_ opts->debug = 0; if (!options) - return ret; + return 1; - while ((this_char = strsep(&options, ",")) != NULL) { - - if ((value = strchr(this_char, '=')) != NULL) - *value++ = 0; - - if (!strcmp(this_char, "uid")) { - if (!value || !*value) { - ret = 0; - } else { - opts->uid = simple_strtoul(value, &value, 0); - opts->use_uid = 1; - if (*value) { - printk(KERN_ERR "BEFS: Invalid uid " - "option: %s\n", value); - ret = 0; + while ((p = strsep(&options, ",")) != NULL) { + int token; + if (!*p) + continue; + + token = match_token(p, befs_tokens, args); + switch (token) { + case Opt_uid: + { + int uid = match_int(&args[0]); + if (uid < 0) { + printk(KERN_ERR "BeFS: Invalid uid %d, " + "using default\n", uid); + break; } + opts->uid = uid; + opts->use_uid = 1; + break; } - } else if (!strcmp(this_char, "gid")) { - if (!value || !*value) - ret = 0; - else { - opts->gid = simple_strtoul(value, &value, 0); - opts->use_gid = 1; - if (*value) { - printk(KERN_ERR - "BEFS: Invalid gid option: " - "%s\n", value); - ret = 0; + case Opt_gid: + { + int gid = match_int(&args[0]); + if (gid < 0) { + printk(KERN_ERR "BeFS: Invalid gid %d, " + "using default\n", gid); + break; } + opts->gid = gid; + opts->use_gid = 1; + break; } - } else if (!strcmp(this_char, "iocharset") && value) { - char *p = value; - int len; - - while (*value && *value != ',') - value++; - len = value - p; - if (len) { - char *buffer = kmalloc(len + 1, GFP_NOFS); - if (buffer) { - opts->iocharset = buffer; - memcpy(buffer, p, len); - buffer[len] = 0; - - } else { - printk(KERN_ERR "BEFS: " - "cannot allocate memory\n"); - ret = 0; + case Opt_charset: + { + kfree(opts->iocharset); + opts->iocharset = match_strdup(&args[0]); + if (!opts->iocharset) { + printk(KERN_ERR "BeFS: allocation failure for " + "iocharset string\n"); + return 0; } + break; } - } else if (!strcmp(this_char, "debug")) { - opts->debug = 1; + case Opt_debug: + opts->debug = 1; + break; + default: + printk(KERN_ERR "BeFS: Unrecognized mount option \"%s\" " + "or missing value\n", p); + return 0; } } - - return ret; + return 1; } /* This function has the responsibiltiy of getting the _