Btrfs-progs: move path modification to filters
[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 struct root_info;
22
23 typedef int (*btrfs_list_filter_func)(struct root_info *, u64);
24 typedef int (*btrfs_list_comp_func)(struct root_info *, struct root_info *,
25                                     int);
26
27 struct btrfs_list_filter {
28         btrfs_list_filter_func filter_func;
29         u64 data;
30 };
31
32 struct btrfs_list_comparer {
33         btrfs_list_comp_func comp_func;
34         int is_descending;
35 };
36
37 struct btrfs_list_filter_set {
38         int total;
39         int nfilters;
40         struct btrfs_list_filter filters[0];
41 };
42
43 struct btrfs_list_comparer_set {
44         int total;
45         int ncomps;
46         struct btrfs_list_comparer comps[0];
47 };
48
49 enum btrfs_list_column_enum {
50         BTRFS_LIST_OBJECTID,
51         BTRFS_LIST_GENERATION,
52         BTRFS_LIST_OGENERATION,
53         BTRFS_LIST_PARENT,
54         BTRFS_LIST_TOP_LEVEL,
55         BTRFS_LIST_OTIME,
56         BTRFS_LIST_UUID,
57         BTRFS_LIST_PATH,
58         BTRFS_LIST_ALL,
59 };
60
61 enum btrfs_list_filter_enum {
62         BTRFS_LIST_FILTER_ROOTID,
63         BTRFS_LIST_FILTER_SNAPSHOT_ONLY,
64         BTRFS_LIST_FILTER_FLAGS,
65         BTRFS_LIST_FILTER_GEN,
66         BTRFS_LIST_FILTER_GEN_EQUAL     =       BTRFS_LIST_FILTER_GEN,
67         BTRFS_LIST_FILTER_GEN_LESS,
68         BTRFS_LIST_FILTER_GEN_MORE,
69         BTRFS_LIST_FILTER_CGEN,
70         BTRFS_LIST_FILTER_CGEN_EQUAL    =       BTRFS_LIST_FILTER_CGEN,
71         BTRFS_LIST_FILTER_CGEN_LESS,
72         BTRFS_LIST_FILTER_CGEN_MORE,
73         BTRFS_LIST_FILTER_TOPID_EQUAL,
74         BTRFS_LIST_FILTER_FULL_PATH,
75         BTRFS_LIST_FILTER_MAX,
76 };
77
78 enum btrfs_list_comp_enum {
79         BTRFS_LIST_COMP_ROOTID,
80         BTRFS_LIST_COMP_OGEN,
81         BTRFS_LIST_COMP_GEN,
82         BTRFS_LIST_COMP_PATH,
83         BTRFS_LIST_COMP_MAX,
84 };
85
86 int btrfs_list_parse_sort_string(char *optarg,
87                                  struct btrfs_list_comparer_set **comps);
88 int btrfs_list_parse_filter_string(char *optarg,
89                                    struct btrfs_list_filter_set **filters,
90                                    enum btrfs_list_filter_enum type);
91 void btrfs_list_setup_print_column(enum btrfs_list_column_enum column);
92 struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void);
93 void btrfs_list_free_filter_set(struct btrfs_list_filter_set *filter_set);
94 int btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
95                             enum btrfs_list_filter_enum filter, u64 data);
96 struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void);
97 void btrfs_list_free_comparer_set(struct btrfs_list_comparer_set *comp_set);
98 int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
99                               enum btrfs_list_comp_enum comparer,
100                               int is_descending);
101
102 int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
103                        struct btrfs_list_comparer_set *comp_set,
104                         int is_tab_result);
105 int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
106 int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
107 char *btrfs_list_path_for_root(int fd, u64 root);
108 u64 btrfs_list_get_path_rootid(int fd);