2 * Copyright (C) 2010 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
19 #include <sys/ioctl.h>
20 #include <sys/mount.h>
23 #include <sys/types.h>
30 #include "transaction.h"
33 #include <uuid/uuid.h>
34 #include "btrfs-list.h"
35 #include "rbtree-utils.h"
37 #define BTRFS_LIST_NFILTERS_INCREASE (2 * BTRFS_LIST_FILTER_MAX)
38 #define BTRFS_LIST_NCOMPS_INCREASE (2 * BTRFS_LIST_COMP_MAX)
40 /* we store all the roots we find in an rbtree so that we can
41 * search for them later.
47 static inline struct root_info
*to_root_info(struct rb_node
*node
)
49 return rb_entry(node
, struct root_info
, rb_node
);
52 static inline struct root_info
*to_root_info_sorted(struct rb_node
*node
)
54 return rb_entry(node
, struct root_info
, sort_node
);
61 } btrfs_list_columns
[] = {
74 .column_name
= "CGen",
79 .column_name
= "Parent",
84 .column_name
= "Top Level",
89 .column_name
= "OTime",
93 .name
= "parent_uuid",
94 .column_name
= "Parent UUID",
98 .name
= "received_uuid",
99 .column_name
= "Received UUID",
104 .column_name
= "UUID",
109 .column_name
= "Path",
119 static btrfs_list_filter_func all_filter_funcs
[];
120 static btrfs_list_comp_func all_comp_funcs
[];
122 void btrfs_list_setup_print_column(enum btrfs_list_column_enum column
)
126 ASSERT(0 <= column
&& column
<= BTRFS_LIST_ALL
);
128 if (column
< BTRFS_LIST_ALL
) {
129 btrfs_list_columns
[column
].need_print
= 1;
133 for (i
= 0; i
< BTRFS_LIST_ALL
; i
++)
134 btrfs_list_columns
[i
].need_print
= 1;
137 static int comp_entry_with_rootid(struct root_info
*entry1
,
138 struct root_info
*entry2
,
143 if (entry1
->root_id
> entry2
->root_id
)
145 else if (entry1
->root_id
< entry2
->root_id
)
150 return is_descending
? -ret
: ret
;
153 static int comp_entry_with_gen(struct root_info
*entry1
,
154 struct root_info
*entry2
,
159 if (entry1
->gen
> entry2
->gen
)
161 else if (entry1
->gen
< entry2
->gen
)
166 return is_descending
? -ret
: ret
;
169 static int comp_entry_with_ogen(struct root_info
*entry1
,
170 struct root_info
*entry2
,
175 if (entry1
->ogen
> entry2
->ogen
)
177 else if (entry1
->ogen
< entry2
->ogen
)
182 return is_descending
? -ret
: ret
;
185 static int comp_entry_with_path(struct root_info
*entry1
,
186 struct root_info
*entry2
,
191 if (strcmp(entry1
->full_path
, entry2
->full_path
) > 0)
193 else if (strcmp(entry1
->full_path
, entry2
->full_path
) < 0)
198 return is_descending
? -ret
: ret
;
201 static btrfs_list_comp_func all_comp_funcs
[] = {
202 [BTRFS_LIST_COMP_ROOTID
] = comp_entry_with_rootid
,
203 [BTRFS_LIST_COMP_OGEN
] = comp_entry_with_ogen
,
204 [BTRFS_LIST_COMP_GEN
] = comp_entry_with_gen
,
205 [BTRFS_LIST_COMP_PATH
] = comp_entry_with_path
,
208 static char *all_sort_items
[] = {
209 [BTRFS_LIST_COMP_ROOTID
] = "rootid",
210 [BTRFS_LIST_COMP_OGEN
] = "ogen",
211 [BTRFS_LIST_COMP_GEN
] = "gen",
212 [BTRFS_LIST_COMP_PATH
] = "path",
213 [BTRFS_LIST_COMP_MAX
] = NULL
,
216 static int btrfs_list_get_sort_item(char *sort_name
)
220 for (i
= 0; i
< BTRFS_LIST_COMP_MAX
; i
++) {
221 if (strcmp(sort_name
, all_sort_items
[i
]) == 0)
227 struct btrfs_list_comparer_set
*btrfs_list_alloc_comparer_set(void)
229 struct btrfs_list_comparer_set
*set
;
232 size
= sizeof(struct btrfs_list_comparer_set
) +
233 BTRFS_LIST_NCOMPS_INCREASE
* sizeof(struct btrfs_list_comparer
);
234 set
= calloc(1, size
);
236 fprintf(stderr
, "memory allocation failed\n");
240 set
->total
= BTRFS_LIST_NCOMPS_INCREASE
;
245 static int btrfs_list_setup_comparer(struct btrfs_list_comparer_set
**comp_set
,
246 enum btrfs_list_comp_enum comparer
, int is_descending
)
248 struct btrfs_list_comparer_set
*set
= *comp_set
;
252 ASSERT(comparer
< BTRFS_LIST_COMP_MAX
);
253 ASSERT(set
->ncomps
<= set
->total
);
255 if (set
->ncomps
== set
->total
) {
258 size
= set
->total
+ BTRFS_LIST_NCOMPS_INCREASE
;
259 size
= sizeof(*set
) + size
* sizeof(struct btrfs_list_comparer
);
261 set
= realloc(set
, size
);
263 fprintf(stderr
, "memory allocation failed\n");
268 memset(&set
->comps
[set
->total
], 0,
269 BTRFS_LIST_NCOMPS_INCREASE
*
270 sizeof(struct btrfs_list_comparer
));
271 set
->total
+= BTRFS_LIST_NCOMPS_INCREASE
;
275 ASSERT(set
->comps
[set
->ncomps
].comp_func
== NULL
);
277 set
->comps
[set
->ncomps
].comp_func
= all_comp_funcs
[comparer
];
278 set
->comps
[set
->ncomps
].is_descending
= is_descending
;
283 static int sort_comp(struct root_info
*entry1
, struct root_info
*entry2
,
284 struct btrfs_list_comparer_set
*set
)
286 int rootid_compared
= 0;
289 if (!set
|| !set
->ncomps
)
290 return comp_entry_with_rootid(entry1
, entry2
, 0);
292 for (i
= 0; i
< set
->ncomps
; i
++) {
293 if (!set
->comps
[i
].comp_func
)
296 ret
= set
->comps
[i
].comp_func(entry1
, entry2
,
297 set
->comps
[i
].is_descending
);
301 if (set
->comps
[i
].comp_func
== comp_entry_with_rootid
)
305 if (!rootid_compared
)
306 ret
= comp_entry_with_rootid(entry1
, entry2
, 0);
311 static int sort_tree_insert(struct root_lookup
*sort_tree
,
312 struct root_info
*ins
,
313 struct btrfs_list_comparer_set
*comp_set
)
315 struct rb_node
**p
= &sort_tree
->root
.rb_node
;
316 struct rb_node
*parent
= NULL
;
317 struct root_info
*curr
;
322 curr
= to_root_info_sorted(parent
);
324 ret
= sort_comp(ins
, curr
, comp_set
);
333 rb_link_node(&ins
->sort_node
, parent
, p
);
334 rb_insert_color(&ins
->sort_node
, &sort_tree
->root
);
339 * insert a new root into the tree. returns the existing root entry
340 * if one is already there. Both root_id and ref_tree are used
343 static int root_tree_insert(struct root_lookup
*root_tree
,
344 struct root_info
*ins
)
346 struct rb_node
**p
= &root_tree
->root
.rb_node
;
347 struct rb_node
* parent
= NULL
;
348 struct root_info
*curr
;
353 curr
= to_root_info(parent
);
355 ret
= comp_entry_with_rootid(ins
, curr
, 0);
364 rb_link_node(&ins
->rb_node
, parent
, p
);
365 rb_insert_color(&ins
->rb_node
, &root_tree
->root
);
370 * find a given root id in the tree. We return the smallest one,
371 * rb_next can be used to move forward looking for more if required
373 static struct root_info
*root_tree_search(struct root_lookup
*root_tree
,
376 struct rb_node
*n
= root_tree
->root
.rb_node
;
377 struct root_info
*entry
;
378 struct root_info tmp
;
381 tmp
.root_id
= root_id
;
384 entry
= to_root_info(n
);
386 ret
= comp_entry_with_rootid(&tmp
, entry
, 0);
397 static int update_root(struct root_lookup
*root_lookup
,
398 u64 root_id
, u64 ref_tree
, u64 root_offset
, u64 flags
,
399 u64 dir_id
, char *name
, int name_len
, u64 ogen
, u64 gen
,
400 time_t otime
, u8
*uuid
, u8
*puuid
, u8
*ruuid
)
402 struct root_info
*ri
;
404 ri
= root_tree_search(root_lookup
, root_id
);
405 if (!ri
|| ri
->root_id
!= root_id
)
407 if (name
&& name_len
> 0) {
410 ri
->name
= malloc(name_len
+ 1);
412 fprintf(stderr
, "memory allocation failed\n");
415 strncpy(ri
->name
, name
, name_len
);
416 ri
->name
[name_len
] = 0;
419 ri
->ref_tree
= ref_tree
;
421 ri
->root_offset
= root_offset
;
430 if (!ri
->ogen
&& root_offset
)
431 ri
->ogen
= root_offset
;
435 memcpy(&ri
->uuid
, uuid
, BTRFS_UUID_SIZE
);
437 memcpy(&ri
->puuid
, puuid
, BTRFS_UUID_SIZE
);
439 memcpy(&ri
->ruuid
, ruuid
, BTRFS_UUID_SIZE
);
445 * add_root - update the existed root, or allocate a new root and insert it
446 * into the lookup tree.
447 * root_id: object id of the root
448 * ref_tree: object id of the referring root.
449 * root_offset: offset value of the root'key
450 * dir_id: inode id of the directory in ref_tree where this root can be found.
451 * name: the name of root_id in that directory
452 * name_len: the length of name
453 * ogen: the original generation of the root
454 * gen: the current generation of the root
455 * otime: the original time (creation time) of the root
456 * uuid: uuid of the root
457 * puuid: uuid of the root parent if any
458 * ruuid: uuid of the received subvol, if any
460 static int add_root(struct root_lookup
*root_lookup
,
461 u64 root_id
, u64 ref_tree
, u64 root_offset
, u64 flags
,
462 u64 dir_id
, char *name
, int name_len
, u64 ogen
, u64 gen
,
463 time_t otime
, u8
*uuid
, u8
*puuid
, u8
*ruuid
)
465 struct root_info
*ri
;
468 ret
= update_root(root_lookup
, root_id
, ref_tree
, root_offset
, flags
,
469 dir_id
, name
, name_len
, ogen
, gen
, otime
,
474 ri
= calloc(1, sizeof(*ri
));
476 printf("memory allocation failed\n");
479 ri
->root_id
= root_id
;
481 if (name
&& name_len
> 0) {
482 ri
->name
= malloc(name_len
+ 1);
484 fprintf(stderr
, "memory allocation failed\n");
487 strncpy(ri
->name
, name
, name_len
);
488 ri
->name
[name_len
] = 0;
491 ri
->ref_tree
= ref_tree
;
495 ri
->root_offset
= root_offset
;
502 if (!ri
->ogen
&& root_offset
)
503 ri
->ogen
= root_offset
;
508 memcpy(&ri
->uuid
, uuid
, BTRFS_UUID_SIZE
);
511 memcpy(&ri
->puuid
, puuid
, BTRFS_UUID_SIZE
);
514 memcpy(&ri
->ruuid
, ruuid
, BTRFS_UUID_SIZE
);
516 ret
= root_tree_insert(root_lookup
, ri
);
518 error("failed to insert subvolume %llu to tree: %s",
519 (unsigned long long)root_id
, strerror(-ret
));
526 * Simplified add_root for back references, omits the uuid and original info
527 * parameters, root offset and flags.
529 static int add_root_backref(struct root_lookup
*root_lookup
, u64 root_id
,
530 u64 ref_tree
, u64 dir_id
, char *name
, int name_len
)
532 return add_root(root_lookup
, root_id
, ref_tree
, 0, 0, dir_id
, name
,
533 name_len
, 0, 0, 0, NULL
, NULL
, NULL
);
537 static void free_root_info(struct rb_node
*node
)
539 struct root_info
*ri
;
541 ri
= to_root_info(node
);
549 * for a given root_info, search through the root_lookup tree to construct
550 * the full path name to it.
552 * This can't be called until all the root_info->path fields are filled
553 * in by lookup_ino_path
555 static int resolve_root(struct root_lookup
*rl
, struct root_info
*ri
,
558 char *full_path
= NULL
;
560 struct root_info
*found
;
563 * we go backwards from the root_info object and add pathnames
564 * from parent directories as we go.
573 * ref_tree = 0 indicates the subvolume
576 if (!found
->ref_tree
) {
581 add_len
= strlen(found
->path
);
584 /* room for / and for null */
585 tmp
= malloc(add_len
+ 2 + len
);
587 perror("malloc failed");
590 memcpy(tmp
+ add_len
+ 1, full_path
, len
);
592 memcpy(tmp
, found
->path
, add_len
);
593 tmp
[add_len
+ len
+ 1] = '\0';
598 full_path
= strdup(found
->path
);
602 ri
->top_id
= found
->ref_tree
;
604 next
= found
->ref_tree
;
608 * if the ref_tree = BTRFS_FS_TREE_OBJECTID,
611 if (next
== BTRFS_FS_TREE_OBJECTID
)
614 * if the ref_tree wasn't in our tree of roots, the
615 * subvolume was deleted.
617 found
= root_tree_search(rl
, next
);
624 ri
->full_path
= full_path
;
630 * for a single root_info, ask the kernel to give us a path name
631 * inside it's ref_root for the dir_id where it lives.
633 * This fills in root_info->path with the path to the directory and and
634 * appends this root's name.
636 static int lookup_ino_path(int fd
, struct root_info
*ri
)
638 struct btrfs_ioctl_ino_lookup_args args
;
647 memset(&args
, 0, sizeof(args
));
648 args
.treeid
= ri
->ref_tree
;
649 args
.objectid
= ri
->dir_id
;
651 ret
= ioctl(fd
, BTRFS_IOC_INO_LOOKUP
, &args
);
653 if (errno
== ENOENT
) {
657 error("failed to lookup path for root %llu: %m",
658 (unsigned long long)ri
->ref_tree
);
664 * we're in a subdirectory of ref_tree, the kernel ioctl
665 * puts a / in there for us
667 ri
->path
= malloc(strlen(ri
->name
) + strlen(args
.name
) + 1);
669 perror("malloc failed");
672 strcpy(ri
->path
, args
.name
);
673 strcat(ri
->path
, ri
->name
);
675 /* we're at the root of ref_tree */
676 ri
->path
= strdup(ri
->name
);
678 perror("strdup failed");
685 /* finding the generation for a given path is a two step process.
686 * First we use the inode lookup routine to find out the root id
688 * Then we use the tree search ioctl to scan all the root items for a
689 * given root id and spit out the latest generation we can find
691 static u64
find_root_gen(int fd
)
693 struct btrfs_ioctl_ino_lookup_args ino_args
;
695 struct btrfs_ioctl_search_args args
;
696 struct btrfs_ioctl_search_key
*sk
= &args
.key
;
697 struct btrfs_ioctl_search_header sh
;
698 unsigned long off
= 0;
702 memset(&ino_args
, 0, sizeof(ino_args
));
703 ino_args
.objectid
= BTRFS_FIRST_FREE_OBJECTID
;
705 /* this ioctl fills in ino_args->treeid */
706 ret
= ioctl(fd
, BTRFS_IOC_INO_LOOKUP
, &ino_args
);
708 error("failed to lookup path for dirid %llu: %m",
709 (unsigned long long)BTRFS_FIRST_FREE_OBJECTID
);
713 memset(&args
, 0, sizeof(args
));
715 sk
->tree_id
= BTRFS_ROOT_TREE_OBJECTID
;
718 * there may be more than one ROOT_ITEM key if there are
719 * snapshots pending deletion, we have to loop through
722 sk
->min_objectid
= ino_args
.treeid
;
723 sk
->max_objectid
= ino_args
.treeid
;
724 sk
->max_type
= BTRFS_ROOT_ITEM_KEY
;
725 sk
->min_type
= BTRFS_ROOT_ITEM_KEY
;
726 sk
->max_offset
= (u64
)-1;
727 sk
->max_transid
= (u64
)-1;
731 ret
= ioctl(fd
, BTRFS_IOC_TREE_SEARCH
, &args
);
733 error("can't perform the search: %m");
736 /* the ioctl returns the number of item it found in nr_items */
737 if (sk
->nr_items
== 0)
741 for (i
= 0; i
< sk
->nr_items
; i
++) {
742 struct btrfs_root_item
*item
;
744 memcpy(&sh
, args
.buf
+ off
, sizeof(sh
));
746 item
= (struct btrfs_root_item
*)(args
.buf
+ off
);
749 sk
->min_objectid
= sh
.objectid
;
750 sk
->min_type
= sh
.type
;
751 sk
->min_offset
= sh
.offset
;
753 if (sh
.objectid
> ino_args
.treeid
)
756 if (sh
.objectid
== ino_args
.treeid
&&
757 sh
.type
== BTRFS_ROOT_ITEM_KEY
) {
758 max_found
= max(max_found
,
759 btrfs_root_generation(item
));
762 if (sk
->min_offset
< (u64
)-1)
767 if (sk
->min_type
!= BTRFS_ROOT_ITEM_KEY
)
769 if (sk
->min_objectid
!= ino_args
.treeid
)
775 /* pass in a directory id and this will return
776 * the full path of the parent directory inside its
779 * It may return NULL if it is in the root, or an ERR_PTR if things
782 static char *__ino_resolve(int fd
, u64 dirid
)
784 struct btrfs_ioctl_ino_lookup_args args
;
788 memset(&args
, 0, sizeof(args
));
789 args
.objectid
= dirid
;
791 ret
= ioctl(fd
, BTRFS_IOC_INO_LOOKUP
, &args
);
793 error("failed to lookup path for dirid %llu: %m",
794 (unsigned long long)dirid
);
800 * we're in a subdirectory of ref_tree, the kernel ioctl
801 * puts a / in there for us
803 full
= strdup(args
.name
);
805 perror("malloc failed");
806 return ERR_PTR(-ENOMEM
);
809 /* we're at the root of ref_tree */
816 * simple string builder, returning a new string with both
819 static char *build_name(const char *dirid
, const char *name
)
826 full
= malloc(strlen(dirid
) + strlen(name
) + 1);
835 * given an inode number, this returns the full path name inside the subvolume
836 * to that file/directory. cache_dirid and cache_name are used to
837 * cache the results so we can avoid tree searches if a later call goes
838 * to the same directory or file name
840 static char *ino_resolve(int fd
, u64 ino
, u64
*cache_dirid
, char **cache_name
)
848 struct btrfs_ioctl_search_args args
;
849 struct btrfs_ioctl_search_key
*sk
= &args
.key
;
850 struct btrfs_ioctl_search_header
*sh
;
851 unsigned long off
= 0;
854 memset(&args
, 0, sizeof(args
));
859 * step one, we search for the inode back ref. We just use the first
862 sk
->min_objectid
= ino
;
863 sk
->max_objectid
= ino
;
864 sk
->max_type
= BTRFS_INODE_REF_KEY
;
865 sk
->max_offset
= (u64
)-1;
866 sk
->min_type
= BTRFS_INODE_REF_KEY
;
867 sk
->max_transid
= (u64
)-1;
870 ret
= ioctl(fd
, BTRFS_IOC_TREE_SEARCH
, &args
);
872 error("can't perform the search: %m");
875 /* the ioctl returns the number of item it found in nr_items */
876 if (sk
->nr_items
== 0)
880 sh
= (struct btrfs_ioctl_search_header
*)(args
.buf
+ off
);
882 if (btrfs_search_header_type(sh
) == BTRFS_INODE_REF_KEY
) {
883 struct btrfs_inode_ref
*ref
;
884 dirid
= btrfs_search_header_offset(sh
);
886 ref
= (struct btrfs_inode_ref
*)(sh
+ 1);
887 namelen
= btrfs_stack_inode_ref_name_len(ref
);
889 name
= (char *)(ref
+ 1);
890 name
= strndup(name
, namelen
);
892 /* use our cached value */
893 if (dirid
== *cache_dirid
&& *cache_name
) {
894 dirname
= *cache_name
;
901 * the inode backref gives us the file name and the parent directory id.
902 * From here we use __ino_resolve to get the path to the parent
904 dirname
= __ino_resolve(fd
, dirid
);
906 full
= build_name(dirname
, name
);
907 if (*cache_name
&& dirname
!= *cache_name
)
910 *cache_name
= dirname
;
911 *cache_dirid
= dirid
;
917 int btrfs_list_get_default_subvolume(int fd
, u64
*default_id
)
919 struct btrfs_ioctl_search_args args
;
920 struct btrfs_ioctl_search_key
*sk
= &args
.key
;
921 struct btrfs_ioctl_search_header
*sh
;
925 memset(&args
, 0, sizeof(args
));
928 * search for a dir item with a name 'default' in the tree of
929 * tree roots, it should point us to a default root
931 sk
->tree_id
= BTRFS_ROOT_TREE_OBJECTID
;
933 /* don't worry about ancient format and request only one item */
936 sk
->max_objectid
= BTRFS_ROOT_TREE_DIR_OBJECTID
;
937 sk
->min_objectid
= BTRFS_ROOT_TREE_DIR_OBJECTID
;
938 sk
->max_type
= BTRFS_DIR_ITEM_KEY
;
939 sk
->min_type
= BTRFS_DIR_ITEM_KEY
;
940 sk
->max_offset
= (u64
)-1;
941 sk
->max_transid
= (u64
)-1;
943 ret
= ioctl(fd
, BTRFS_IOC_TREE_SEARCH
, &args
);
947 /* the ioctl returns the number of items it found in nr_items */
948 if (sk
->nr_items
== 0)
951 sh
= (struct btrfs_ioctl_search_header
*)args
.buf
;
953 if (btrfs_search_header_type(sh
) == BTRFS_DIR_ITEM_KEY
) {
954 struct btrfs_dir_item
*di
;
958 di
= (struct btrfs_dir_item
*)(sh
+ 1);
959 name_len
= btrfs_stack_dir_name_len(di
);
960 name
= (char *)(di
+ 1);
962 if (!strncmp("default", name
, name_len
))
963 found
= btrfs_disk_key_objectid(&di
->location
);
971 static int list_subvol_search(int fd
, struct root_lookup
*root_lookup
)
974 struct btrfs_ioctl_search_args args
;
975 struct btrfs_ioctl_search_key
*sk
= &args
.key
;
976 struct btrfs_ioctl_search_header sh
;
977 struct btrfs_root_ref
*ref
;
978 struct btrfs_root_item
*ri
;
988 root_lookup
->root
.rb_node
= NULL
;
989 memset(&args
, 0, sizeof(args
));
991 sk
->tree_id
= BTRFS_ROOT_TREE_OBJECTID
;
992 /* Search both live and deleted subvolumes */
993 sk
->min_type
= BTRFS_ROOT_ITEM_KEY
;
994 sk
->max_type
= BTRFS_ROOT_BACKREF_KEY
;
995 sk
->min_objectid
= BTRFS_FS_TREE_OBJECTID
;
996 sk
->max_objectid
= BTRFS_LAST_FREE_OBJECTID
;
997 sk
->max_offset
= (u64
)-1;
998 sk
->max_transid
= (u64
)-1;
1001 sk
->nr_items
= 4096;
1002 ret
= ioctl(fd
, BTRFS_IOC_TREE_SEARCH
, &args
);
1005 if (sk
->nr_items
== 0)
1011 * for each item, pull the key out of the header and then
1012 * read the root_ref item it contains
1014 for (i
= 0; i
< sk
->nr_items
; i
++) {
1015 memcpy(&sh
, args
.buf
+ off
, sizeof(sh
));
1017 if (sh
.type
== BTRFS_ROOT_BACKREF_KEY
) {
1018 ref
= (struct btrfs_root_ref
*)(args
.buf
+ off
);
1019 name_len
= btrfs_stack_root_ref_name_len(ref
);
1020 name
= (char *)(ref
+ 1);
1021 dir_id
= btrfs_stack_root_ref_dirid(ref
);
1023 add_root_backref(root_lookup
, sh
.objectid
,
1024 sh
.offset
, dir_id
, name
,
1026 } else if (sh
.type
== BTRFS_ROOT_ITEM_KEY
&&
1027 (sh
.objectid
>= BTRFS_FIRST_FREE_OBJECTID
||
1028 sh
.objectid
== BTRFS_FS_TREE_OBJECTID
)) {
1030 u8 uuid
[BTRFS_UUID_SIZE
];
1031 u8 puuid
[BTRFS_UUID_SIZE
];
1032 u8 ruuid
[BTRFS_UUID_SIZE
];
1034 ri
= (struct btrfs_root_item
*)(args
.buf
+ off
);
1035 gen
= btrfs_root_generation(ri
);
1036 flags
= btrfs_root_flags(ri
);
1038 sizeof(struct btrfs_root_item_v0
)) {
1039 otime
= btrfs_stack_timespec_sec(&ri
->otime
);
1040 ogen
= btrfs_root_otransid(ri
);
1041 memcpy(uuid
, ri
->uuid
, BTRFS_UUID_SIZE
);
1042 memcpy(puuid
, ri
->parent_uuid
, BTRFS_UUID_SIZE
);
1043 memcpy(ruuid
, ri
->received_uuid
, BTRFS_UUID_SIZE
);
1047 memset(uuid
, 0, BTRFS_UUID_SIZE
);
1048 memset(puuid
, 0, BTRFS_UUID_SIZE
);
1049 memset(ruuid
, 0, BTRFS_UUID_SIZE
);
1052 add_root(root_lookup
, sh
.objectid
, 0,
1053 sh
.offset
, flags
, 0, NULL
, 0, ogen
,
1054 gen
, otime
, uuid
, puuid
, ruuid
);
1059 sk
->min_objectid
= sh
.objectid
;
1060 sk
->min_type
= sh
.type
;
1061 sk
->min_offset
= sh
.offset
;
1064 if (!sk
->min_offset
)
1069 if (sk
->min_type
> BTRFS_ROOT_BACKREF_KEY
) {
1070 sk
->min_type
= BTRFS_ROOT_ITEM_KEY
;
1075 if (sk
->min_objectid
> sk
->max_objectid
)
1082 static int filter_by_rootid(struct root_info
*ri
, u64 data
)
1084 return ri
->root_id
== data
;
1087 static int filter_snapshot(struct root_info
*ri
, u64 data
)
1089 return !!ri
->root_offset
;
1092 static int filter_flags(struct root_info
*ri
, u64 flags
)
1094 return ri
->flags
& flags
;
1097 static int filter_gen_more(struct root_info
*ri
, u64 data
)
1099 return ri
->gen
>= data
;
1102 static int filter_gen_less(struct root_info
*ri
, u64 data
)
1104 return ri
->gen
<= data
;
1107 static int filter_gen_equal(struct root_info
*ri
, u64 data
)
1109 return ri
->gen
== data
;
1112 static int filter_cgen_more(struct root_info
*ri
, u64 data
)
1114 return ri
->ogen
>= data
;
1117 static int filter_cgen_less(struct root_info
*ri
, u64 data
)
1119 return ri
->ogen
<= data
;
1122 static int filter_cgen_equal(struct root_info
*ri
, u64 data
)
1124 return ri
->ogen
== data
;
1127 static int filter_topid_equal(struct root_info
*ri
, u64 data
)
1129 return ri
->top_id
== data
;
1132 static int filter_full_path(struct root_info
*ri
, u64 data
)
1134 if (ri
->full_path
&& ri
->top_id
!= data
) {
1136 char p
[] = "<FS_TREE>";
1137 int add_len
= strlen(p
);
1138 int len
= strlen(ri
->full_path
);
1140 tmp
= malloc(len
+ add_len
+ 2);
1142 fprintf(stderr
, "memory allocation failed\n");
1145 memcpy(tmp
+ add_len
+ 1, ri
->full_path
, len
);
1146 tmp
[len
+ add_len
+ 1] = '\0';
1148 memcpy(tmp
, p
, add_len
);
1149 free(ri
->full_path
);
1150 ri
->full_path
= tmp
;
1155 static int filter_by_parent(struct root_info
*ri
, u64 data
)
1157 return !uuid_compare(ri
->puuid
, (u8
*)(unsigned long)data
);
1160 static int filter_deleted(struct root_info
*ri
, u64 data
)
1165 static btrfs_list_filter_func all_filter_funcs
[] = {
1166 [BTRFS_LIST_FILTER_ROOTID
] = filter_by_rootid
,
1167 [BTRFS_LIST_FILTER_SNAPSHOT_ONLY
] = filter_snapshot
,
1168 [BTRFS_LIST_FILTER_FLAGS
] = filter_flags
,
1169 [BTRFS_LIST_FILTER_GEN_MORE
] = filter_gen_more
,
1170 [BTRFS_LIST_FILTER_GEN_LESS
] = filter_gen_less
,
1171 [BTRFS_LIST_FILTER_GEN_EQUAL
] = filter_gen_equal
,
1172 [BTRFS_LIST_FILTER_CGEN_MORE
] = filter_cgen_more
,
1173 [BTRFS_LIST_FILTER_CGEN_LESS
] = filter_cgen_less
,
1174 [BTRFS_LIST_FILTER_CGEN_EQUAL
] = filter_cgen_equal
,
1175 [BTRFS_LIST_FILTER_TOPID_EQUAL
] = filter_topid_equal
,
1176 [BTRFS_LIST_FILTER_FULL_PATH
] = filter_full_path
,
1177 [BTRFS_LIST_FILTER_BY_PARENT
] = filter_by_parent
,
1178 [BTRFS_LIST_FILTER_DELETED
] = filter_deleted
,
1181 struct btrfs_list_filter_set
*btrfs_list_alloc_filter_set(void)
1183 struct btrfs_list_filter_set
*set
;
1186 size
= sizeof(struct btrfs_list_filter_set
) +
1187 BTRFS_LIST_NFILTERS_INCREASE
* sizeof(struct btrfs_list_filter
);
1188 set
= calloc(1, size
);
1190 fprintf(stderr
, "memory allocation failed\n");
1194 set
->total
= BTRFS_LIST_NFILTERS_INCREASE
;
1200 * Setup list filters. Exit if there's not enough memory, as we can't continue
1201 * without the structures set up properly.
1203 void btrfs_list_setup_filter(struct btrfs_list_filter_set
**filter_set
,
1204 enum btrfs_list_filter_enum filter
, u64 data
)
1206 struct btrfs_list_filter_set
*set
= *filter_set
;
1209 ASSERT(set
!= NULL
);
1210 ASSERT(filter
< BTRFS_LIST_FILTER_MAX
);
1211 ASSERT(set
->nfilters
<= set
->total
);
1213 if (set
->nfilters
== set
->total
) {
1216 size
= set
->total
+ BTRFS_LIST_NFILTERS_INCREASE
;
1217 size
= sizeof(*set
) + size
* sizeof(struct btrfs_list_filter
);
1219 set
= realloc(set
, size
);
1221 fprintf(stderr
, "memory allocation failed\n");
1226 memset(&set
->filters
[set
->total
], 0,
1227 BTRFS_LIST_NFILTERS_INCREASE
*
1228 sizeof(struct btrfs_list_filter
));
1229 set
->total
+= BTRFS_LIST_NFILTERS_INCREASE
;
1233 ASSERT(set
->filters
[set
->nfilters
].filter_func
== NULL
);
1235 if (filter
== BTRFS_LIST_FILTER_DELETED
)
1236 set
->only_deleted
= 1;
1238 set
->filters
[set
->nfilters
].filter_func
= all_filter_funcs
[filter
];
1239 set
->filters
[set
->nfilters
].data
= data
;
1243 static int filter_root(struct root_info
*ri
,
1244 struct btrfs_list_filter_set
*set
)
1251 if (set
->only_deleted
&& !ri
->deleted
)
1254 if (!set
->only_deleted
&& ri
->deleted
)
1257 for (i
= 0; i
< set
->nfilters
; i
++) {
1258 if (!set
->filters
[i
].filter_func
)
1260 ret
= set
->filters
[i
].filter_func(ri
, set
->filters
[i
].data
);
1267 static void filter_and_sort_subvol(struct root_lookup
*all_subvols
,
1268 struct root_lookup
*sort_tree
,
1269 struct btrfs_list_filter_set
*filter_set
,
1270 struct btrfs_list_comparer_set
*comp_set
,
1274 struct root_info
*entry
;
1277 sort_tree
->root
.rb_node
= NULL
;
1279 n
= rb_last(&all_subvols
->root
);
1281 entry
= to_root_info(n
);
1283 ret
= resolve_root(all_subvols
, entry
, top_id
);
1284 if (ret
== -ENOENT
) {
1285 if (entry
->root_id
!= BTRFS_FS_TREE_OBJECTID
) {
1286 entry
->full_path
= strdup("DELETED");
1290 * The full path is not supposed to be printed,
1291 * but we don't want to print an empty string,
1292 * in case it appears somewhere.
1294 entry
->full_path
= strdup("TOPLEVEL");
1298 ret
= filter_root(entry
, filter_set
);
1300 sort_tree_insert(sort_tree
, entry
, comp_set
);
1305 static int list_subvol_fill_paths(int fd
, struct root_lookup
*root_lookup
)
1309 n
= rb_first(&root_lookup
->root
);
1311 struct root_info
*entry
;
1313 entry
= to_root_info(n
);
1314 ret
= lookup_ino_path(fd
, entry
);
1315 if (ret
&& ret
!= -ENOENT
)
1323 static void print_subvolume_column(struct root_info
*subv
,
1324 enum btrfs_list_column_enum column
)
1327 char uuidparse
[BTRFS_UUID_UNPARSED_SIZE
];
1329 ASSERT(0 <= column
&& column
< BTRFS_LIST_ALL
);
1332 case BTRFS_LIST_OBJECTID
:
1333 printf("%llu", subv
->root_id
);
1335 case BTRFS_LIST_GENERATION
:
1336 printf("%llu", subv
->gen
);
1338 case BTRFS_LIST_OGENERATION
:
1339 printf("%llu", subv
->ogen
);
1341 case BTRFS_LIST_PARENT
:
1342 printf("%llu", subv
->ref_tree
);
1344 case BTRFS_LIST_TOP_LEVEL
:
1345 printf("%llu", subv
->top_id
);
1347 case BTRFS_LIST_OTIME
:
1351 localtime_r(&subv
->otime
, &tm
);
1352 strftime(tstr
, 256, "%Y-%m-%d %X", &tm
);
1357 case BTRFS_LIST_UUID
:
1358 if (uuid_is_null(subv
->uuid
))
1359 strcpy(uuidparse
, "-");
1361 uuid_unparse(subv
->uuid
, uuidparse
);
1362 printf("%-36s", uuidparse
);
1364 case BTRFS_LIST_PUUID
:
1365 if (uuid_is_null(subv
->puuid
))
1366 strcpy(uuidparse
, "-");
1368 uuid_unparse(subv
->puuid
, uuidparse
);
1369 printf("%-36s", uuidparse
);
1371 case BTRFS_LIST_RUUID
:
1372 if (uuid_is_null(subv
->ruuid
))
1373 strcpy(uuidparse
, "-");
1375 uuid_unparse(subv
->ruuid
, uuidparse
);
1376 printf("%-36s", uuidparse
);
1378 case BTRFS_LIST_PATH
:
1379 BUG_ON(!subv
->full_path
);
1380 printf("%s", subv
->full_path
);
1387 static void print_one_subvol_info_raw(struct root_info
*subv
,
1388 const char *raw_prefix
)
1392 for (i
= 0; i
< BTRFS_LIST_ALL
; i
++) {
1393 if (!btrfs_list_columns
[i
].need_print
)
1397 printf("%s",raw_prefix
);
1399 print_subvolume_column(subv
, i
);
1404 static void print_one_subvol_info_table(struct root_info
*subv
)
1408 for (i
= 0; i
< BTRFS_LIST_ALL
; i
++) {
1409 if (!btrfs_list_columns
[i
].need_print
)
1412 print_subvolume_column(subv
, i
);
1414 if (i
!= BTRFS_LIST_PATH
)
1417 if (i
== BTRFS_LIST_TOP_LEVEL
)
1423 static void print_one_subvol_info_default(struct root_info
*subv
)
1427 for (i
= 0; i
< BTRFS_LIST_ALL
; i
++) {
1428 if (!btrfs_list_columns
[i
].need_print
)
1431 printf("%s ", btrfs_list_columns
[i
].name
);
1432 print_subvolume_column(subv
, i
);
1434 if (i
!= BTRFS_LIST_PATH
)
1440 static void print_all_subvol_info_tab_head(void)
1446 for (i
= 0; i
< BTRFS_LIST_ALL
; i
++) {
1447 if (btrfs_list_columns
[i
].need_print
)
1448 printf("%s\t", btrfs_list_columns
[i
].name
);
1450 if (i
== BTRFS_LIST_ALL
-1)
1454 for (i
= 0; i
< BTRFS_LIST_ALL
; i
++) {
1455 memset(barrier
, 0, sizeof(barrier
));
1457 if (btrfs_list_columns
[i
].need_print
) {
1458 len
= strlen(btrfs_list_columns
[i
].name
);
1460 strcat(barrier
, "-");
1462 printf("%s\t", barrier
);
1464 if (i
== BTRFS_LIST_ALL
-1)
1469 static void print_all_subvol_info(struct root_lookup
*sorted_tree
,
1470 enum btrfs_list_layout layout
, const char *raw_prefix
)
1473 struct root_info
*entry
;
1475 if (layout
== BTRFS_LIST_LAYOUT_TABLE
)
1476 print_all_subvol_info_tab_head();
1478 n
= rb_first(&sorted_tree
->root
);
1480 entry
= to_root_info_sorted(n
);
1482 /* The toplevel subvolume is not listed by default */
1483 if (entry
->root_id
== BTRFS_FS_TREE_OBJECTID
)
1487 case BTRFS_LIST_LAYOUT_DEFAULT
:
1488 print_one_subvol_info_default(entry
);
1490 case BTRFS_LIST_LAYOUT_TABLE
:
1491 print_one_subvol_info_table(entry
);
1493 case BTRFS_LIST_LAYOUT_RAW
:
1494 print_one_subvol_info_raw(entry
, raw_prefix
);
1502 static int btrfs_list_subvols(int fd
, struct root_lookup
*root_lookup
)
1506 ret
= list_subvol_search(fd
, root_lookup
);
1508 error("can't perform the search: %m");
1513 * now we have an rbtree full of root_info objects, but we need to fill
1514 * in their path names within the subvol that is referencing each one.
1516 ret
= list_subvol_fill_paths(fd
, root_lookup
);
1520 int btrfs_list_subvols_print(int fd
, struct btrfs_list_filter_set
*filter_set
,
1521 struct btrfs_list_comparer_set
*comp_set
,
1522 enum btrfs_list_layout layout
, int full_path
,
1523 const char *raw_prefix
)
1525 struct root_lookup root_lookup
;
1526 struct root_lookup root_sort
;
1531 ret
= btrfs_list_get_path_rootid(fd
, &top_id
);
1535 ret
= btrfs_list_subvols(fd
, &root_lookup
);
1538 filter_and_sort_subvol(&root_lookup
, &root_sort
, filter_set
,
1541 print_all_subvol_info(&root_sort
, layout
, raw_prefix
);
1542 rb_free_nodes(&root_lookup
.root
, free_root_info
);
1547 static char *strdup_or_null(const char *s
)
1554 int btrfs_get_toplevel_subvol(int fd
, struct root_info
*the_ri
)
1557 struct root_lookup rl
;
1558 struct rb_node
*rbn
;
1559 struct root_info
*ri
;
1562 ret
= btrfs_list_get_path_rootid(fd
, &root_id
);
1566 ret
= btrfs_list_subvols(fd
, &rl
);
1570 rbn
= rb_first(&rl
.root
);
1571 ri
= to_root_info(rbn
);
1573 if (ri
->root_id
!= BTRFS_FS_TREE_OBJECTID
)
1576 memcpy(the_ri
, ri
, offsetof(struct root_info
, path
));
1577 the_ri
->path
= strdup_or_null("/");
1578 the_ri
->name
= strdup_or_null("<FS_TREE>");
1579 the_ri
->full_path
= strdup_or_null("/");
1580 rb_free_nodes(&rl
.root
, free_root_info
);
1585 int btrfs_get_subvol(int fd
, struct root_info
*the_ri
)
1588 struct root_lookup rl
;
1589 struct rb_node
*rbn
;
1590 struct root_info
*ri
;
1593 ret
= btrfs_list_get_path_rootid(fd
, &root_id
);
1597 ret
= btrfs_list_subvols(fd
, &rl
);
1601 rbn
= rb_first(&rl
.root
);
1603 ri
= to_root_info(rbn
);
1604 rr
= resolve_root(&rl
, ri
, root_id
);
1605 if (rr
== -ENOENT
) {
1611 if (!comp_entry_with_rootid(the_ri
, ri
, 0) ||
1612 !uuid_compare(the_ri
->uuid
, ri
->uuid
)) {
1613 memcpy(the_ri
, ri
, offsetof(struct root_info
, path
));
1614 the_ri
->path
= strdup_or_null(ri
->path
);
1615 the_ri
->name
= strdup_or_null(ri
->name
);
1616 the_ri
->full_path
= strdup_or_null(ri
->full_path
);
1622 rb_free_nodes(&rl
.root
, free_root_info
);
1626 static int print_one_extent(int fd
, struct btrfs_ioctl_search_header
*sh
,
1627 struct btrfs_file_extent_item
*item
,
1628 u64 found_gen
, u64
*cache_dirid
,
1629 char **cache_dir_name
, u64
*cache_ino
,
1630 char **cache_full_name
)
1634 u64 disk_offset
= 0;
1640 if (btrfs_search_header_objectid(sh
) == *cache_ino
) {
1641 name
= *cache_full_name
;
1642 } else if (*cache_full_name
) {
1643 free(*cache_full_name
);
1644 *cache_full_name
= NULL
;
1647 name
= ino_resolve(fd
, btrfs_search_header_objectid(sh
),
1650 *cache_full_name
= name
;
1651 *cache_ino
= btrfs_search_header_objectid(sh
);
1656 type
= btrfs_stack_file_extent_type(item
);
1657 compressed
= btrfs_stack_file_extent_compression(item
);
1659 if (type
== BTRFS_FILE_EXTENT_REG
||
1660 type
== BTRFS_FILE_EXTENT_PREALLOC
) {
1661 disk_start
= btrfs_stack_file_extent_disk_bytenr(item
);
1662 disk_offset
= btrfs_stack_file_extent_offset(item
);
1663 len
= btrfs_stack_file_extent_num_bytes(item
);
1664 } else if (type
== BTRFS_FILE_EXTENT_INLINE
) {
1667 len
= btrfs_stack_file_extent_ram_bytes(item
);
1670 "unhandled extent type %d for inode %llu file offset %llu gen %llu",
1672 (unsigned long long)btrfs_search_header_objectid(sh
),
1673 (unsigned long long)btrfs_search_header_offset(sh
),
1674 (unsigned long long)found_gen
);
1678 printf("inode %llu file offset %llu len %llu disk start %llu "
1679 "offset %llu gen %llu flags ",
1680 (unsigned long long)btrfs_search_header_objectid(sh
),
1681 (unsigned long long)btrfs_search_header_offset(sh
),
1682 (unsigned long long)len
,
1683 (unsigned long long)disk_start
,
1684 (unsigned long long)disk_offset
,
1685 (unsigned long long)found_gen
);
1691 if (type
== BTRFS_FILE_EXTENT_PREALLOC
) {
1692 printf("%sPREALLOC", flags
? "|" : "");
1695 if (type
== BTRFS_FILE_EXTENT_INLINE
) {
1696 printf("%sINLINE", flags
? "|" : "");
1702 printf(" %s\n", name
);
1706 int btrfs_list_find_updated_files(int fd
, u64 root_id
, u64 oldest_gen
)
1709 struct btrfs_ioctl_search_args args
;
1710 struct btrfs_ioctl_search_key
*sk
= &args
.key
;
1711 struct btrfs_ioctl_search_header sh
;
1712 struct btrfs_file_extent_item
*item
;
1713 unsigned long off
= 0;
1717 u64 cache_dirid
= 0;
1719 char *cache_dir_name
= NULL
;
1720 char *cache_full_name
= NULL
;
1721 struct btrfs_file_extent_item backup
;
1723 memset(&backup
, 0, sizeof(backup
));
1724 memset(&args
, 0, sizeof(args
));
1726 sk
->tree_id
= root_id
;
1729 * set all the other params to the max, we'll take any objectid
1732 sk
->max_objectid
= (u64
)-1;
1733 sk
->max_offset
= (u64
)-1;
1734 sk
->max_transid
= (u64
)-1;
1735 sk
->max_type
= BTRFS_EXTENT_DATA_KEY
;
1736 sk
->min_transid
= oldest_gen
;
1737 /* just a big number, doesn't matter much */
1738 sk
->nr_items
= 4096;
1740 max_found
= find_root_gen(fd
);
1742 ret
= ioctl(fd
, BTRFS_IOC_TREE_SEARCH
, &args
);
1744 error("can't perform the search: %m");
1747 /* the ioctl returns the number of item it found in nr_items */
1748 if (sk
->nr_items
== 0)
1754 * for each item, pull the key out of the header and then
1755 * read the root_ref item it contains
1757 for (i
= 0; i
< sk
->nr_items
; i
++) {
1758 memcpy(&sh
, args
.buf
+ off
, sizeof(sh
));
1762 * just in case the item was too big, pass something other
1768 item
= (struct btrfs_file_extent_item
*)(args
.buf
+
1770 found_gen
= btrfs_stack_file_extent_generation(item
);
1771 if (sh
.type
== BTRFS_EXTENT_DATA_KEY
&&
1772 found_gen
>= oldest_gen
) {
1773 print_one_extent(fd
, &sh
, item
, found_gen
,
1774 &cache_dirid
, &cache_dir_name
,
1775 &cache_ino
, &cache_full_name
);
1780 * record the mins in sk so we can make sure the
1781 * next search doesn't repeat this root
1783 sk
->min_objectid
= sh
.objectid
;
1784 sk
->min_offset
= sh
.offset
;
1785 sk
->min_type
= sh
.type
;
1787 sk
->nr_items
= 4096;
1788 if (sk
->min_offset
< (u64
)-1)
1790 else if (sk
->min_objectid
< (u64
)-1) {
1797 free(cache_dir_name
);
1798 free(cache_full_name
);
1799 printf("transid marker was %llu\n", (unsigned long long)max_found
);
1803 char *btrfs_list_path_for_root(int fd
, u64 root
)
1805 struct root_lookup root_lookup
;
1807 char *ret_path
= NULL
;
1811 ret
= btrfs_list_get_path_rootid(fd
, &top_id
);
1813 return ERR_PTR(ret
);
1815 ret
= list_subvol_search(fd
, &root_lookup
);
1817 return ERR_PTR(ret
);
1819 ret
= list_subvol_fill_paths(fd
, &root_lookup
);
1821 return ERR_PTR(ret
);
1823 n
= rb_last(&root_lookup
.root
);
1825 struct root_info
*entry
;
1827 entry
= to_root_info(n
);
1828 ret
= resolve_root(&root_lookup
, entry
, top_id
);
1829 if (ret
== -ENOENT
&& entry
->root_id
== root
) {
1833 if (entry
->root_id
== root
) {
1834 ret_path
= entry
->full_path
;
1835 entry
->full_path
= NULL
;
1840 rb_free_nodes(&root_lookup
.root
, free_root_info
);
1845 int btrfs_list_parse_sort_string(char *opt_arg
,
1846 struct btrfs_list_comparer_set
**comps
)
1854 while ((p
= strtok(opt_arg
, ",")) != NULL
) {
1856 ptr_argv
= all_sort_items
;
1859 if (strcmp(*ptr_argv
, p
) == 0) {
1864 if (strcmp(*ptr_argv
, p
) == 0) {
1881 } else if (*p
== '-') {
1887 what_to_sort
= btrfs_list_get_sort_item(p
);
1888 btrfs_list_setup_comparer(comps
, what_to_sort
, order
);
1897 * This function is used to parse the argument of filter condition.
1899 * type is the filter object.
1901 int btrfs_list_parse_filter_string(char *opt_arg
,
1902 struct btrfs_list_filter_set
**filters
,
1903 enum btrfs_list_filter_enum type
)
1908 switch (*(opt_arg
++)) {
1910 arg
= arg_strtou64(opt_arg
);
1913 btrfs_list_setup_filter(filters
, type
, arg
);
1916 arg
= arg_strtou64(opt_arg
);
1919 btrfs_list_setup_filter(filters
, type
, arg
);
1923 arg
= arg_strtou64(opt_arg
);
1925 btrfs_list_setup_filter(filters
, type
, arg
);
1932 int btrfs_list_get_path_rootid(int fd
, u64
*treeid
)
1936 ret
= lookup_path_rootid(fd
, treeid
);
1938 error("cannot resolve rootid for path: %m");