[PATCH 12/42] mkfs: factor sector subopts parser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Dave Chinner <dchinner@xxxxxxxxxx>

Signed-Off-By: Dave Chinner <dchinner@xxxxxxxxxx>
---
 mkfs/xfs_mkfs.c | 69 +++++++++++++++++++++++++++------------------------------
 1 file changed, 33 insertions(+), 36 deletions(-)

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 87505c61aa79..5a646b89cd0f 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -1755,6 +1755,27 @@ sector_opts_parser(
 	char			*value,
 	struct cli_params	*cli)
 {
+	int			sectorlog;
+
+	switch (subopt) {
+	case S_LOG:
+	case S_SECTLOG:
+		if (cli->sectorsize)
+			conflict('s', opts->subopts, S_SECTSIZE, S_SECTLOG);
+		sectorlog = getnum(value, &sopts, S_SECTLOG);
+		cli->sectorsize = 1 << sectorlog;
+		cli->lsectorsize = cli->sectorsize;
+		break;
+	case S_SIZE:
+	case S_SECTSIZE:
+		if (cli->sectorsize)
+			conflict('s', opts->subopts, S_SECTLOG, S_SECTSIZE);
+		cli->sectorsize = getnum(value, &sopts, S_SECTSIZE);
+		cli->lsectorsize = cli->sectorsize;
+		break;
+	default:
+		return -EINVAL;
+	}
 	return 0;
 }
 
@@ -1881,7 +1902,6 @@ main(
 	int			nvflag;
 	int			Nflag;
 	int			discard = 1;
-	char			*p;
 	char			*protofile;
 	char			*protostring;
 	int			qflag;
@@ -2091,41 +2111,18 @@ main(
 			/* end temp don't break code */
 			break;
 		case 's':
-			p = optarg;
-			while (*p != '\0') {
-				char	**subopts = (char **)sopts.subopts;
-				char	*value;
-
-				switch (getsubopt(&p, subopts, &value)) {
-				case S_LOG:
-				case S_SECTLOG:
-					if (lssflag)
-						conflict('s', (const char **)subopts,
-							 S_SECTSIZE, S_SECTLOG);
-					sectorlog = getnum(value, &sopts,
-							   S_SECTLOG);
-					lsectorlog = sectorlog;
-					sectorsize = 1 << sectorlog;
-					lsectorsize = sectorsize;
-					lslflag = slflag = 1;
-					break;
-				case S_SIZE:
-				case S_SECTSIZE:
-					if (lslflag)
-						conflict('s', (const char **)subopts, S_SECTLOG,
-							 S_SECTSIZE);
-					sectorsize = getnum(value, &sopts,
-							    S_SECTSIZE);
-					lsectorsize = sectorsize;
-					sectorlog =
-						libxfs_highbit32(sectorsize);
-					lsectorlog = sectorlog;
-					lssflag = ssflag = 1;
-					break;
-				default:
-					unknown('s', value);
-				}
-			}
+			parse_subopts(c, optarg, &cli);
+
+			/* temp don't break code */
+			sectorsize = cli.sectorsize;
+			lsectorlog = libxfs_highbit32(sectorsize);
+			lsectorsize = cli.lsectorsize;
+			lsectorlog = libxfs_highbit32(lsectorsize);
+			lslflag = slflag = cli_opt_set(&sopts, S_LOG) ||
+					   cli_opt_set(&sopts, S_SECTLOG);
+
+			lssflag = ssflag = cli_opt_set(&sopts, S_SIZE) ||
+					   cli_opt_set(&sopts, S_SECTSIZE);
 			break;
 		case 'V':
 			printf(_("%s version %s\n"), progname, VERSION);
-- 
2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux