summaryrefslogtreecommitdiff
path: root/c_src/cmd_format.c
diff options
context:
space:
mode:
Diffstat (limited to 'c_src/cmd_format.c')
-rw-r--r--c_src/cmd_format.c94
1 files changed, 51 insertions, 43 deletions
diff --git a/c_src/cmd_format.c b/c_src/cmd_format.c
index b103d2bd..4fbf3a4b 100644
--- a/c_src/cmd_format.c
+++ b/c_src/cmd_format.c
@@ -39,11 +39,7 @@ x('L', fs_label, required_argument) \
x('U', uuid, required_argument) \
x(0, fs_size, required_argument) \
x(0, superblock_size, required_argument) \
-x(0, bucket_size, required_argument) \
x('l', label, required_argument) \
-x(0, discard, no_argument) \
-x(0, data_allowed, required_argument) \
-x(0, durability, required_argument) \
x(0, version, required_argument) \
x(0, no_initialize, no_argument) \
x(0, source, required_argument) \
@@ -52,17 +48,16 @@ x('q', quiet, no_argument) \
x('v', verbose, no_argument) \
x('h', help, no_argument)
-static void usage(void)
+static void format_usage(void)
{
puts("bcachefs format - create a new bcachefs filesystem on one or more devices\n"
"Usage: bcachefs format [OPTION]... <devices>\n"
"\n"
"Options:");
- bch2_opts_usage(OPT_FORMAT);
+ bch2_opts_usage(OPT_FORMAT|OPT_FS);
- puts(
- " --replicas=# Sets both data and metadata replicas\n"
+ puts(" --replicas=# Sets both data and metadata replicas\n"
" --encrypted Enable whole filesystem encryption (chacha20/poly1305)\n"
" --no_passphrase Don't encrypt master encryption key\n"
" -L, --fs_label=label\n"
@@ -72,9 +67,10 @@ static void usage(void)
"\n"
"Device specific options:");
- bch2_opts_usage(OPT_DEVICE);
+ bch2_opts_usage(OPT_FORMAT|OPT_DEVICE);
- puts(" -l, --label=label Disk label\n"
+ puts(" --fs_size=size Size of filesystem on device\n"
+ " -l, --label=label Disk label\n"
"\n"
" -f, --force\n"
" -q, --quiet Only print errors\n"
@@ -137,20 +133,48 @@ int cmd_format(int argc, char *argv[])
bool force = false, no_passphrase = false, quiet = false, initialize = true, verbose = false;
bool unconsumed_dev_option = false;
unsigned v;
- int opt;
- struct bch_opt_strs fs_opt_strs =
- bch2_cmdline_opts_get(&argc, argv, OPT_FORMAT);
- struct bch_opts fs_opts = bch2_parse_opts(fs_opt_strs);
+ struct bch_opt_strs fs_opt_strs = {};
+ struct bch_opts fs_opts = bch2_opts_empty();
if (getenv("BCACHEFS_KERNEL_ONLY"))
initialize = false;
- while ((opt = getopt_long(argc, argv,
- "-L:l:U:g:fqhv",
- format_opts,
- NULL)) != -1)
- switch (opt) {
+ while (true) {
+ const struct bch_option *opt =
+ bch2_cmdline_opt_parse(argc, argv, OPT_FORMAT|OPT_FS|OPT_DEVICE);
+ if (opt) {
+ unsigned id = opt - bch2_opt_table;
+ u64 v;
+ struct printbuf err = PRINTBUF;
+ int ret = bch2_opt_parse(NULL, opt, optarg, &v, &err);
+ if (ret == -BCH_ERR_option_needs_open_fs) {
+ fs_opt_strs.by_id[id] = strdup(optarg);
+ continue;
+ }
+ if (ret)
+ die("invalid option: %s", err.buf);
+
+ if (opt->flags & OPT_DEVICE) {
+ bch2_opt_set_by_id(&dev_opts.opts, id, v);
+ unconsumed_dev_option = true;
+ } else if (opt->flags & OPT_FS) {
+ bch2_opt_set_by_id(&fs_opts, id, v);
+ } else {
+ die("got bch_opt of wrong type %s", opt->attr.name);
+ }
+
+ continue;
+ }
+
+ int optid = getopt_long(argc, argv,
+ "-L:l:U:g:fqhv",
+ format_opts,
+ NULL);
+ if (optid == -1)
+ break;
+
+ switch (optid) {
case O_replicas:
if (kstrtouint(optarg, 10, &v) ||
!v ||
@@ -183,8 +207,9 @@ int cmd_format(int argc, char *argv[])
force = true;
break;
case O_fs_size:
- if (bch2_strtoull_h(optarg, &dev_opts.size))
+ if (bch2_strtoull_h(optarg, &dev_opts.opts.fs_size))
die("invalid filesystem size");
+ dev_opts.opts.fs_size_defined = true;
unconsumed_dev_option = true;
break;
case O_superblock_size:
@@ -193,32 +218,11 @@ int cmd_format(int argc, char *argv[])
opts.superblock_size >>= 9;
break;
- case O_bucket_size:
- if (bch2_strtoull_h(optarg, &dev_opts.bucket_size))
- die("bad bucket_size %s", optarg);
- unconsumed_dev_option = true;
- break;
case O_label:
case 'l':
dev_opts.label = optarg;
unconsumed_dev_option = true;
break;
- case O_discard:
- dev_opts.discard = true;
- unconsumed_dev_option = true;
- break;
- case O_data_allowed:
- dev_opts.data_allowed =
- read_flag_list_or_die(optarg,
- __bch2_data_types, "data type");
- unconsumed_dev_option = true;
- break;
- case O_durability:
- if (kstrtouint(optarg, 10, &dev_opts.durability) ||
- dev_opts.durability > BCH_REPLICAS_MAX)
- die("invalid durability");
- unconsumed_dev_option = true;
- break;
case O_version:
opts.version = version_parse(optarg);
break;
@@ -229,7 +233,8 @@ int cmd_format(int argc, char *argv[])
darray_push(&device_paths, optarg);
dev_opts.path = optarg;
darray_push(&devices, dev_opts);
- dev_opts.size = 0;
+ dev_opts.opts.fs_size = 0;
+ dev_opts.opts.fs_size_defined = 0;
unconsumed_dev_option = false;
break;
case O_quiet:
@@ -241,13 +246,16 @@ int cmd_format(int argc, char *argv[])
break;
case O_help:
case 'h':
- usage();
+ format_usage();
exit(EXIT_SUCCESS);
break;
case '?':
exit(EXIT_FAILURE);
break;
+ default:
+ die("getopt ret %i %c", optid, optid);
}
+ }
if (unconsumed_dev_option)
die("Options for devices apply to subsequent devices; got a device option with no device");