]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: factor inode subopts parser
authorDave Chinner <dchinner@redhat.com>
Wed, 6 Dec 2017 23:14:27 +0000 (17:14 -0600)
committerEric Sandeen <sandeen@redhat.com>
Wed, 6 Dec 2017 23:14:27 +0000 (17:14 -0600)
Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
mkfs/xfs_mkfs.c

index 7dca302b57756d0440406ff7754708ca33f33b4c..2292362b49e4f346ed32c892439f25c5063b821b 100644 (file)
@@ -1581,6 +1581,37 @@ inode_opts_parser(
        char                    *value,
        struct cli_params       *cli)
 {
+       int                     inodelog;
+
+       switch (subopt) {
+       case I_ALIGN:
+               cli->sb_feat.inode_align = getnum(value, &iopts, I_ALIGN);
+               break;
+       case I_LOG:
+               inodelog = getnum(value, &iopts, I_LOG);
+               cli->inodesize = 1 << inodelog;
+               break;
+       case I_MAXPCT:
+               cli->imaxpct = getnum(value, &iopts, I_MAXPCT);
+               break;
+       case I_PERBLOCK:
+               cli->inopblock = getnum(value, &iopts, I_PERBLOCK);
+               break;
+       case I_SIZE:
+               cli->inodesize = getnum(value, &iopts, I_SIZE);
+               break;
+       case I_ATTR:
+               cli->sb_feat.attr_version = getnum(value, &iopts, I_ATTR);
+               break;
+       case I_PROJID32BIT:
+               cli->sb_feat.projid16bit = !getnum(value, &iopts, I_PROJID32BIT);
+               break;
+       case I_SPINODES:
+               cli->sb_feat.spinodes = getnum(value, &iopts, I_SPINODES);
+               break;
+       default:
+               return -EINVAL;
+       }
        return 0;
 }
 
@@ -1795,6 +1826,7 @@ main(
        };
        struct cli_params       cli = {
                .xi = &xi,
+               .sb_feat = sb_feat,
        };
 
        platform_uuid_generate(&uuid);
@@ -1878,53 +1910,19 @@ main(
                        /* end temp don't break code */
                        break;
                case 'i':
-                       p = optarg;
-                       while (*p != '\0') {
-                               char    **subopts = (char **)iopts.subopts;
-                               char    *value;
+                       parse_subopts(c, optarg, &cli);
 
-                               switch (getsubopt(&p, subopts, &value)) {
-                               case I_ALIGN:
-                                       sb_feat.inode_align = getnum(value,
-                                                               &iopts, I_ALIGN);
-                                       break;
-                               case I_LOG:
-                                       inodelog = getnum(value, &iopts, I_LOG);
-                                       isize = 1 << inodelog;
-                                       ilflag = 1;
-                                       break;
-                               case I_MAXPCT:
-                                       imaxpct = getnum(value, &iopts,
-                                                        I_MAXPCT);
-                                       imflag = 1;
-                                       break;
-                               case I_PERBLOCK:
-                                       inopblock = getnum(value, &iopts,
-                                                          I_PERBLOCK);
-                                       ipflag = 1;
-                                       break;
-                               case I_SIZE:
-                                       isize = getnum(value, &iopts, I_SIZE);
-                                       inodelog = libxfs_highbit32(isize);
-                                       isflag = 1;
-                                       break;
-                               case I_ATTR:
-                                       sb_feat.attr_version =
-                                               getnum(value, &iopts, I_ATTR);
-                                       break;
-                               case I_PROJID32BIT:
-                                       sb_feat.projid16bit =
-                                               !getnum(value, &iopts,
-                                                       I_PROJID32BIT);
-                                       break;
-                               case I_SPINODES:
-                                       sb_feat.spinodes = getnum(value,
-                                                       &iopts, I_SPINODES);
-                                       break;
-                               default:
-                                       unknown('i', value);
-                               }
-                       }
+                       /* temp don't break code */
+                       isize = cli.inodesize;
+                       inodelog = libxfs_highbit32(isize);
+                       inopblock = cli.inopblock;
+                       ilflag = cli_opt_set(&iopts, I_LOG);
+                       isflag = cli_opt_set(&iopts, I_SIZE);
+                       ipflag = cli_opt_set(&iopts, I_PERBLOCK);
+
+                       imaxpct = cli.imaxpct;
+                       imflag = cli_opt_set(&iopts, I_MAXPCT);
+                       /* end temp don't break code */
                        break;
                case 'l':
                        p = optarg;
@@ -2172,6 +2170,10 @@ main(
        } else
                dfile = xi.dname;
 
+       /* temp don't break code */
+       sb_feat = cli.sb_feat;
+       /* end temp don't break code */
+
        /*
         * Blocksize and sectorsize first, other things depend on them
         * For RAID4/5/6 we want to align sector size and block size,