5 #include <linux/kernel.h>
6 #include <linux/string.h>
13 * ncp_getopt - option parser
14 * @caller: name of the caller, for error messages
15 * @options: the options string
16 * @opts: an array of &struct option entries controlling parser operations
17 * @optopt: output; will contain the current option
18 * @optarg: output; will contain the value (if one exists)
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 ncp_getopt(const char *caller
, char **options
, const struct ncp_option
*opts
,
27 char **optopt
, char **optarg
, unsigned long *value
)
33 if ((token
= strsep(options
, ",")) == NULL
)
35 } while (*token
== '\0');
39 if ((val
= strchr (token
, '=')) != NULL
) {
43 for (; opts
->name
; opts
++) {
44 if (!strcmp(opts
->name
, token
)) {
46 if (opts
->has_arg
& OPT_NOPARAM
) {
49 printk(KERN_INFO
"%s: the %s option requires an argument\n",
53 if (opts
->has_arg
& OPT_INT
) {
56 *value
= simple_strtoul(val
, &v
, 0);
60 printk(KERN_INFO
"%s: invalid numeric value in %s=%s\n",
64 if (opts
->has_arg
& OPT_STRING
) {
67 printk(KERN_INFO
"%s: unexpected argument %s to the %s option\n",
72 printk(KERN_INFO
"%s: Unrecognized mount option %s\n", caller
, token
);