btrfs-progs: Add -R to list UUIDs of original received subvolume
[platform/upstream/btrfs-progs.git] / btrfs-list.h
1 /*
2  * Copyright (C) 2012 FUJITSU LIMITED.  All rights reserved.
3  *
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.
7  *
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.
12  *
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.
17  */
18
19 #if BTRFS_FLAT_INCLUDES
20 #include "kerncompat.h"
21 #else
22 #include <btrfs/kerncompat.h>
23 #endif /* BTRFS_FLAT_INCLUDES */
24
25 #define BTRFS_LIST_LAYOUT_DEFAULT       0
26 #define BTRFS_LIST_LAYOUT_TABLE 1
27 #define BTRFS_LIST_LAYOUT_RAW           2
28
29 /*
30  * one of these for each root we find.
31  */
32 struct root_info {
33         struct rb_node rb_node;
34         struct rb_node sort_node;
35
36         /* this root's id */
37         u64 root_id;
38
39         /* equal the offset of the root's key */
40         u64 root_offset;
41
42         /* flags of the root */
43         u64 flags;
44
45         /* the id of the root that references this one */
46         u64 ref_tree;
47
48         /* the dir id we're in from ref_tree */
49         u64 dir_id;
50
51         u64 top_id;
52
53         /* generation when the root is created or last updated */
54         u64 gen;
55
56         /* creation generation of this root in sec*/
57         u64 ogen;
58
59         /* creation time of this root in sec*/
60         time_t otime;
61
62         u8 uuid[BTRFS_UUID_SIZE];
63         u8 puuid[BTRFS_UUID_SIZE];
64         u8 ruuid[BTRFS_UUID_SIZE];
65
66         /* path from the subvol we live in to this root, including the
67          * root's name.  This is null until we do the extra lookup ioctl.
68          */
69         char *path;
70
71         /* the name of this root in the directory it lives in */
72         char *name;
73
74         char *full_path;
75
76         int deleted;
77 };
78
79 typedef int (*btrfs_list_filter_func)(struct root_info *, u64);
80 typedef int (*btrfs_list_comp_func)(struct root_info *, struct root_info *,
81                                     int);
82
83 struct btrfs_list_filter {
84         btrfs_list_filter_func filter_func;
85         u64 data;
86 };
87
88 struct btrfs_list_comparer {
89         btrfs_list_comp_func comp_func;
90         int is_descending;
91 };
92
93 struct btrfs_list_filter_set {
94         int total;
95         int nfilters;
96         int only_deleted;
97         struct btrfs_list_filter filters[0];
98 };
99
100 struct btrfs_list_comparer_set {
101         int total;
102         int ncomps;
103         struct btrfs_list_comparer comps[0];
104 };
105
106 enum btrfs_list_column_enum {
107         BTRFS_LIST_OBJECTID,
108         BTRFS_LIST_GENERATION,
109         BTRFS_LIST_OGENERATION,
110         BTRFS_LIST_PARENT,
111         BTRFS_LIST_TOP_LEVEL,
112         BTRFS_LIST_OTIME,
113         BTRFS_LIST_PUUID,
114         BTRFS_LIST_RUUID,
115         BTRFS_LIST_UUID,
116         BTRFS_LIST_PATH,
117         BTRFS_LIST_ALL,
118 };
119
120 enum btrfs_list_filter_enum {
121         BTRFS_LIST_FILTER_ROOTID,
122         BTRFS_LIST_FILTER_SNAPSHOT_ONLY,
123         BTRFS_LIST_FILTER_FLAGS,
124         BTRFS_LIST_FILTER_GEN,
125         BTRFS_LIST_FILTER_GEN_EQUAL     =       BTRFS_LIST_FILTER_GEN,
126         BTRFS_LIST_FILTER_GEN_LESS,
127         BTRFS_LIST_FILTER_GEN_MORE,
128         BTRFS_LIST_FILTER_CGEN,
129         BTRFS_LIST_FILTER_CGEN_EQUAL    =       BTRFS_LIST_FILTER_CGEN,
130         BTRFS_LIST_FILTER_CGEN_LESS,
131         BTRFS_LIST_FILTER_CGEN_MORE,
132         BTRFS_LIST_FILTER_TOPID_EQUAL,
133         BTRFS_LIST_FILTER_FULL_PATH,
134         BTRFS_LIST_FILTER_BY_PARENT,
135         BTRFS_LIST_FILTER_DELETED,
136         BTRFS_LIST_FILTER_MAX,
137 };
138
139 enum btrfs_list_comp_enum {
140         BTRFS_LIST_COMP_ROOTID,
141         BTRFS_LIST_COMP_OGEN,
142         BTRFS_LIST_COMP_GEN,
143         BTRFS_LIST_COMP_PATH,
144         BTRFS_LIST_COMP_MAX,
145 };
146
147 int btrfs_list_parse_sort_string(char *optarg,
148                                  struct btrfs_list_comparer_set **comps);
149 int btrfs_list_parse_filter_string(char *optarg,
150                                    struct btrfs_list_filter_set **filters,
151                                    enum btrfs_list_filter_enum type);
152 void btrfs_list_setup_print_column(enum btrfs_list_column_enum column);
153 struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void);
154 void btrfs_list_free_filter_set(struct btrfs_list_filter_set *filter_set);
155 int btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
156                             enum btrfs_list_filter_enum filter, u64 data);
157 struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void);
158 void btrfs_list_free_comparer_set(struct btrfs_list_comparer_set *comp_set);
159
160 int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
161                        struct btrfs_list_comparer_set *comp_set,
162                        int is_tab_result, int full_path, char *raw_prefix);
163 int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
164 int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
165 char *btrfs_list_path_for_root(int fd, u64 root);
166 int btrfs_list_get_path_rootid(int fd, u64 *treeid);
167 int btrfs_get_subvol(int fd, struct root_info *the_ri);