This is a resend of my previous patch with code style optimized as I
forgot to add Kent Overstreet in "To". The previous patch is
(https://lore.kernel.org/linux-bcachefs/[email protected]/T/#u).

Currently, when using bcachefs-tools to set options, bool-type options can
only accept 1 or 0. Add support for accepting true/false and yes/no for
these options.

---
 libbcachefs/opts.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libbcachefs/opts.c b/libbcachefs/opts.c
index 0770aebe..e6ebc4c1 100644
--- a/libbcachefs/opts.c
+++ b/libbcachefs/opts.c
@@ -332,17 +332,19 @@ int bch2_opt_parse(struct bch_fs *c,
        switch (opt->type) {
        case BCH_OPT_BOOL:
                if (val) {
-                       ret = kstrtou64(val, 10, res);
+                       if (!strcmp(val, "1") || !strcmp(val, "true") || 
!strcmp(val, "yes")) {
+                               *res = 1;
+                       } else if (!strcmp(val, "0") || !strcmp(val, "false") 
|| !strcmp(val, "no")) {
+                               *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