From: Filipe David Borba Manana Date: Tue, 12 Nov 2013 13:41:42 +0000 (+0000) Subject: Btrfs-progs: let get_label return the label instead of printing it X-Git-Tag: upstream/4.16.1~3020 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=457b1286dd9976efbfec25bb286ddc8cec410aa1;p=platform%2Fupstream%2Fbtrfs-progs.git Btrfs-progs: let get_label return the label instead of printing it 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 Signed-off-by: David Sterba Signed-off-by: Chris Mason --- diff --git a/cmds-filesystem.c b/cmds-filesystem.c index ef426d30..67834389 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -896,10 +896,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 2422338b..c46e09a4 100644 --- a/utils.c +++ b/utils.c @@ -1345,7 +1345,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; @@ -1368,7 +1368,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); @@ -1403,18 +1403,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 6f4b10c1..b38bd3a2 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);