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;
+                       }
                } else {
-                       ret = 0;
                        *res = 1;
                }
 
-               if (ret < 0 || (*res != 0 && *res != 1)) {
-                       if (err)
-                               prt_printf(err, "%s: must be bool", 
opt->attr.name);
-                       return ret < 0 ? ret : -BCH_ERR_option_not_bool;
-               }
                break;
        case BCH_OPT_UINT:
                if (!val) {
-- 
2.45.2


Reply via email to