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