proc options parsing
Subsystems (2)
PATCH 13/15 proc options parsing
fs/proc/inode.c +27 -18
@@ -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