From: Jan Tulak Date: Tue, 10 May 2016 07:16:07 +0000 (+1000) Subject: mkfs: add optional 'reason' for illegal_option X-Git-Tag: v4.7.0-rc1~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aa3034d47661ebb87cb99ad148dd516f608d6463;p=thirdparty%2Fxfsprogs-dev.git mkfs: add optional 'reason' for illegal_option Allow us to tell the user what exactly is wrong with the specified options. For example, that the value is too small, instead of just generic "bad option." [dchinner: fix whitespace, simplify illegal option message ] 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 95a1caee2..2e4feb835 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1544,13 +1544,15 @@ sb_set_features( static __attribute__((noreturn)) void illegal_option( - const char *value, + const char *value, struct opt_params *opts, - int index) + int index, + const char *reason) { fprintf(stderr, - _("Illegal value %s for -%c %s option\n"), - value, opts->name, opts->subopts[index]); + _("Illegal value %s for -%c %s option. %s\n"), + value, opts->name, opts->subopts[index], + reason ? reason : ""); usage(); } @@ -1642,16 +1644,18 @@ getnum( c = strtoll(str, &str_end, 0); if (c == 0 && str_end == str) - illegal_option(str, opts, index); + illegal_option(str, opts, index, NULL); if (*str_end != '\0') - illegal_option(str, opts, index); + illegal_option(str, opts, index, NULL); } /* Validity check the result. */ - if (c < sp->minval || c > sp->maxval) - illegal_option(str, opts, index); + if (c < sp->minval) + illegal_option(str, opts, index, _("value is too small")); + else if (c > sp->maxval) + illegal_option(str, opts, index, _("value is too large")); if (sp->is_power_2 && !ispow2(c)) - illegal_option(str, opts, index); + illegal_option(str, opts, index, _("value must be a power of 2")); return c; }