]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - cmd_format.c
Update bcachefs sources to f26267fc82 bcachefs: kill bset_tree->max_key
[bcachefs-tools-debian] / cmd_format.c
index ae83a9770ebc9cc599c37c0411858fe590d57aee..b88ffe91f6c05c8751d285a2293725dfb5d93234 100644 (file)
@@ -36,11 +36,14 @@ x(0,        no_passphrase,          no_argument)            \
 x('L', 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(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)
@@ -60,6 +63,7 @@ static void usage(void)
             "      --no_passphrase         Don't encrypt master encryption key\n"
             "  -L, --label=label\n"
             "  -U, --uuid=uuid\n"
+            "      --superblock_size=size\n"
             "\n"
             "Device specific options:");
 
@@ -112,7 +116,7 @@ int cmd_format(int argc, char *argv[])
        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;
 
@@ -162,6 +166,12 @@ int cmd_format(int argc, char *argv[])
 
                        dev_opts.size >>= 9;
                        break;
+               case O_superblock_size:
+                       if (bch2_strtouint_h(optarg, &opts.superblock_size))
+                               die("invalid filesystem size");
+
+                       opts.superblock_size >>= 9;
+                       break;
                case O_bucket_size:
                        dev_opts.bucket_size =
                                hatoi_validate(optarg, "bucket size");
@@ -183,6 +193,13 @@ int cmd_format(int argc, char *argv[])
                            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;
@@ -206,8 +223,10 @@ int cmd_format(int argc, char *argv[])
        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);
@@ -229,7 +248,7 @@ int cmd_format(int argc, char *argv[])
 
        darray_free(devices);
 
-       if (!opts.passphrase) {
+       if (initialize) {
                /*
                 * Start the filesystem once, to allocate the journal and create
                 * the root directory:
@@ -244,6 +263,8 @@ int cmd_format(int argc, char *argv[])
                bch2_fs_stop(c);
        }
 
+       darray_free(device_paths);
+
        return 0;
 }