From: Jan Tulak Date: Tue, 21 Jun 2016 02:53:32 +0000 (+1000) Subject: mkfs: better error with incorrect b/s value suffix usage X-Git-Tag: v4.7.0-rc1~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef92dd5ab20043b8fac1843bd1e1149137577a6e;p=thirdparty%2Fxfsprogs-dev.git mkfs: better error with incorrect b/s value suffix usage If user writes a value using b or s suffix without explicitly stating the size of blocks or sectors, mkfs ends with a not helpful error about the value being too small. It happens because we read the physical geometry after all options are parsed. So, tell the user exactly what is wrong with the input. Signed-off-by: Jan Tulak Reviewed-by: Dave Chinner Signed-off-by: Dave Chinner --- diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index ce1ade257..47e2219e4 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -3289,10 +3289,24 @@ cvtnum( if (sp[1] != '\0') return -1LL; - if (*sp == 'b') - return i * blksize; - if (*sp == 's') - return i * sectsize; + if (*sp == 'b') { + if (!blksize) { + fprintf(stderr, +_("Blocksize must be provided prior to using 'b' suffix.\n")); + usage(); + } else { + return i * blksize; + } + } + if (*sp == 's') { + if (!sectsize) { + fprintf(stderr, +_("Sectorsize must be specified prior to using 's' suffix.\n")); + usage(); + } else { + return i * sectsize; + } + } c = tolower(*sp); switch (c) {