From: Dave Chinner Date: Wed, 6 Dec 2017 23:14:27 +0000 (-0600) Subject: mkfs: add generic subopt parsing table X-Git-Tag: v4.15.0-rc1~119 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a350bbc1808acc5ec28a477de5d811c4bc913b03;p=thirdparty%2Fxfsprogs-dev.git mkfs: add generic subopt parsing table Abstract out the common subopt parsing code into a common function and type table so we can factor the parsing code. Add the function stubs in preparation for factoring. Signed-Off-By: Dave Chinner Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index e17e3b674..10a064cbe 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1478,6 +1478,136 @@ getstr( return str; } +static int +block_opts_parser( + struct opt_params *opts, + int subopt, + char *value, + struct cli_params *cli) +{ + return 0; +} + +static int +data_opts_parser( + struct opt_params *opts, + int subopt, + char *value, + struct cli_params *cli) +{ + return 0; +} + +static int +inode_opts_parser( + struct opt_params *opts, + int subopt, + char *value, + struct cli_params *cli) +{ + return 0; +} + +static int +log_opts_parser( + struct opt_params *opts, + int subopt, + char *value, + struct cli_params *cli) +{ + return 0; +} + +static int +meta_opts_parser( + struct opt_params *opts, + int subopt, + char *value, + struct cli_params *cli) +{ + return 0; +} + +static int +naming_opts_parser( + struct opt_params *opts, + int subopt, + char *value, + struct cli_params *cli) +{ + return 0; +} + +static int +rtdev_opts_parser( + struct opt_params *opts, + int subopt, + char *value, + struct cli_params *cli) +{ + return 0; +} + +static int +sector_opts_parser( + struct opt_params *opts, + int subopt, + char *value, + struct cli_params *cli) +{ + return 0; +} + +struct subopts { + char opt; + struct opt_params *opts; + int (*parser)(); +} subopt_tab[] = { + { 'b', &bopts, block_opts_parser }, + { 'd', &dopts, data_opts_parser }, + { 'i', &iopts, inode_opts_parser }, + { 'l', &lopts, log_opts_parser }, + { 'm', &mopts, meta_opts_parser }, + { 'n', &nopts, naming_opts_parser }, + { 'r', &ropts, rtdev_opts_parser }, + { 's', &sopts, sector_opts_parser }, + { '\0', NULL, NULL }, +}; + +static void +parse_subopts( + char opt, + char *arg, + struct cli_params *cli) +{ + struct subopts *sop = &subopt_tab[0]; + char *p; + int ret = 0; + + while (sop->opts) { + if (sop->opt == opt) + break; + sop++; + } + + /* should never happen */ + if (!sop->opts) + return; + + p = arg; + while (*p != '\0') { + char **subopts = (char **)sop->opts->subopts; + char *value; + int subopt; + + subopt = getsubopt(&p, subopts, &value); + + ret = (sop->parser)(sop->opts, subopt, value, cli); + if (ret) + unknown(opt, value); + } +} + int main( int argc,