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