Btrfs progs v4.17.1
[btrfs-progs-unstable/devel.git] / check / mode-original.h
blobec2842e0b3be6c19b66452277d1bf8d4d47e854e
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public
4 * License v2 as published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License for more details.
11 * You should have received a copy of the GNU General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 * Boston, MA 021110-1307, USA.
18 * Defines and function declarations for original mode check.
21 #ifndef __BTRFS_CHECK_MODE_ORIGINAL_H__
22 #define __BTRFS_CHECK_MODE_ORIGINAL_H__
24 #include "rbtree-utils.h"
26 struct extent_backref {
27 struct rb_node node;
28 unsigned int is_data:1;
29 unsigned int found_extent_tree:1;
30 unsigned int full_backref:1;
31 unsigned int found_ref:1;
32 unsigned int broken:1;
35 static inline struct extent_backref* rb_node_to_extent_backref(struct rb_node *node)
37 return rb_entry(node, struct extent_backref, node);
40 struct data_backref {
41 struct extent_backref node;
42 union {
43 u64 parent;
44 u64 root;
46 u64 owner;
47 u64 offset;
48 u64 disk_bytenr;
49 u64 bytes;
50 u64 ram_bytes;
51 u32 num_refs;
52 u32 found_ref;
55 static inline struct data_backref* to_data_backref(struct extent_backref *back)
57 return container_of(back, struct data_backref, node);
61 * Much like data_backref, just removed the undetermined members
62 * and change it to use list_head.
63 * During extent scan, it is stored in root->orphan_data_extent.
64 * During fs tree scan, it is then moved to inode_rec->orphan_data_extents.
66 struct orphan_data_extent {
67 struct list_head list;
68 u64 root;
69 u64 objectid;
70 u64 offset;
71 u64 disk_bytenr;
72 u64 disk_len;
75 struct tree_backref {
76 struct extent_backref node;
77 union {
78 u64 parent;
79 u64 root;
83 static inline struct tree_backref* to_tree_backref(struct extent_backref *back)
85 return container_of(back, struct tree_backref, node);
88 /* Explicit initialization for extent_record::flag_block_full_backref */
89 enum { FLAG_UNSET = 2 };
91 struct extent_record {
92 struct list_head backrefs;
93 struct list_head dups;
94 struct rb_root backref_tree;
95 struct list_head list;
96 struct cache_extent cache;
97 struct btrfs_disk_key parent_key;
98 u64 start;
99 u64 max_size;
100 u64 nr;
101 u64 refs;
102 u64 extent_item_refs;
103 u64 generation;
104 u64 parent_generation;
105 u64 info_objectid;
106 u32 num_duplicates;
107 u8 info_level;
108 unsigned int flag_block_full_backref:2;
109 unsigned int found_rec:1;
110 unsigned int content_checked:1;
111 unsigned int owner_ref_checked:1;
112 unsigned int is_root:1;
113 unsigned int metadata:1;
114 unsigned int bad_full_backref:1;
115 unsigned int crossing_stripes:1;
116 unsigned int wrong_chunk_type:1;
119 static inline struct extent_record* to_extent_record(struct list_head *entry)
121 return container_of(entry, struct extent_record, list);
124 struct inode_backref {
125 struct list_head list;
126 unsigned int found_dir_item:1;
127 unsigned int found_dir_index:1;
128 unsigned int found_inode_ref:1;
129 u8 filetype;
130 u8 ref_type;
131 int errors;
132 u64 dir;
133 u64 index;
134 u16 namelen;
135 char name[0];
138 static inline struct inode_backref* to_inode_backref(struct list_head *entry)
140 return list_entry(entry, struct inode_backref, list);
143 struct root_item_record {
144 struct list_head list;
145 u64 objectid;
146 u64 bytenr;
147 u64 last_snapshot;
148 u8 level;
149 u8 drop_level;
150 struct btrfs_key drop_key;
153 #define REF_ERR_NO_DIR_ITEM (1 << 0)
154 #define REF_ERR_NO_DIR_INDEX (1 << 1)
155 #define REF_ERR_NO_INODE_REF (1 << 2)
156 #define REF_ERR_DUP_DIR_ITEM (1 << 3)
157 #define REF_ERR_DUP_DIR_INDEX (1 << 4)
158 #define REF_ERR_DUP_INODE_REF (1 << 5)
159 #define REF_ERR_INDEX_UNMATCH (1 << 6)
160 #define REF_ERR_FILETYPE_UNMATCH (1 << 7)
161 #define REF_ERR_NAME_TOO_LONG (1 << 8) // 100
162 #define REF_ERR_NO_ROOT_REF (1 << 9)
163 #define REF_ERR_NO_ROOT_BACKREF (1 << 10)
164 #define REF_ERR_DUP_ROOT_REF (1 << 11)
165 #define REF_ERR_DUP_ROOT_BACKREF (1 << 12)
167 struct file_extent_hole {
168 struct rb_node node;
169 u64 start;
170 u64 len;
173 #define I_ERR_NO_INODE_ITEM (1 << 0)
174 #define I_ERR_NO_ORPHAN_ITEM (1 << 1)
175 #define I_ERR_DUP_INODE_ITEM (1 << 2)
176 #define I_ERR_DUP_DIR_INDEX (1 << 3)
177 #define I_ERR_ODD_DIR_ITEM (1 << 4)
178 #define I_ERR_ODD_FILE_EXTENT (1 << 5)
179 #define I_ERR_BAD_FILE_EXTENT (1 << 6)
180 #define I_ERR_FILE_EXTENT_OVERLAP (1 << 7)
181 #define I_ERR_FILE_EXTENT_DISCOUNT (1 << 8) // 100
182 #define I_ERR_DIR_ISIZE_WRONG (1 << 9)
183 #define I_ERR_FILE_NBYTES_WRONG (1 << 10) // 400
184 #define I_ERR_ODD_CSUM_ITEM (1 << 11)
185 #define I_ERR_SOME_CSUM_MISSING (1 << 12)
186 #define I_ERR_LINK_COUNT_WRONG (1 << 13)
187 #define I_ERR_FILE_EXTENT_ORPHAN (1 << 14)
188 #define I_ERR_FILE_EXTENT_TOO_LARGE (1 << 15)
189 #define I_ERR_ODD_INODE_FLAGS (1 << 16)
190 #define I_ERR_INLINE_RAM_BYTES_WRONG (1 << 17)
192 struct inode_record {
193 struct list_head backrefs;
194 unsigned int checked:1;
195 unsigned int merging:1;
196 unsigned int found_inode_item:1;
197 unsigned int found_dir_item:1;
198 unsigned int found_file_extent:1;
199 unsigned int found_csum_item:1;
200 unsigned int some_csum_missing:1;
201 unsigned int nodatasum:1;
202 int errors;
204 u64 ino;
205 u32 nlink;
206 u32 imode;
207 u64 isize;
208 u64 nbytes;
210 u32 found_link;
211 u64 found_size;
212 u64 extent_start;
213 u64 extent_end;
214 struct rb_root holes;
215 struct list_head orphan_extents;
217 u32 refs;
220 struct root_backref {
221 struct list_head list;
222 unsigned int found_dir_item:1;
223 unsigned int found_dir_index:1;
224 unsigned int found_back_ref:1;
225 unsigned int found_forward_ref:1;
226 unsigned int reachable:1;
227 int errors;
228 u64 ref_root;
229 u64 dir;
230 u64 index;
231 u16 namelen;
232 char name[0];
235 static inline struct root_backref* to_root_backref(struct list_head *entry)
237 return list_entry(entry, struct root_backref, list);
240 struct root_record {
241 struct list_head backrefs;
242 struct cache_extent cache;
243 unsigned int found_root_item:1;
244 u64 objectid;
245 u32 found_ref;
248 struct ptr_node {
249 struct cache_extent cache;
250 void *data;
253 struct shared_node {
254 struct cache_extent cache;
255 struct cache_tree root_cache;
256 struct cache_tree inode_cache;
257 struct inode_record *current;
258 u32 refs;
261 struct block_info {
262 u64 start;
263 u32 size;
266 struct walk_control {
267 struct cache_tree shared;
268 struct shared_node *nodes[BTRFS_MAX_LEVEL];
269 int active_node;
270 int root_level;
273 struct bad_item {
274 struct btrfs_key key;
275 u64 root_id;
276 struct list_head list;
279 struct extent_entry {
280 u64 bytenr;
281 u64 bytes;
282 int count;
283 int broken;
284 struct list_head list;
287 struct root_item_info {
288 /* level of the root */
289 u8 level;
290 /* number of nodes at this level, must be 1 for a root */
291 int node_count;
292 u64 bytenr;
293 u64 gen;
294 struct cache_extent cache_extent;
297 #endif