btrfs-progs: get_label_mounted to return label instead of print

This would help to reuse the function

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
Anand Jain 2013-07-15 13:30:54 +08:00 committed by David Sterba
parent b8e23d4fb2
commit b3a9a3c94a
2 changed files with 14 additions and 5 deletions

18
utils.c
View File

@ -1330,7 +1330,7 @@ static int get_label_unmounted(const char *dev)
* mounted path rather than device. Return the corresponding error
* the user specified the device path.
*/
static int get_label_mounted(const char *mount_path)
int get_label_mounted(const char *mount_path, char *labelp)
{
char label[BTRFS_LABEL_SIZE];
int fd;
@ -1348,16 +1348,24 @@ static int get_label_mounted(const char *mount_path)
return -1;
}
fprintf(stdout, "%s\n", label);
strncpy(labelp, label, sizeof(label));
close(fd);
return 0;
}
int get_label(const char *btrfs_dev)
{
return is_existing_blk_or_reg_file(btrfs_dev) ?
get_label_unmounted(btrfs_dev) :
get_label_mounted(btrfs_dev);
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_mounted(btrfs_dev, label);
if (!ret)
fprintf(stdout, "%s\n", label);
}
return ret;
}
int set_label(const char *btrfs_dev, const char *label)

View File

@ -78,4 +78,5 @@ u64 btrfs_device_size(int fd, struct stat *st);
#define strncpy_null(dest, src) __strncpy__null(dest, src, sizeof(dest))
int test_dev_for_mkfs(char *file, int force_overwrite, char *estr);
int scan_for_btrfs(int where, int update_kernel);
int get_label_mounted(const char *mount_path, char *labelp);
#endif