From 85691ebeac9432b4ebb1a268514279a0b2c7c61d Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Wed, 14 May 2014 12:39:07 -0500 Subject: btrfs-progs: mkfs: allow UUID specification at mkfs time Allow the specification of the filesystem UUID at mkfs time. Non-unique unique IDs are rejected. This includes attempting to re-mkfs with the same UUID; if you really want to do that, you can mkfs with a new UUID, then re-mkfs with the one you wanted. (Implemented only for mkfs.btrfs, not btrfs-convert). Signed-off-by: Eric Sandeen [converted help to asciidoc] Signed-off-by: David Sterba --- mkfs.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'mkfs.c') diff --git a/mkfs.c b/mkfs.c index 16e92221..7695c015 100644 --- a/mkfs.c +++ b/mkfs.c @@ -288,6 +288,7 @@ static void print_usage(void) fprintf(stderr, "\t -r --rootdir the source directory\n"); fprintf(stderr, "\t -K --nodiscard do not perform whole device TRIM\n"); fprintf(stderr, "\t -O --features comma separated list of filesystem features\n"); + fprintf(stderr, "\t -U --uuid specify the filesystem UUID\n"); fprintf(stderr, "\t -V --version print the mkfs.btrfs version and exit\n"); fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION); exit(1); @@ -351,6 +352,7 @@ static struct option long_options[] = { { "rootdir", 1, NULL, 'r' }, { "nodiscard", 0, NULL, 'K' }, { "features", 1, NULL, 'O' }, + { "uuid", 0, NULL, 'U' }, { NULL, 0, NULL, 0} }; @@ -1273,11 +1275,12 @@ int main(int ac, char **av) int dev_cnt = 0; int saved_optind; char estr[100]; + char *fs_uuid = NULL; u64 features = DEFAULT_MKFS_FEATURES; while(1) { int c; - c = getopt_long(ac, av, "A:b:fl:n:s:m:d:L:O:r:VMK", + c = getopt_long(ac, av, "A:b:fl:n:s:m:d:L:O:r:U:VMK", long_options, &option_index); if (c < 0) break; @@ -1346,6 +1349,9 @@ int main(int ac, char **av) source_dir = optarg; source_dir_set = 1; break; + case 'U': + fs_uuid = optarg; + break; case 'K': discard = 0; break; @@ -1368,6 +1374,20 @@ int main(int ac, char **av) "The -r option is limited to a single device\n"); exit(1); } + + if (fs_uuid) { + uuid_t dummy_uuid; + + if (uuid_parse(fs_uuid, dummy_uuid) != 0) { + fprintf(stderr, "could not parse UUID: %s\n", fs_uuid); + exit(1); + } + if (!test_uuid_unique(fs_uuid)) { + fprintf(stderr, "non-unique UUID: %s\n", fs_uuid); + exit(1); + } + } + while (dev_cnt-- > 0) { file = av[optind++]; if (is_block_device(file)) @@ -1514,7 +1534,7 @@ int main(int ac, char **av) process_fs_features(features); - ret = make_btrfs(fd, file, label, blocks, dev_block_count, + ret = make_btrfs(fd, file, label, fs_uuid, blocks, dev_block_count, nodesize, leafsize, sectorsize, stripesize, features); if (ret) { -- cgit v1.2.3