x(0, replicas, required_argument) \
x(0, encrypted, no_argument) \
x(0, no_passphrase, no_argument) \
-x('L', label, required_argument) \
+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('g', group, 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('f', force, no_argument) \
x('q', quiet, no_argument) \
x('h', help, no_argument)
" --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, --label=label\n"
+ " -L, --fs_label=label\n"
" -U, --uuid=uuid\n"
+ " --superblock_size=size\n"
"\n"
"Device specific options:");
bch2_opts_usage(OPT_DEVICE);
- puts(" -g, --group=label Disk group\n"
+ puts(" -l, --label=label Disk label\n"
"\n"
" -f, --force\n"
" -q, --quiet Only print errors\n"
" -h, --help Display this help and exit\n"
"\n"
"Device specific options must come before corresponding devices, e.g.\n"
- " bcachefs format --group cache /dev/sdb /dev/sdc\n"
+ " bcachefs format --label cache /dev/sdb /dev/sdc\n"
"\n"
"Report bugs to <linux-bcache@vger.kernel.org>");
}
int cmd_format(int argc, char *argv[])
{
darray(struct dev_opts) devices;
+ darray(char *) device_paths;
struct format_opts opts = format_opts_default();
struct dev_opts dev_opts = dev_opts_default(), *dev;
- bool force = false, no_passphrase = false, quiet = false;
+ bool force = false, no_passphrase = false, quiet = false, initialize = true;
unsigned v;
int opt;
darray_init(devices);
+ darray_init(device_paths);
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);
while ((opt = getopt_long(argc, argv,
- "-L:U:fqh",
+ "-L:U:g:fqh",
format_opts,
NULL)) != -1)
switch (opt) {
case O_no_passphrase:
no_passphrase = true;
break;
- case O_label:
+ case O_fs_label:
case 'L':
opts.label = optarg;
break;
case O_fs_size:
if (bch2_strtoull_h(optarg, &dev_opts.size))
die("invalid filesystem size");
+ break;
+ case O_superblock_size:
+ if (bch2_strtouint_h(optarg, &opts.superblock_size))
+ die("invalid filesystem size");
- dev_opts.size >>= 9;
+ opts.superblock_size >>= 9;
break;
case O_bucket_size:
- dev_opts.bucket_size =
- hatoi_validate(optarg, "bucket size");
+ if (bch2_strtoull_h(optarg, &dev_opts.bucket_size))
+ die("bad bucket_size %s", optarg);
break;
- case O_group:
- case 'g':
- dev_opts.group = optarg;
+ case O_label:
+ case 'l':
+ dev_opts.label = optarg;
break;
case O_discard:
dev_opts.discard = true;
dev_opts.durability > BCH_REPLICAS_MAX)
die("invalid durability");
break;
+ case O_version:
+ if (kstrtouint(optarg, 10, &opts.version))
+ die("invalid version");
+ break;
+ case O_no_initialize:
+ initialize = false;
+ break;
case O_no_opt:
+ darray_append(device_paths, optarg);
dev_opts.path = optarg;
darray_append(devices, dev_opts);
dev_opts.size = 0;
exit(EXIT_SUCCESS);
break;
case '?':
- die("unrecognized option %s", optarg);
+ exit(EXIT_FAILURE);
break;
}
if (darray_empty(devices))
die("Please supply a device");
- if (opts.encrypted && !no_passphrase)
+ if (opts.encrypted && !no_passphrase) {
opts.passphrase = read_passphrase_twice("Enter passphrase: ");
+ initialize = false;
+ }
darray_foreach(dev, devices)
dev->fd = open_for_format(dev->path, force);
fs_opts,
opts,
devices.item, darray_size(devices));
+ bch2_opt_strs_free(&fs_opt_strs);
if (!quiet)
bch2_sb_print(sb, false, 1 << BCH_SB_FIELD_members, HUMAN_READABLE);
darray_free(devices);
+ if (initialize) {
+ /*
+ * Start the filesystem once, to allocate the journal and create
+ * the root directory:
+ */
+ struct bch_fs *c = bch2_fs_open(device_paths.item,
+ darray_size(device_paths),
+ bch2_opts_empty());
+ if (IS_ERR(c))
+ die("error opening %s: %s", device_paths.item[0],
+ strerror(-PTR_ERR(c)));
+
+ bch2_fs_stop(c);
+ }
+
+ darray_free(device_paths);
+
return 0;
}