summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoffredo Baroncelli <kreijack@gmail.com>2014-12-17 21:14:09 +0100
committerDavid Sterba <dsterba@suse.cz>2015-06-08 17:50:46 +0200
commitf8a0b85e382ed0f76fd67f65ba5c5697a8468525 (patch)
tree3266ce0d837bad7e49c92f5a6b4e3b92d4ba8078
parentb96345c7ff452fe0b37a503d16072fdebf96d2fd (diff)
btrfs-progs: return the fsid from make_btrfs()
The function make_btrfs() has as argument the fsid of the filesystem. If this fsid is empty or null make_btrfs() generates a new fsid. However If the buffer is valid (but the string is empty) the generated fsid is copied back to the caller. Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
-rw-r--r--mkfs.c7
-rw-r--r--utils.c7
2 files changed, 10 insertions, 4 deletions
diff --git a/mkfs.c b/mkfs.c
index c069d369..962a7cd2 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1142,7 +1142,7 @@ int main(int ac, char **av)
int dev_cnt = 0;
int saved_optind;
char estr[100];
- char *fs_uuid = NULL;
+ char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 };
u64 features = BTRFS_MKFS_DEFAULT_FEATURES;
while(1) {
@@ -1235,7 +1235,8 @@ int main(int ac, char **av)
source_dir_set = 1;
break;
case 'U':
- fs_uuid = optarg;
+ strncpy(fs_uuid, optarg,
+ BTRFS_UUID_UNPARSED_SIZE - 1);
break;
case 'K':
discard = 0;
@@ -1261,7 +1262,7 @@ int main(int ac, char **av)
exit(1);
}
- if (fs_uuid) {
+ if (*fs_uuid) {
uuid_t dummy_uuid;
if (uuid_parse(fs_uuid, dummy_uuid) != 0) {
diff --git a/utils.c b/utils.c
index ef27c51e..f34c27b7 100644
--- a/utils.c
+++ b/utils.c
@@ -169,6 +169,9 @@ int test_uuid_unique(char *fs_uuid)
return unique;
}
+/*
+ * @fs_uuid - if NULL, generates a UUID, returns back the new filesystem UUID
+ */
int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
u64 blocks[7], u64 num_bytes, u32 nodesize,
u32 sectorsize, u32 stripesize, u64 features)
@@ -201,7 +204,7 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
memset(&super, 0, sizeof(super));
num_bytes = (num_bytes / sectorsize) * sectorsize;
- if (fs_uuid) {
+ if (fs_uuid && *fs_uuid) {
if (uuid_parse(fs_uuid, super.fsid) != 0) {
fprintf(stderr, "could not parse UUID: %s\n", fs_uuid);
ret = -EINVAL;
@@ -214,6 +217,8 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
}
} else {
uuid_generate(super.fsid);
+ if (fs_uuid)
+ uuid_unparse(super.fsid, fs_uuid);
}
uuid_generate(super.dev_item.uuid);
uuid_generate(chunk_tree_uuid);