while (1) {
char *tmp;
u64 next;
+ int add_len;
+
/*
- * ref_tree = 0 indicates the subvolumes
- * has been deleted.
- */
- if (!found->ref_tree)
+ * ref_tree = 0 indicates the subvolumes
+ * has been deleted.
+ */
+ if (!found->ref_tree) {
+ free(full_path);
return -ENOENT;
- int add_len = strlen(found->path);
+ }
+
+ add_len = strlen(found->path);
/* room for / and for null */
tmp = malloc(add_len + 2 + len);
next = found->ref_tree;
- if (next == top_id) {
+ if (next == top_id) {
ri->top_id = top_id;
break;
}
* subvolume was deleted.
*/
found = root_tree_search(rl, next);
- if (!found)
+ if (!found) {
+ free(full_path);
return -ENOENT;
+ }
}
ri->full_path = full_path;
{
struct root_lookup root_lookup;
struct root_lookup root_sort;
- int ret;
- u64 top_id = (full_path ? 0 : btrfs_list_get_path_rootid(fd));
+ int ret = 0;
+ u64 top_id = 0;
+
+ if (full_path)
+ ret = btrfs_list_get_path_rootid(fd, &top_id);
+ if (ret)
+ return ret;
ret = btrfs_list_subvols(fd, &root_lookup);
if (ret)
int btrfs_get_subvol(int fd, struct root_info *the_ri)
{
- int ret = 1, rr;
+ int ret, rr;
struct root_lookup rl;
struct rb_node *rbn;
struct root_info *ri;
- u64 root_id = btrfs_list_get_path_rootid(fd);
+ u64 root_id;
+
+ ret = btrfs_list_get_path_rootid(fd, &root_id);
+ if (ret)
+ return ret;
- if (btrfs_list_subvols(fd, &rl))
+ ret = btrfs_list_subvols(fd, &rl);
+ if (ret)
return ret;
rbn = rb_first(&rl.root);
struct rb_node *n;
char *ret_path = NULL;
int ret;
- u64 top_id = btrfs_list_get_path_rootid(fd);
+ u64 top_id;
+
+ ret = btrfs_list_get_path_rootid(fd, &top_id);
+ if (ret)
+ return ERR_PTR(ret);
ret = __list_subvol_search(fd, &root_lookup);
if (ret < 0)
return 0;
}
-u64 btrfs_list_get_path_rootid(int fd)
+int btrfs_list_get_path_rootid(int fd, u64 *treeid)
{
int ret;
struct btrfs_ioctl_ino_lookup_args args;
strerror(errno));
return ret;
}
- return args.treeid;
+ *treeid = args.treeid;
+ return 0;
}