* This can't be called until all the root_info->path fields are filled
* in by lookup_ino_path
*/
-static int resolve_root(struct root_lookup *rl, struct root_info *ri)
+static int resolve_root(struct root_lookup *rl, struct root_info *ri,
+ u64 top_id)
{
char *full_path = NULL;
int len = 0;
next = found->ref_tree;
+ if (next == top_id) {
+ ri->top_id = top_id;
+ break;
+ }
+
/* if the ref_tree refers to ourselves, we're at the top */
if (next == found->root_id) {
ri->top_id = next;
return ri->ogen == data;
}
+static int filter_topid_equal(struct root_info *ri, u64 data)
+{
+ return ri->top_id == data;
+}
+
static btrfs_list_filter_func all_filter_funcs[] = {
[BTRFS_LIST_FILTER_ROOTID] = filter_by_rootid,
[BTRFS_LIST_FILTER_SNAPSHOT_ONLY] = filter_snapshot,
[BTRFS_LIST_FILTER_CGEN_MORE] = filter_cgen_more,
[BTRFS_LIST_FILTER_CGEN_LESS] = filter_cgen_less,
[BTRFS_LIST_FILTER_CGEN_EQUAL] = filter_cgen_equal,
+ [BTRFS_LIST_FILTER_TOPID_EQUAL] = filter_topid_equal,
};
struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void)
static void __filter_and_sort_subvol(struct root_lookup *all_subvols,
struct root_lookup *sort_tree,
struct btrfs_list_filter_set *filter_set,
- struct btrfs_list_comparer_set *comp_set)
+ struct btrfs_list_comparer_set *comp_set,
+ int fd)
{
struct rb_node *n;
struct root_info *entry;
int ret;
+ u64 top_id = btrfs_list_get_path_rootid(fd);
root_lookup_init(sort_tree);
while (n) {
entry = rb_entry(n, struct root_info, rb_node);
- resolve_root(all_subvols, entry);
+ resolve_root(all_subvols, entry, top_id);
ret = filter_root(entry, filter_set);
if (ret)
sort_tree_insert(sort_tree, entry, comp_set);
return ret;
__filter_and_sort_subvol(&root_lookup, &root_sort, filter_set,
- comp_set);
+ comp_set, fd);
print_all_volume_info(&root_sort, is_tab_result);
__free_all_subvolumn(&root_lookup);
struct rb_node *n;
char *ret_path = NULL;
int ret;
+ u64 top_id = btrfs_list_get_path_rootid(fd);
ret = __list_subvol_search(fd, &root_lookup);
if (ret < 0)
struct root_info *entry;
entry = rb_entry(n, struct root_info, rb_node);
- resolve_root(&root_lookup, entry);
+ resolve_root(&root_lookup, entry, top_id);
if (entry->root_id == root) {
ret_path = entry->full_path;
entry->full_path = NULL;
return 0;
}
+u64 btrfs_list_get_path_rootid(int fd)
+{
+ int ret;
+ struct btrfs_ioctl_ino_lookup_args args;
+
+ memset(&args, 0, sizeof(args));
+ args.objectid = BTRFS_FIRST_FREE_OBJECTID;
+
+ ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
+ if (ret < 0) {
+ fprintf(stderr,
+ "ERROR: can't perform the search -%s\n",
+ strerror(errno));
+ return ret;
+ }
+ return args.treeid;
+}
BTRFS_LIST_FILTER_CGEN_EQUAL = BTRFS_LIST_FILTER_CGEN,
BTRFS_LIST_FILTER_CGEN_LESS,
BTRFS_LIST_FILTER_CGEN_MORE,
+ BTRFS_LIST_FILTER_TOPID_EQUAL,
BTRFS_LIST_FILTER_MAX,
};
int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
char *btrfs_list_path_for_root(int fd, u64 root);
+u64 btrfs_list_get_path_rootid(int fd);