cmd_format: fix --version

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-12-03 21:36:29 -05:00
parent 51ebefdd6e
commit c560ff06f4
3 changed files with 18 additions and 2 deletions

View File

@ -220,8 +220,7 @@ int cmd_format(int argc, char *argv[])
unconsumed_dev_option = true; unconsumed_dev_option = true;
break; break;
case O_version: case O_version:
if (kstrtouint(optarg, 10, &opts.version)) opts.version = version_parse(optarg);
die("invalid version");
break; break;
case O_no_initialize: case O_no_initialize:
initialize = false; initialize = false;

View File

@ -726,6 +726,21 @@ struct bbpos_range bbpos_range_parse(char *buf)
return (struct bbpos_range) { .start = start, .end = end }; return (struct bbpos_range) { .start = start, .end = end };
} }
unsigned version_parse(char *buf)
{
char *s = buf;
char *major_str = strsep(&s, ".");
char *minor_str = strsep(&s, ".");
unsigned major, minor;
if (kstrtouint(major_str, 10, &major) ||
kstrtouint(minor_str, 10, &minor))
die("invalid version");
return BCH_VERSION(major, minor);
}
darray_str get_or_split_cmdline_devs(int argc, char *argv[]) darray_str get_or_split_cmdline_devs(int argc, char *argv[])
{ {
darray_str ret = {}; darray_str ret = {};

View File

@ -209,6 +209,8 @@ struct bbpos_range {
struct bbpos_range bbpos_range_parse(char *); struct bbpos_range bbpos_range_parse(char *);
unsigned version_parse(char *);
darray_str get_or_split_cmdline_devs(int argc, char *argv[]); darray_str get_or_split_cmdline_devs(int argc, char *argv[]);
#endif /* _TOOLS_UTIL_H */ #endif /* _TOOLS_UTIL_H */