X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=cmd_format.c;h=4debc285f9101a3df0e8e0c474fbce43a9d00814;hb=0e69c66198aa76c59130747c7f10f5d72e5e2afd;hp=bcd69783f0f74ed5e24a8a573674f2bf147548ba;hpb=d3dc47271bc7a82b96e6441129058831835c0677;p=bcachefs-tools-debian diff --git a/cmd_format.c b/cmd_format.c index bcd6978..4debc28 100644 --- a/cmd_format.c +++ b/cmd_format.c @@ -20,11 +20,10 @@ #include -#include "ccan/darray/darray.h" - #include "cmds.h" #include "libbcachefs.h" #include "crypto.h" +#include "libbcachefs/darray.h" #include "libbcachefs/opts.h" #include "libbcachefs/super-io.h" #include "libbcachefs/util.h" @@ -33,11 +32,12 @@ 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) \ @@ -45,6 +45,7 @@ x(0, version, required_argument) \ x(0, no_initialize, no_argument) \ x('f', force, no_argument) \ x('q', quiet, no_argument) \ +x('v', verbose, no_argument) \ x('h', help, no_argument) static void usage(void) @@ -60,23 +61,25 @@ static void usage(void) " --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" + " -v, --verbose Verbose filesystem initialization\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 "); + "Report bugs to "); } enum { @@ -110,23 +113,20 @@ u64 read_flag_list_or_die(char *opt, const char * const list[], int cmd_format(int argc, char *argv[]) { - darray(struct dev_opts) devices; - darray(char *) device_paths; + DARRAY(struct dev_opts) devices = { 0 }; + DARRAY(char *) device_paths = { 0 }; struct format_opts opts = format_opts_default(); struct dev_opts dev_opts = dev_opts_default(), *dev; - bool force = false, no_passphrase = false, quiet = false, initialize = true; + bool force = false, no_passphrase = false, quiet = false, initialize = true, verbose = false; 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:g:fqh", + "-L:U:g:fqhv", format_opts, NULL)) != -1) switch (opt) { @@ -145,7 +145,7 @@ int cmd_format(int argc, char *argv[]) case O_no_passphrase: no_passphrase = true; break; - case O_label: + case O_fs_label: case 'L': opts.label = optarg; break; @@ -161,16 +161,20 @@ int cmd_format(int argc, char *argv[]) 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; @@ -193,15 +197,17 @@ int cmd_format(int argc, char *argv[]) initialize = false; break; case O_no_opt: - darray_append(device_paths, optarg); + darray_push(&device_paths, optarg); dev_opts.path = optarg; - darray_append(devices, dev_opts); + darray_push(&devices, dev_opts); dev_opts.size = 0; break; case O_quiet: case 'q': quiet = true; break; + case 'v': + verbose = true; case O_help: case 'h': usage(); @@ -212,7 +218,7 @@ int cmd_format(int argc, char *argv[]) break; } - if (darray_empty(devices)) + if (!devices.nr) die("Please supply a device"); if (opts.encrypted && !no_passphrase) { @@ -220,17 +226,26 @@ int cmd_format(int argc, char *argv[]) initialize = false; } - darray_foreach(dev, devices) + darray_for_each(devices, dev) dev->fd = open_for_format(dev->path, force); struct bch_sb *sb = bch2_format(fs_opt_strs, fs_opts, opts, - devices.item, darray_size(devices)); + devices.data, devices.nr); + bch2_opt_strs_free(&fs_opt_strs); + + if (!quiet) { + struct printbuf buf = PRINTBUF; + + buf.human_readable_units = true; - if (!quiet) - bch2_sb_print(sb, false, 1 << BCH_SB_FIELD_members, HUMAN_READABLE); + bch2_sb_to_text(&buf, sb, false, 1 << BCH_SB_FIELD_members); + printf("%s", buf.buf); + + printbuf_exit(&buf); + } free(sb); if (opts.passphrase) { @@ -238,24 +253,29 @@ int cmd_format(int argc, char *argv[]) free(opts.passphrase); } - darray_free(devices); + darray_exit(&devices); if (initialize) { + struct bch_opts mount_opts = bch2_opts_empty(); + + + opt_set(mount_opts, verbose, verbose); + /* * 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()); + struct bch_fs *c = bch2_fs_open(device_paths.data, + device_paths.nr, + mount_opts); if (IS_ERR(c)) - die("error opening %s: %s", device_paths.item, + die("error opening %s: %s", device_paths.data[0], strerror(-PTR_ERR(c))); bch2_fs_stop(c); } - darray_free(device_paths); + darray_exit(&device_paths); return 0; } @@ -269,7 +289,7 @@ static void show_super_usage(void) " -f, --fields=(fields) list of sections to print\n" " -l, --layout print superblock layout\n" " -h, --help display this help and exit\n" - "Report bugs to "); + "Report bugs to "); exit(EXIT_SUCCESS); } @@ -318,7 +338,14 @@ int cmd_show_super(int argc, char *argv[]) if (ret) die("Error opening %s: %s", dev, strerror(-ret)); - bch2_sb_print(sb.sb, print_layout, fields, HUMAN_READABLE); + struct printbuf buf = PRINTBUF; + + buf.human_readable_units = true; + + bch2_sb_to_text(&buf, sb.sb, print_layout, fields); + printf("%s", buf.buf); + bch2_free_super(&sb); + printbuf_exit(&buf); return 0; }