]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: better error with incorrect b/s value suffix usage
authorJan Tulak <jtulak@redhat.com>
Tue, 21 Jun 2016 02:53:32 +0000 (12:53 +1000)
committerDave Chinner <david@fromorbit.com>
Tue, 21 Jun 2016 02:53:32 +0000 (12:53 +1000)
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 <jtulak@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
mkfs/xfs_mkfs.c

index ce1ade25780e76f78d62873d1a10d40f3abe4455..47e2219e4fc4165187d5fe2aeabdd9b64ef35af1 100644 (file)
@@ -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) {