-#include "opts.h"
-#include "util.h"
-
-/* Open a block device, do magic blkid stuff: */
-static int open_for_format(const char *dev, bool force)
-{
- blkid_probe pr;
- const char *fs_type = NULL, *fs_label = NULL;
- size_t fs_type_len, fs_label_len;
-
- int fd = xopen(dev, O_RDWR|O_EXCL);
-
- if (force)
- return fd;
-
- if (!(pr = blkid_new_probe()))
- die("blkid error 1");
- if (blkid_probe_set_device(pr, fd, 0, 0))
- die("blkid error 2");
- if (blkid_probe_enable_partitions(pr, true))
- die("blkid error 3");
- if (blkid_do_fullprobe(pr) < 0)
- die("blkid error 4");
-
- blkid_probe_lookup_value(pr, "TYPE", &fs_type, &fs_type_len);
- blkid_probe_lookup_value(pr, "LABEL", &fs_label, &fs_label_len);
-
- if (fs_type) {
- if (fs_label)
- printf("%s contains a %s filesystem labelled '%s'\n",
- dev, fs_type, fs_label);
- else
- printf("%s contains a %s filesystem\n",
- dev, fs_type);
- fputs("Proceed anyway?", stdout);
- if (!ask_yn())
- exit(EXIT_FAILURE);
- }
-
- blkid_free_probe(pr);
- return fd;
-}
-
-#define OPTS \
-t("bcache format - create a new bcache filesystem on one or more devices") \
-t("Usage: bcache format [OPTION]... <devices>") \
-t("") \
-x('b', block_size, "size", NULL) \
-x(0, btree_node_size, "size", "Default 256k") \
-x(0, metadata_checksum_type, "(none|crc32c|crc64)", NULL) \
-x(0, data_checksum_type, "(none|crc32c|crc64)", NULL) \
-x(0, compression_type, "(none|lz4|gzip)", NULL) \
-x(0, data_replicas, "#", NULL) \
-x(0, metadata_replicas, "#", NULL) \
-x(0, encrypted, NULL, "Enable whole filesystem encryption (chacha20/poly1305)")\
-x(0, no_passphrase, NULL, "Don't encrypt master encryption key")\
-x('e', error_action, "(continue|readonly|panic)", NULL) \
-x(0, max_journal_entry_size, "size", NULL) \
-x('L', label, "label", NULL) \
-x('U', uuid, "uuid", NULL) \
-x('f', force, NULL, NULL) \
-t("") \
-t("Device specific options:") \
-x(0, fs_size, "size", "Size of filesystem on device")\
-x(0, bucket_size, "size", "Bucket size") \
-x('t', tier, "#", "Higher tier indicates slower devices")\
-x(0, discard, NULL, NULL) \
-t("Device specific options must come before corresponding devices, e.g.") \
-t(" bcache format --tier 0 /dev/sdb --tier 1 /dev/sdc") \
-t("") \
-x('h', help, NULL, "display this help and exit")
+#include "libbcachefs/darray.h"
+#include "libbcachefs/errcode.h"
+#include "libbcachefs/opts.h"
+#include "libbcachefs/super-io.h"
+#include "libbcachefs/util.h"
+
+#define OPTS \
+x(0, replicas, required_argument) \
+x(0, encrypted, no_argument) \
+x(0, no_passphrase, no_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('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('v', verbose, no_argument) \
+x('h', help, no_argument)