Compare commits
1 Commits
f53fb186b8
...
8b08b0c2c1
Author | SHA1 | Date |
---|---|---|
Tom Marshall | 8b08b0c2c1 |
33
cbd/cbd.c
33
cbd/cbd.c
|
@ -70,6 +70,27 @@ parse_numeric_arg(const char* arg, uint64_t* val)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_boolean_arg(const char* arg, uint64_t* val)
|
||||
{
|
||||
if (!strcmp(arg, "1") ||
|
||||
!strcasecmp(arg, "true") ||
|
||||
!strcasecmp(arg, "on") ||
|
||||
!strcasecmp(arg, "yes")) {
|
||||
*val = 1;
|
||||
return true;
|
||||
}
|
||||
else if (!strcmp(arg, "0") ||
|
||||
!strcasecmp(arg, "false") ||
|
||||
!strcasecmp(arg, "off") ||
|
||||
!strcasecmp(arg, "no")) {
|
||||
*val = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
struct profile {
|
||||
const char* name;
|
||||
uint pblksize;
|
||||
|
@ -181,7 +202,7 @@ do_format(int argc, char** argv)
|
|||
{ "size", required_argument, NULL, 's' },
|
||||
{ "compress-alg", required_argument, NULL, 'z' },
|
||||
{ "compress-level", required_argument, NULL, 'Z' },
|
||||
{ "detect-zeros", no_argument, NULL, 0x1 },
|
||||
{ "detect-zeros", optional_argument, NULL, 0x1 },
|
||||
{ "profile", required_argument, NULL, 0x2 },
|
||||
{ "full-init", no_argument, NULL, 0x3 },
|
||||
{ NULL, no_argument, NULL, 0 }
|
||||
|
@ -270,7 +291,15 @@ do_format(int argc, char** argv)
|
|||
level = optval;
|
||||
break;
|
||||
case 0x1:
|
||||
flags |= CBD_FLAG_DETECT_ZEROS;
|
||||
optval = 1;
|
||||
if (optarg) {
|
||||
if (!parse_boolean_arg(optarg, &optval)) {
|
||||
error("Failed to parse \"%s\"\n", optarg);
|
||||
}
|
||||
}
|
||||
if (optval) {
|
||||
flags |= CBD_FLAG_DETECT_ZEROS;
|
||||
}
|
||||
break;
|
||||
case 0x2:
|
||||
if (!parse_profile(optarg, &pblksize, &lblksize, &alg, &level)) {
|
||||
|
|
Loading…
Reference in New Issue