From ef92dd5ab20043b8fac1843bd1e1149137577a6e Mon Sep 17 00:00:00 2001 From: Jan Tulak Date: Tue, 21 Jun 2016 12:53:32 +1000 Subject: [PATCH] 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 --- mkfs/xfs_mkfs.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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) { -- 2.50.1