Skip to contentSkip to conversation

Add support for true/false & yes/no in bool-type options

PATCH In review Integral 2 participants 2 messages Jul 18, 2024 – Jul 22, 2024

lore
Share & tools
lore

Integral

author
#0 lore raw

PATCH 1/1 Add support for true/false & yes/no in bool-type options

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 | 5 +++++
 1 file changed, 5 insertions(+)
libbcachefs/opts.c +5 -0
index 0770aebe..2c0113fb 100644
@@ -332,6 +332,11 @@ int bch2_opt_parse(struct bch_fs *c,
 	switch (opt->type) {
 	case BCH_OPT_BOOL:
 		if (val) {
+			if (!strcmp(val, "true") || !strcmp(val, "yes"))
+				val = "1";
+			else if (!strcmp(val, "false") || !strcmp(val, "no"))
+				val = "0";
+
 			ret = kstrtou64(val, 10, res);
 		} else {
 			ret = 0;
Signature · 1 line
2.45.2
#1 lore raw
Quoted 3 lines · Integral

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.

this needs to be against the kernel repo, fs/bcachefs/; tools is imported from there

Quoted 24 lines
---
 libbcachefs/opts.c | 5 +++++
 1 file changed, 5 insertions(+)
libbcachefs/opts.c +5 -0
index 0770aebe..2c0113fb 100644
@@ -332,6 +332,11 @@ int bch2_opt_parse(struct bch_fs *c,
 	switch (opt->type) {
 	case BCH_OPT_BOOL:
 		if (val) {
+			if (!strcmp(val, "true") || !strcmp(val, "yes"))
+				val = "1";
+			else if (!strcmp(val, "false") || !strcmp(val, "no"))
+				val = "0";
+
 			ret = kstrtou64(val, 10, res);
 		} else {
 			ret = 0;
Signature · 1 line
2.45.2