Btrfs progs v4.17.1
[btrfs-progs-unstable/devel.git] / btrfs-list.h
blob6e5fc7784fb1531a408bd0ccd134bed6933d3178
1 /*
2 * Copyright (C) 2012 FUJITSU LIMITED. All rights reserved.
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.
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.
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.
19 #ifndef __BTRFS_LIST_H__
20 #define __BTRFS_LIST_H__
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 */
32 #include <time.h>
34 enum btrfs_list_layout {
35 BTRFS_LIST_LAYOUT_DEFAULT = 0,
36 BTRFS_LIST_LAYOUT_TABLE,
37 BTRFS_LIST_LAYOUT_RAW
41 * one of these for each root we find.
43 struct root_info {
44 struct rb_node rb_node;
45 struct rb_node sort_node;
47 /* this root's id */
48 u64 root_id;
50 /* equal the offset of the root's key */
51 u64 root_offset;
53 /* flags of the root */
54 u64 flags;
56 /* the id of the root that references this one */
57 u64 ref_tree;
59 /* the dir id we're in from ref_tree */
60 u64 dir_id;
62 u64 top_id;
64 /* generation when the root is created or last updated */
65 u64 gen;
67 /* creation generation of this root in sec*/
68 u64 ogen;
70 /* creation time of this root in sec*/
71 time_t otime;
73 u8 uuid[BTRFS_UUID_SIZE];
74 u8 puuid[BTRFS_UUID_SIZE];
75 u8 ruuid[BTRFS_UUID_SIZE];
77 /* path from the subvol we live in to this root, including the
78 * root's name. This is null until we do the extra lookup ioctl.
80 char *path;
82 /* the name of this root in the directory it lives in */
83 char *name;
85 char *full_path;
87 int deleted;
90 typedef int (*btrfs_list_filter_func)(struct root_info *, u64);
91 typedef int (*btrfs_list_comp_func)(struct root_info *, struct root_info *,
92 int);
94 struct btrfs_list_filter {
95 btrfs_list_filter_func filter_func;
96 u64 data;
99 struct btrfs_list_comparer {
100 btrfs_list_comp_func comp_func;
101 int is_descending;
104 struct btrfs_list_filter_set {
105 int total;
106 int nfilters;
107 int only_deleted;
108 struct btrfs_list_filter filters[0];
111 struct btrfs_list_comparer_set {
112 int total;
113 int ncomps;
114 struct btrfs_list_comparer comps[0];
117 enum btrfs_list_column_enum {
118 BTRFS_LIST_OBJECTID,
119 BTRFS_LIST_GENERATION,
120 BTRFS_LIST_OGENERATION,
121 BTRFS_LIST_PARENT,
122 BTRFS_LIST_TOP_LEVEL,
123 BTRFS_LIST_OTIME,
124 BTRFS_LIST_PUUID,
125 BTRFS_LIST_RUUID,
126 BTRFS_LIST_UUID,
127 BTRFS_LIST_PATH,
128 BTRFS_LIST_ALL,
131 enum btrfs_list_filter_enum {
132 BTRFS_LIST_FILTER_ROOTID,
133 BTRFS_LIST_FILTER_SNAPSHOT_ONLY,
134 BTRFS_LIST_FILTER_FLAGS,
135 BTRFS_LIST_FILTER_GEN,
136 BTRFS_LIST_FILTER_GEN_EQUAL = BTRFS_LIST_FILTER_GEN,
137 BTRFS_LIST_FILTER_GEN_LESS,
138 BTRFS_LIST_FILTER_GEN_MORE,
139 BTRFS_LIST_FILTER_CGEN,
140 BTRFS_LIST_FILTER_CGEN_EQUAL = BTRFS_LIST_FILTER_CGEN,
141 BTRFS_LIST_FILTER_CGEN_LESS,
142 BTRFS_LIST_FILTER_CGEN_MORE,
143 BTRFS_LIST_FILTER_TOPID_EQUAL,
144 BTRFS_LIST_FILTER_FULL_PATH,
145 BTRFS_LIST_FILTER_BY_PARENT,
146 BTRFS_LIST_FILTER_DELETED,
147 BTRFS_LIST_FILTER_MAX,
150 enum btrfs_list_comp_enum {
151 BTRFS_LIST_COMP_ROOTID,
152 BTRFS_LIST_COMP_OGEN,
153 BTRFS_LIST_COMP_GEN,
154 BTRFS_LIST_COMP_PATH,
155 BTRFS_LIST_COMP_MAX,
158 int btrfs_list_parse_sort_string(char *optarg,
159 struct btrfs_list_comparer_set **comps);
160 int btrfs_list_parse_filter_string(char *optarg,
161 struct btrfs_list_filter_set **filters,
162 enum btrfs_list_filter_enum type);
163 void btrfs_list_setup_print_column(enum btrfs_list_column_enum column);
164 struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void);
165 void btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
166 enum btrfs_list_filter_enum filter, u64 data);
167 struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void);
169 int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
170 struct btrfs_list_comparer_set *comp_set,
171 enum btrfs_list_layout layot, int full_path,
172 const char *raw_prefix);
173 int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
174 int btrfs_list_get_default_subvolume(int fd, u64 *default_id);
175 char *btrfs_list_path_for_root(int fd, u64 root);
176 int btrfs_list_get_path_rootid(int fd, u64 *treeid);
177 int btrfs_get_subvol(int fd, struct root_info *the_ri);
178 int btrfs_get_toplevel_subvol(int fd, struct root_info *the_ri);
180 #endif