On Thu, Jul 18, 2024 at 08:29:28PM GMT, Integral wrote: > Here is the new patch: > > Currently, when using bcachefs-tools to set options, bool-type options can > only accept 1 or 0. Add support for accepting true/false, yes/no & > on/off for these options. > > Signed-off-by: Integral <[email protected]> > --- > fs/bcachefs/opts.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c > index 0770aebef6d8..0e4cd6984eda 100644 > --- a/fs/bcachefs/opts.c > +++ b/fs/bcachefs/opts.c > @@ -332,17 +332,21 @@ int bch2_opt_parse(struct bch_fs *c, > switch (opt->type) { > case BCH_OPT_BOOL: > if (val) { > - ret = kstrtou64(val, 10, res); > + if (!strcasecmp(val, "1") || !strcasecmp(val, "true") || > + !strcasecmp(val, "yes") || !strcasecmp(val, > "on")) { > + *res = 1; > + } else if (!strcasecmp(val, "0") || !strcasecmp(val, > "false") || > + !strcasecmp(val, "no") || !strcasecmp(val, > "off")) { > + *res = 0; > + } else { > + if (err) > + prt_printf(err, "%s: must be bool", > opt->attr.name); > + return -BCH_ERR_option_not_bool; > + }
There _should_ be something more standard in the kernel for parsing bool options (commandline options, module options) - please hunt around for that and see if it works; report back on what you find. We want to be consistent on how we parse bools throughout the kernel.
