+ ret = list_subvol_fill_paths(fd, root_lookup);
+ return ret;
+}
+
+int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
+ struct btrfs_list_comparer_set *comp_set,
+ enum btrfs_list_layout layout, int full_path,
+ const char *raw_prefix)
+{
+ struct root_lookup root_lookup;
+ struct root_lookup root_sort;
+ 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)
+ return ret;
+ filter_and_sort_subvol(&root_lookup, &root_sort, filter_set,
+ comp_set, top_id);
+
+ print_all_subvol_info(&root_sort, layout, raw_prefix);
+ rb_free_nodes(&root_lookup.root, free_root_info);
+
+ return 0;
+}
+
+static char *strdup_or_null(const char *s)
+{
+ if (!s)
+ return NULL;
+ return strdup(s);
+}
+
+int btrfs_get_toplevel_subvol(int fd, struct root_info *the_ri)
+{
+ int ret;
+ struct root_lookup rl;
+ struct rb_node *rbn;
+ struct root_info *ri;
+ u64 root_id;
+
+ ret = btrfs_list_get_path_rootid(fd, &root_id);
+ if (ret)
+ return ret;
+
+ ret = btrfs_list_subvols(fd, &rl);
+ if (ret)
+ return ret;
+
+ rbn = rb_first(&rl.root);
+ ri = rb_entry(rbn, struct root_info, rb_node);
+
+ if (ri->root_id != BTRFS_FS_TREE_OBJECTID)
+ return -ENOENT;
+
+ memcpy(the_ri, ri, offsetof(struct root_info, path));
+ the_ri->path = strdup_or_null("/");
+ the_ri->name = strdup_or_null("<FS_TREE>");
+ the_ri->full_path = strdup_or_null("/");
+ rb_free_nodes(&rl.root, free_root_info);
+
+ return ret;
+}
+
+int btrfs_get_subvol(int fd, struct root_info *the_ri)
+{
+ int ret, rr;
+ struct root_lookup rl;
+ struct rb_node *rbn;
+ struct root_info *ri;
+ u64 root_id;
+
+ ret = btrfs_list_get_path_rootid(fd, &root_id);
+ if (ret)
+ return ret;
+
+ ret = btrfs_list_subvols(fd, &rl);
+ if (ret)