Btrfs-progs: Add block group check funtion
[platform/upstream/btrfs-progs.git] / btrfsck.h
1 /*
2  * Copyright (C) 2013 Fujitsu.  All rights reserved.
3  * Written by Miao Xie <miaox@cn.fujitsu.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public
7  * License v2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 021110-1307, USA.
18  */
19
20 #ifndef __CHUNK_CHECK_H__
21 #define __CHUNK_CHECK_H__
22
23 #if BTRFS_FLAT_INCLUDES
24 #include "kerncompat.h"
25 #include "extent-cache.h"
26 #include "list.h"
27 #else
28 #include <btrfs/kerncompat.h>
29 #include <btrfs/extent-cache.h>
30 #include <btrfs/list.h>
31 #endif /* BTRFS_FLAT_INCLUDES */
32
33 struct block_group_record {
34         struct cache_extent cache;
35         /* Used to identify the orphan block groups */
36         struct list_head list;
37
38         u64 objectid;
39         u8  type;
40         u64 offset;
41
42         u64 flags;
43 };
44
45 struct block_group_tree {
46         struct cache_tree tree;
47         struct list_head block_groups;
48 };
49
50 struct device_record {
51         struct rb_node node;
52         u64 devid;
53
54         u64 objectid;
55         u8  type;
56         u64 offset;
57
58         u64 total_byte;
59         u64 byte_used;
60
61         u64 real_used;
62 };
63
64 struct stripe {
65         u64 devid;
66         u64 offset;
67 };
68
69 struct chunk_record {
70         struct cache_extent cache;
71
72         u64 objectid;
73         u8  type;
74         u64 offset;
75
76         u64 length;
77         u64 type_flags;
78         u16 num_stripes;
79         u16 sub_stripes;
80         struct stripe stripes[0];
81 };
82
83 struct device_extent_record {
84         struct cache_extent cache;
85         /*
86          * Used to identify the orphan device extents (the device extents
87          * don't belong to a chunk or a device)
88          */
89         struct list_head chunk_list;
90         struct list_head device_list;
91
92         u64 objectid;
93         u8  type;
94         u64 offset;
95
96         u64 chunk_objecteid;
97         u64 chunk_offset;
98         u64 length;
99 };
100
101 struct device_extent_tree {
102         struct cache_tree tree;
103         /*
104          * The idea is:
105          * When checking the chunk information, we move the device extents
106          * that has its chunk to the chunk's device extents list. After the
107          * check, if there are still some device extents in no_chunk_orphans,
108          * it means there are some device extents which don't belong to any
109          * chunk.
110          *
111          * The usage of no_device_orphans is the same as the first one, but it
112          * is for the device information check.
113          */
114         struct list_head no_chunk_orphans;
115         struct list_head no_device_orphans;
116 };
117
118 #endif