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.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/c_src/cmd_format.c b/c_src/cmd_format.c
index d0c56882..873c1a69 100644
--- a/c_src/cmd_format.c
+++ b/c_src/cmd_format.c
@@ -21,6 +21,8 @@
#include <uuid/uuid.h>
#include "cmds.h"
+#include "cmd_super.h"
+#include "tools-util.h"
#include "posix_to_bcachefs.h"
#include "libbcachefs.h"
#include "crypto.h"
@@ -34,6 +36,7 @@
#define OPTS \
x(0, replicas, required_argument) \
x(0, encrypted, no_argument) \
+x(0, passphrase_file, required_argument) \
x(0, no_passphrase, no_argument) \
x('L', fs_label, required_argument) \
x('U', uuid, required_argument) \
@@ -59,10 +62,12 @@ static void format_usage(void)
puts(" --replicas=# Sets both data and metadata replicas\n"
" --encrypted Enable whole filesystem encryption (chacha20/poly1305)\n"
+ " --passphrase_file=file File containing passphrase used for encryption/decryption\n"
" --no_passphrase Don't encrypt master encryption key\n"
" -L, --fs_label=label\n"
" -U, --uuid=uuid\n"
" --superblock_size=size\n"
+ " --version=version Create filesystem with specified on disk format version instead of the latest\n"
" --source=path Initialize the bcachefs filesystem from this root directory\n"
"\n"
"Device specific options:");
@@ -102,12 +107,12 @@ static const struct option format_opts[] = {
};
#undef x
-static void build_fs(struct bch_fs *c, const char *src_path)
+static int build_fs(struct bch_fs *c, const char *src_path)
{
struct copy_fs_state s = {};
int src_fd = xopen(src_path, O_RDONLY|O_NOATIME);
- copy_fs(c, src_fd, src_path, &s, 0);
+ return copy_fs(c, &s, src_fd, src_path);
}
int cmd_format(int argc, char *argv[])
@@ -173,6 +178,9 @@ int cmd_format(int argc, char *argv[])
case O_encrypted:
opts.encrypted = true;
break;
+ case O_passphrase_file:
+ opts.passphrase_file = optarg;
+ break;
case O_no_passphrase:
no_passphrase = true;
break;
@@ -241,14 +249,27 @@ int cmd_format(int argc, char *argv[])
if (unconsumed_dev_option)
die("Options for devices apply to subsequent devices; got a device option with no device");
- if (!devices.nr)
+ if (!devices.nr) {
+ format_usage();
die("Please supply a device");
+ }
if (opts.source && !initialize)
die("--source, --no_initialize are incompatible");
+ if (opts.passphrase_file && !opts.encrypted)
+ die("--passphrase_file, requires --encrypted set");
+
+ if (opts.passphrase_file && no_passphrase) {
+ die("--passphrase_file, --no_passphrase are incompatible");
+ }
+
if (opts.encrypted && !no_passphrase) {
- opts.passphrase = read_passphrase_twice("Enter passphrase: ");
+ if (opts.passphrase_file) {
+ opts.passphrase = read_file_str(AT_FDCWD, opts.passphrase_file);
+ } else {
+ opts.passphrase = read_passphrase_twice("Enter passphrase: ");
+ }
initialize = false;
}
@@ -276,7 +297,7 @@ int cmd_format(int argc, char *argv[])
struct printbuf buf = PRINTBUF;
buf.human_readable_units = true;
- bch2_sb_to_text(&buf, sb, false, 1 << BCH_SB_FIELD_members_v2);
+ bch2_sb_to_text_with_names(&buf, sb, false, 1 << BCH_SB_FIELD_members_v2, -1);
printf("%s", buf.buf);
printbuf_exit(&buf);
}