Btrfs-progs: restructure list_subvolumes
[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_MAX,
65 };
66
67 enum btrfs_list_comp_enum {
68         BTRFS_LIST_COMP_ROOTID,
69         BTRFS_LIST_COMP_OGEN,
70         BTRFS_LIST_COMP_GEN,
71         BTRFS_LIST_COMP_MAX,
72 };
73
74 void btrfs_list_setup_print_column(enum btrfs_list_column_enum column);
75 struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void);
76 void btrfs_list_free_filter_set(struct btrfs_list_filter_set *filter_set);
77 int btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
78                             enum btrfs_list_filter_enum filter, u64 data);
79 struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void);
80 void btrfs_list_free_comparer_set(struct btrfs_list_comparer_set *comp_set);
81 int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
82                               enum btrfs_list_comp_enum comparer,
83                               int is_descending);
84
85 int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
86                        struct btrfs_list_comparer_set *comp_set);
87 int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
88 int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
89 char *btrfs_list_path_for_root(int fd, u64 root);