btrfs-progs: check: Cleanup all checkpatch error and warning
[platform/upstream/btrfs-progs.git] / check / original.h
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.
5  *
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.
10  *
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.
15  */
16
17 /*
18  * Defines and function declarations for original mode check.
19  */
20
21 #ifndef __BTRFS_CHECK_ORIGINAL_H__
22 #define __BTRFS_CHECK_ORIGINAL_H__
23 #include "rbtree-utils.h"
24
25 struct extent_backref {
26         struct rb_node node;
27         unsigned int is_data:1;
28         unsigned int found_extent_tree:1;
29         unsigned int full_backref:1;
30         unsigned int found_ref:1;
31         unsigned int broken:1;
32 };
33
34 static inline struct extent_backref* rb_node_to_extent_backref(struct rb_node *node)
35 {
36         return rb_entry(node, struct extent_backref, node);
37 }
38
39 struct data_backref {
40         struct extent_backref node;
41         union {
42                 u64 parent;
43                 u64 root;
44         };
45         u64 owner;
46         u64 offset;
47         u64 disk_bytenr;
48         u64 bytes;
49         u64 ram_bytes;
50         u32 num_refs;
51         u32 found_ref;
52 };
53
54 static inline struct data_backref* to_data_backref(struct extent_backref *back)
55 {
56         return container_of(back, struct data_backref, node);
57 }
58
59 /*
60  * Much like data_backref, just removed the undetermined members
61  * and change it to use list_head.
62  * During extent scan, it is stored in root->orphan_data_extent.
63  * During fs tree scan, it is then moved to inode_rec->orphan_data_extents.
64  */
65 struct orphan_data_extent {
66         struct list_head list;
67         u64 root;
68         u64 objectid;
69         u64 offset;
70         u64 disk_bytenr;
71         u64 disk_len;
72 };
73
74 struct tree_backref {
75         struct extent_backref node;
76         union {
77                 u64 parent;
78                 u64 root;
79         };
80 };
81
82 static inline struct tree_backref* to_tree_backref(struct extent_backref *back)
83 {
84         return container_of(back, struct tree_backref, node);
85 }
86
87 /* Explicit initialization for extent_record::flag_block_full_backref */
88 enum { FLAG_UNSET = 2 };
89
90 struct extent_record {
91         struct list_head backrefs;
92         struct list_head dups;
93         struct rb_root backref_tree;
94         struct list_head list;
95         struct cache_extent cache;
96         struct btrfs_disk_key parent_key;
97         u64 start;
98         u64 max_size;
99         u64 nr;
100         u64 refs;
101         u64 extent_item_refs;
102         u64 generation;
103         u64 parent_generation;
104         u64 info_objectid;
105         u32 num_duplicates;
106         u8 info_level;
107         unsigned int flag_block_full_backref:2;
108         unsigned int found_rec:1;
109         unsigned int content_checked:1;
110         unsigned int owner_ref_checked:1;
111         unsigned int is_root:1;
112         unsigned int metadata:1;
113         unsigned int bad_full_backref:1;
114         unsigned int crossing_stripes:1;
115         unsigned int wrong_chunk_type:1;
116 };
117
118 static inline struct extent_record* to_extent_record(struct list_head *entry)
119 {
120         return container_of(entry, struct extent_record, list);
121 }
122
123 struct inode_backref {
124         struct list_head list;
125         unsigned int found_dir_item:1;
126         unsigned int found_dir_index:1;
127         unsigned int found_inode_ref:1;
128         u8 filetype;
129         u8 ref_type;
130         int errors;
131         u64 dir;
132         u64 index;
133         u16 namelen;
134         char name[0];
135 };
136
137 static inline struct inode_backref* to_inode_backref(struct list_head *entry)
138 {
139         return list_entry(entry, struct inode_backref, list);
140 }
141
142 struct root_item_record {
143         struct list_head list;
144         u64 objectid;
145         u64 bytenr;
146         u64 last_snapshot;
147         u8 level;
148         u8 drop_level;
149         struct btrfs_key drop_key;
150 };
151
152 #define REF_ERR_NO_DIR_ITEM             (1 << 0)
153 #define REF_ERR_NO_DIR_INDEX            (1 << 1)
154 #define REF_ERR_NO_INODE_REF            (1 << 2)
155 #define REF_ERR_DUP_DIR_ITEM            (1 << 3)
156 #define REF_ERR_DUP_DIR_INDEX           (1 << 4)
157 #define REF_ERR_DUP_INODE_REF           (1 << 5)
158 #define REF_ERR_INDEX_UNMATCH           (1 << 6)
159 #define REF_ERR_FILETYPE_UNMATCH        (1 << 7)
160 #define REF_ERR_NAME_TOO_LONG           (1 << 8) // 100
161 #define REF_ERR_NO_ROOT_REF             (1 << 9)
162 #define REF_ERR_NO_ROOT_BACKREF         (1 << 10)
163 #define REF_ERR_DUP_ROOT_REF            (1 << 11)
164 #define REF_ERR_DUP_ROOT_BACKREF        (1 << 12)
165
166 struct file_extent_hole {
167         struct rb_node node;
168         u64 start;
169         u64 len;
170 };
171
172 #define I_ERR_NO_INODE_ITEM             (1 << 0)
173 #define I_ERR_NO_ORPHAN_ITEM            (1 << 1)
174 #define I_ERR_DUP_INODE_ITEM            (1 << 2)
175 #define I_ERR_DUP_DIR_INDEX             (1 << 3)
176 #define I_ERR_ODD_DIR_ITEM              (1 << 4)
177 #define I_ERR_ODD_FILE_EXTENT           (1 << 5)
178 #define I_ERR_BAD_FILE_EXTENT           (1 << 6)
179 #define I_ERR_FILE_EXTENT_OVERLAP       (1 << 7)
180 #define I_ERR_FILE_EXTENT_DISCOUNT      (1 << 8) // 100
181 #define I_ERR_DIR_ISIZE_WRONG           (1 << 9)
182 #define I_ERR_FILE_NBYTES_WRONG         (1 << 10) // 400
183 #define I_ERR_ODD_CSUM_ITEM             (1 << 11)
184 #define I_ERR_SOME_CSUM_MISSING         (1 << 12)
185 #define I_ERR_LINK_COUNT_WRONG          (1 << 13)
186 #define I_ERR_FILE_EXTENT_ORPHAN        (1 << 14)
187
188 struct inode_record {
189         struct list_head backrefs;
190         unsigned int checked:1;
191         unsigned int merging:1;
192         unsigned int found_inode_item:1;
193         unsigned int found_dir_item:1;
194         unsigned int found_file_extent:1;
195         unsigned int found_csum_item:1;
196         unsigned int some_csum_missing:1;
197         unsigned int nodatasum:1;
198         int errors;
199
200         u64 ino;
201         u32 nlink;
202         u32 imode;
203         u64 isize;
204         u64 nbytes;
205
206         u32 found_link;
207         u64 found_size;
208         u64 extent_start;
209         u64 extent_end;
210         struct rb_root holes;
211         struct list_head orphan_extents;
212
213         u32 refs;
214 };
215
216 struct root_backref {
217         struct list_head list;
218         unsigned int found_dir_item:1;
219         unsigned int found_dir_index:1;
220         unsigned int found_back_ref:1;
221         unsigned int found_forward_ref:1;
222         unsigned int reachable:1;
223         int errors;
224         u64 ref_root;
225         u64 dir;
226         u64 index;
227         u16 namelen;
228         char name[0];
229 };
230
231 static inline struct root_backref* to_root_backref(struct list_head *entry)
232 {
233         return list_entry(entry, struct root_backref, list);
234 }
235
236 struct root_record {
237         struct list_head backrefs;
238         struct cache_extent cache;
239         unsigned int found_root_item:1;
240         u64 objectid;
241         u32 found_ref;
242 };
243
244 struct ptr_node {
245         struct cache_extent cache;
246         void *data;
247 };
248
249 struct shared_node {
250         struct cache_extent cache;
251         struct cache_tree root_cache;
252         struct cache_tree inode_cache;
253         struct inode_record *current;
254         u32 refs;
255 };
256
257 struct block_info {
258         u64 start;
259         u32 size;
260 };
261
262 struct walk_control {
263         struct cache_tree shared;
264         struct shared_node *nodes[BTRFS_MAX_LEVEL];
265         int active_node;
266         int root_level;
267 };
268
269 struct bad_item {
270         struct btrfs_key key;
271         u64 root_id;
272         struct list_head list;
273 };
274
275 struct extent_entry {
276         u64 bytenr;
277         u64 bytes;
278         int count;
279         int broken;
280         struct list_head list;
281 };
282
283 struct root_item_info {
284         /* level of the root */
285         u8 level;
286         /* number of nodes at this level, must be 1 for a root */
287         int node_count;
288         u64 bytenr;
289         u64 gen;
290         struct cache_extent cache_extent;
291 };
292
293 #endif