@@ -29,6 +29,7 @@
#include "common/messages.h"
#include "common/open-utils.h"
#include "common/path-utils.h"
+#include "common/btrfs-info.h"
/*
* For a given:
@@ -189,31 +190,57 @@ int get_label_mounted(const char *mount_path, char *labelp)
return 0;
}
-int get_label(const char *btrfs_dev, char *label)
+int get_label(const char *path, char *label)
{
int ret;
+ const struct btrfs_info *bi;
- ret = path_is_reg_or_block_device(btrfs_dev);
- if (!ret)
- ret = get_label_mounted(btrfs_dev, label);
- else if (ret > 0)
- ret = get_label_unmounted(btrfs_dev, label);
+ ret = btrfs_info_find(path, &bi);
+ if (ret == -ENOENT) {
+ error("'%s' is not a btrfs filesystem", path);
+ return -ENOENT;
+ }
+ if (ret < 0) {
+ error("unable to access btrfs filesystem info");
+ return -EINVAL;
+ }
+
+ if (btrfs_info_is_mounted(bi)) {
+ path = btrfs_info_find_valid_path(bi);
+ ret = get_label_mounted(path, label);
+ } else {
+ path = btrfs_info_find_valid_dev(bi);
+ ret = get_label_unmounted(path, label);
+ }
return ret;
}
-int set_label(const char *btrfs_dev, const char *label)
+int set_label(const char *path, const char *label)
{
int ret;
+ const struct btrfs_info *bi;
if (check_label(label))
return -1;
- ret = path_is_reg_or_block_device(btrfs_dev);
- if (!ret)
- ret = set_label_mounted(btrfs_dev, label);
- else if (ret > 0)
- ret = set_label_unmounted(btrfs_dev, label);
+ ret = btrfs_info_find(path, &bi);
+ if (ret == -ENOENT) {
+ error("'%s' is not a btrfs filesystem", path);
+ return -ENOENT;
+ }
+ if (ret < 0) {
+ error("unable to access btrfs filesystem info");
+ return -EINVAL;
+ }
+
+ if (btrfs_info_is_mounted(bi)) {
+ path = btrfs_info_find_valid_path(bi);
+ ret = set_label_mounted(path, label);
+ } else {
+ path = btrfs_info_find_valid_dev(bi);
+ ret = set_label_unmounted(path, label);
+ }
return ret;
}