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 <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
This commit is contained in:
Filipe David Borba Manana 2013-11-12 13:41:42 +00:00 committed by Chris Mason
parent 67d3c3c0d3
commit 457b1286dd
3 changed files with 18 additions and 13 deletions

View File

@ -896,10 +896,18 @@ static int cmd_label(int argc, char **argv)
if (check_argc_min(argc, 2) || check_argc_max(argc, 3)) if (check_argc_min(argc, 2) || check_argc_max(argc, 3))
usage(cmd_label_usage); usage(cmd_label_usage);
if (argc > 2) if (argc > 2) {
return set_label(argv[1], argv[2]); return set_label(argv[1], argv[2]);
else } else {
return get_label(argv[1]); 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 = { const struct cmd_group filesystem_cmd_group = {

15
utils.c
View File

@ -1345,7 +1345,7 @@ static int set_label_mounted(const char *mount_path, const char *label)
return 0; return 0;
} }
static int get_label_unmounted(const char *dev) static int get_label_unmounted(const char *dev, char *label)
{ {
struct btrfs_root *root; struct btrfs_root *root;
int ret; int ret;
@ -1368,7 +1368,7 @@ static int get_label_unmounted(const char *dev)
if(!root) if(!root)
return -1; 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. */ /* Now we close it since we are done. */
close_ctree(root); close_ctree(root);
@ -1403,18 +1403,15 @@ int get_label_mounted(const char *mount_path, char *labelp)
return 0; return 0;
} }
int get_label(const char *btrfs_dev) int get_label(const char *btrfs_dev, char *label)
{ {
int ret; int ret;
char label[BTRFS_LABEL_SIZE];
if (is_existing_blk_or_reg_file(btrfs_dev)) if (is_existing_blk_or_reg_file(btrfs_dev))
ret = get_label_unmounted(btrfs_dev); ret = get_label_unmounted(btrfs_dev, label);
else { else
ret = get_label_mounted(btrfs_dev, label); ret = get_label_mounted(btrfs_dev, label);
if (!ret)
fprintf(stdout, "%s\n", label);
}
return ret; return ret;
} }

View File

@ -72,7 +72,7 @@ int open_file_or_dir(const char *fname, DIR **dirstream);
void close_file_or_dir(int fd, 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, int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
struct btrfs_ioctl_dev_info_args **di_ret); 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); int set_label(const char *btrfs_dev, const char *label);
char *__strncpy__null(char *dest, const char *src, size_t n); char *__strncpy__null(char *dest, const char *src, size_t n);