5 #include <linux/kernel.h>
6 #include <linux/string.h>
12 * smb_getopt - option parser
13 * @caller: name of the caller, for error messages
14 * @options: the options string
15 * @opts: an array of &struct option entries controlling parser operations
16 * @optopt: output; will contain the current option
17 * @optarg: output; will contain the value (if one exists)
18 * @flag: output; may be NULL; should point to a long for or'ing flags
19 * @value: output; may be NULL; will be overwritten with the integer value
20 * of the current argument.
22 * Helper to parse options on the format used by mount ("a=b,c=d,e,f").
23 * Returns opts->val if a matching entry in the 'opts' array is found,
24 * 0 when no more tokens are found, -1 if an error is encountered.
26 int smb_getopt(char *caller
, char **options
, struct option
*opts
,
27 char **optopt
, char **optarg
, unsigned long *flag
,
35 if ((token
= strsep(options
, ",")) == NULL
)
37 } while (*token
== '\0');
41 if ((val
= strchr (token
, '=')) != NULL
) {
44 *value
= simple_strtoul(val
, NULL
, 0);
48 for (i
= 0; opts
[i
].name
!= NULL
; i
++) {
49 if (!strcmp(opts
[i
].name
, token
)) {
50 if (!opts
[i
].flag
&& (!val
|| !*val
)) {
51 printk("%s: the %s option requires an argument\n",
56 if (flag
&& opts
[i
].flag
)
57 *flag
|= opts
[i
].flag
;
62 printk("%s: Unrecognized mount option %s\n", caller
, token
);