diff mbox

[18/22] mkfs: prevent sector/blocksize to be specified as a number of blocks

Message ID 20170315160017.27805-19-jtulak@redhat.com (mailing list archive)
State Superseded
Headers show

Commit Message

Jan Tulak March 15, 2017, 4 p.m. UTC
Documentation states that the options blocked in this patch accepts the
size only in bytes. So prevent blocksize or sectorsize to be specified as
a number of blocks or sectors.

Signed-off-by: Jan Tulak <jtulak@redhat.com>

--
Change:
  * sectsize can be set in blocks and vice versa now
---
 mkfs/xfs_mkfs.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff mbox

Patch

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index bd2d81a3..767aeeea 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -2044,6 +2044,33 @@  getnum(
 		}
 	}
 
+	/* Prevent things like specifying blocksize as a number of blocks. */
+	if (opts->index == OPT_B ||
+		(opts->index == OPT_N && (index == N_SIZE))
+		) {
+		if ('b' == str[strlen(str)-1]) {
+			fprintf(stderr,
+				_("You can't set a block size in "
+				  "number of blocks (-%c %s).\n"),
+				opts->name, opts->subopts[index]);
+			exit(1);
+		}
+	}
+	else if (opts->index == OPT_S ||
+		(opts->index == OPT_L && (index == L_SECTLOG ||
+			index == L_SECTSIZE)) ||
+		(opts->index == OPT_D && (index == D_SECTLOG ||
+			index == D_SECTSIZE))
+		) {
+		if ('s' == str[strlen(str)-1]) {
+			fprintf(stderr,
+				_("You can't set a sector size in "
+				  "number of sectors (-%c %s).\n"),
+				opts->name, opts->subopts[index]);
+			exit(1);
+		}
+	}
+
 	sp->seen = true;
 
 	if (test_uvalue_num(sp->type, sp->minval, 0) &&