[PATCH 18/19] mkfs: add optional 'reason' for illegal_option
Jan Tulak
jtulak at redhat.com
Thu Apr 21 04:39:52 CDT 2016
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."
Signed-off-by: Jan Tulak <jtulak at redhat.com>
---
CHANGES:
* code format (space)
* add translation _() to strings
---
mkfs/xfs_mkfs.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index a35c4a5..c4cd5ba 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -1546,11 +1546,18 @@ static __attribute__((noreturn)) void
illegal_option(
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]);
+ if (reason == NULL){
+ fprintf(stderr,
+ _("Illegal value %s for -%c %s option\n"),
+ value, opts->name, opts->subopts[index]);
+ } else {
+ fprintf(stderr,
+ _("Illegal value %s for -%c %s option: %s\n"),
+ value, opts->name, opts->subopts[index], reason);
+ }
usage();
}
@@ -1642,16 +1649,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;
}
--
2.5.0
More information about the xfs
mailing list