linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Filipe David Borba Manana <fdmanana@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Filipe David Borba Manana <fdmanana@gmail.com>
Subject: [PATCH 1/5] Btrfs-progs: let get_label return the label instead of printing it
Date: Tue, 12 Nov 2013 13:41:42 +0000	[thread overview]
Message-ID: <1384263706-25549-2-git-send-email-fdmanana@gmail.com> (raw)
In-Reply-To: <1384263706-25549-1-git-send-email-fdmanana@gmail.com>

get_label prints the label at the moment. Change this so that
the label is returned and printing is done by the caller.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
---
 cmds-filesystem.c |   14 +++++++++++---
 utils.c           |   15 ++++++---------
 utils.h           |    2 +-
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index d2cad81..9fda41a 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -810,10 +810,18 @@ static int cmd_label(int argc, char **argv)
 	if (check_argc_min(argc, 2) || check_argc_max(argc, 3))
 		usage(cmd_label_usage);
 
-	if (argc > 2)
+	if (argc > 2) {
 		return set_label(argv[1], argv[2]);
-	else
-		return get_label(argv[1]);
+	} else {
+		char label[BTRFS_LABEL_SIZE];
+		int ret;
+
+		ret = get_label(argv[1], label);
+		if (!ret)
+			fprintf(stdout, "%s\n", label);
+
+		return ret;
+	}
 }
 
 const struct cmd_group filesystem_cmd_group = {
diff --git a/utils.c b/utils.c
index 85682d9..9105af1 100644
--- a/utils.c
+++ b/utils.c
@@ -1343,7 +1343,7 @@ static int set_label_mounted(const char *mount_path, const char *label)
 	return 0;
 }
 
-static int get_label_unmounted(const char *dev)
+static int get_label_unmounted(const char *dev, char *label)
 {
 	struct btrfs_root *root;
 	int ret;
@@ -1366,7 +1366,7 @@ static int get_label_unmounted(const char *dev)
 	if(!root)
 		return -1;
 
-	fprintf(stdout, "%s\n", root->fs_info->super_copy->label);
+	memcpy(label, root->fs_info->super_copy->label, BTRFS_LABEL_SIZE);
 
 	/* Now we close it since we are done. */
 	close_ctree(root);
@@ -1401,18 +1401,15 @@ int get_label_mounted(const char *mount_path, char *labelp)
 	return 0;
 }
 
-int get_label(const char *btrfs_dev)
+int get_label(const char *btrfs_dev, char *label)
 {
 	int ret;
-	char label[BTRFS_LABEL_SIZE];
 
 	if (is_existing_blk_or_reg_file(btrfs_dev))
-		ret = get_label_unmounted(btrfs_dev);
-	else {
+		ret = get_label_unmounted(btrfs_dev, label);
+	else
 		ret = get_label_mounted(btrfs_dev, label);
-		if (!ret)
-			fprintf(stdout, "%s\n", label);
-	}
+
 	return ret;
 }
 
diff --git a/utils.h b/utils.h
index 6f4b10c..b38bd3a 100644
--- a/utils.h
+++ b/utils.h
@@ -72,7 +72,7 @@ int open_file_or_dir(const char *fname, DIR **dirstream);
 void close_file_or_dir(int fd, DIR *dirstream);
 int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
 		struct btrfs_ioctl_dev_info_args **di_ret);
-int get_label(const char *btrfs_dev);
+int get_label(const char *btrfs_dev, char *label);
 int set_label(const char *btrfs_dev, const char *label);
 
 char *__strncpy__null(char *dest, const char *src, size_t n);
-- 
1.7.9.5


  reply	other threads:[~2013-11-12 13:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-12 13:41 [PATCH 0/5] Add support for object properties Filipe David Borba Manana
2013-11-12 13:41 ` Filipe David Borba Manana [this message]
2013-11-13 15:43   ` [PATCH 1/5] Btrfs-progs: let get_label return the label instead of printing it David Sterba
2013-11-12 13:41 ` [PATCH 2/5] Btrfs-progs: introduce btrfs property subgroup Filipe David Borba Manana
2013-11-12 13:41 ` [PATCH 3/5] Btrfs-progs: fix detection of root objects in cmds-property.c Filipe David Borba Manana
2013-11-12 13:41 ` [PATCH 4/5] Btrfs-progs: add type root to label property Filipe David Borba Manana
2013-11-12 13:41 ` [PATCH 5/5] Btrfs-progs: add support for the compression property Filipe David Borba Manana
2013-11-13  1:22 ` [PATCH 5/5 V2] " Filipe David Borba Manana
2013-11-13 16:15 ` [PATCH 0/5] Add support for object properties David Sterba
2013-11-23  0:52 ` David Sterba
2013-11-23 10:45   ` Goffredo Baroncelli
2014-01-07 11:51   ` Filipe David Manana
2014-01-23 17:47     ` David Sterba

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=1384263706-25549-2-git-send-email-fdmanana@gmail.com \
    --to=fdmanana@gmail.com \
    --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).