From: Goffredo Baroncelli <kreijack@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Goffredo Baroncelli <kreijack@inwind.it>
Subject: [PATCH 5/8] Return the fsid from make_btrfs()
Date: Wed, 17 Dec 2014 21:14:09 +0100 [thread overview]
Message-ID: <1418847252-14184-6-git-send-email-kreijack@inwind.it> (raw)
In-Reply-To: <1418847252-14184-1-git-send-email-kreijack@inwind.it>
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>
---
mkfs.c | 7 ++++---
utils.c | 7 ++++++-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/mkfs.c b/mkfs.c
index 042d12e..70c88ea 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1281,7 +1281,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 = DEFAULT_MKFS_FEATURES;
while(1) {
@@ -1356,7 +1356,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;
@@ -1387,7 +1388,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 3f50e4d..c7f1b2f 100644
--- a/utils.c
+++ b/utils.c
@@ -203,7 +203,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;
@@ -216,6 +216,11 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
}
} else {
uuid_generate(super.fsid);
+ /*
+ * if the fs_uuid is a valid pointer, return the generated uuid
+ */
+ if (fs_uuid)
+ uuid_unparse(super.fsid, fs_uuid);
}
uuid_generate(super.dev_item.uuid);
uuid_generate(chunk_tree_uuid);
--
2.1.3
next prev parent reply other threads:[~2014-12-17 20:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-17 20:14 [PATCH V2][BTRFS-PROGS] Improve output of mkfs.btrfs command Goffredo Baroncelli
2014-12-17 20:14 ` [PATCH 1/8] Add -v -q switches to mkfs.btrfs Goffredo Baroncelli
2014-12-25 1:19 ` Satoru Takeuchi
2014-12-17 20:14 ` [PATCH 2/8] Move group_profile_str() in utils.c Goffredo Baroncelli
2014-12-25 1:20 ` Satoru Takeuchi
2014-12-17 20:14 ` [PATCH 3/8] Add verbose option to btrfs_add_to_fsid() Goffredo Baroncelli
2014-12-25 1:28 ` Satoru Takeuchi
2014-12-17 20:14 ` [PATCH 4/8] Add strdup in btrfs_add_to_fsid() to track the device path Goffredo Baroncelli
2014-12-25 1:29 ` Satoru Takeuchi
2014-12-17 20:14 ` Goffredo Baroncelli [this message]
2014-12-25 2:44 ` [PATCH 5/8] Return the fsid from make_btrfs() Satoru Takeuchi
2014-12-25 9:22 ` Goffredo Baroncelli
2014-12-17 20:14 ` [PATCH 6/8] Track the size of the chunk created Goffredo Baroncelli
2014-12-17 20:14 ` [PATCH 7/8] Print the summary Goffredo Baroncelli
2014-12-17 20:14 ` [PATCH 8/8] Add -v and -q switches in the mkfs.btrfs man page Goffredo Baroncelli
2014-12-17 22:38 ` [PATCH V2][BTRFS-PROGS] Improve output of mkfs.btrfs command Martin Steigerwald
2014-12-18 2:28 ` Anand Jain
2015-03-23 23:46 ` David Sterba
2015-03-25 19:07 ` Goffredo Baroncelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1418847252-14184-6-git-send-email-kreijack@inwind.it \
--to=kreijack@gmail.com \
--cc=kreijack@inwind.it \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).