autofs4 options parsing
PATCH 5/15 autofs4 options parsing
fs/autofs4/inode.c +43 -47
@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/file.h> #include <linux/pagemap.h> +#include <linux/parser.h> #include <asm/bitops.h> #include "autofs_i.h" #include <linux/module.h>
@@ -94,10 +95,23 @@ static struct super_operations autofs4_s .statfs = simple_statfs, }; +enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto}; + +static match_table_t tokens = { + {Opt_fd,"fd=%d" }, + {Opt_uid,"uid=%d" }, + {Opt_gid,"gid=%d" }, + {Opt_pgrp,"pgrp=%d" }, + {Opt_minproto,"minproto=%d" }, + {Opt_maxproto,"maxproto=%d" }, + {Opt_err,NULL } +}; +static int parse_options (char *options,int *pipefd,uid_t *uid,gid_t *gid,pid_t *pgrp,int *minproto,int *maxproto) { -char *this_char, *value; +char *p; +substring_t args[MAX_OPT_ARGS ]; *uid = current->uid; *gid = current->gid;
@@ -108,55 +122,37 @@ static int parse_options(char *options, *pipefd =-1 ; -if ( !options )return 1 ; -while ((this_char =strsep (&options,"," )) !=NULL ) { -if (!*this_char) +if (!options) +return 1 ; + +while ((p =strsep (&options,"," )) !=NULL ) { +int token; +if (!*p)continue ; -if ((value =strchr (this_char,'=' )) !=NULL ) - *value++ =0 ; -if (!strcmp (this_char,"fd" )) { -if (!value || !*value) -return 1 ; - *pipefd =simple_strtoul (value,&value,0 ); -if (*value) -return 1 ; - } -else if (!strcmp (this_char,"uid" )) { -if (!value || !*value) -return 1 ; - *uid =simple_strtoul (value,&value,0 ); -if (*value) -return 1 ; - } -else if (!strcmp (this_char,"gid" )) { -if (!value || !*value) -return 1 ; - *gid =simple_strtoul (value,&value,0 ); -if (*value) -return 1 ; - } -else if (!strcmp (this_char,"pgrp" )) { -if (!value || !*value) -return 1 ; - *pgrp =simple_strtoul (value,&value,0 ); -if (*value) -return 1 ; - } -else if (!strcmp (this_char,"minproto" )) { -if (!value || !*value) -return 1 ; - *minproto =simple_strtoul (value,&value,0 ); -if (*value) -return 1 ; - } -else if (!strcmp (this_char,"maxproto" )) { -if (!value || !*value) -return 1 ; - *maxproto =simple_strtoul (value,&value,0 ); -if (*value) + + token =match_token (p, tokens, args); +switch (token) { +case Opt_fd: + *pipefd =match_int (args); +break ; +case Opt_uid: + *uid =match_int (args); +break ; +case Opt_gid: + *gid =match_int (args); +break ; +case Opt_pgrp: + *pgrp =match_int (args); +break ; +case Opt_minproto: + *minproto =match_int (args); +break ; +case Opt_maxproto: + *maxproto =match_int (args); +break ; +default :return 1 ; } -else break ; }return (*pipefd <0 ); }
--
~Randy