Thread (64 messages) 64 messages, 7 authors, 2017-10-25
STALE3180d

[PATCH 05/42] mkfs: factor block subopts parser

From: Dave Chinner <david@fromorbit.com>
Date: 2017-08-29 23:50:59
Subsystem: the rest · Maintainer: Linus Torvalds

From: Dave Chinner <redacted>

Signed-Off-By: Dave Chinner <redacted>
---
 mkfs/xfs_mkfs.c | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 022fb84016f6..40de7ea9bfa8 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -1474,6 +1474,19 @@ block_opts_parser(
 	char			*value,
 	struct cli_params	*cli)
 {
+	int			blocklog;
+
+	switch (subopt) {
+	case B_LOG:
+		blocklog = getnum(value, opts, B_LOG);
+		cli->blocksize = 1 << blocklog;
+		break;
+	case B_SIZE:
+		cli->blocksize = getnum(value, opts, B_SIZE);
+		break;
+	default:
+		return -EINVAL;
+	}
 	return 0;
 }
 
@@ -1706,6 +1719,7 @@ main(
 		.rmapbt = false,
 		.reflink = false,
 	};
+	struct cli_params	cli = {};
 
 	platform_uuid_generate(&uuid);
 	progname = basename(argv[0]);
@@ -1745,27 +1759,14 @@ main(
 			force_overwrite = 1;
 			break;
 		case 'b':
-			p = optarg;
-			while (*p != '\0') {
-				char	**subopts = (char **)bopts.subopts;
-				char	*value;
-
-				switch (getsubopt(&p, subopts, &value)) {
-				case B_LOG:
-					blocklog = getnum(value, &bopts, B_LOG);
-					blocksize = 1 << blocklog;
-					blflag = 1;
-					break;
-				case B_SIZE:
-					blocksize = getnum(value, &bopts,
-							   B_SIZE);
-					blocklog = libxfs_highbit32(blocksize);
-					bsflag = 1;
-					break;
-				default:
-					unknown('b', value);
-				}
-			}
+			parse_subopts(c, optarg, &cli);
+
+			/* temp don't break code */
+			blocksize = cli.blocksize;
+			blocklog = libxfs_highbit32(blocksize);
+			blflag = cli_opt_set(&bopts, B_LOG);
+			bsflag = cli_opt_set(&bopts, B_SIZE);
+			/* end temp don't break code */
 			break;
 		case 'd':
 			p = optarg;
-- 
2.13.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help