Add memtest support.
[syslinux-debian/hramrach.git] / core / fs / btrfs / btrfs.h
blobaa1245b4525cb64338b68a51d4e3d1abb8f656e5
1 #ifndef _BTRFS_H_
2 #define _BTRFS_H_
4 #include <stdint.h>
5 #include <zconf.h>
7 typedef uint8_t u8;
8 typedef uint16_t u16;
9 typedef uint32_t u32;
10 typedef uint64_t u64;
11 /* type that store on disk, but it is same as cpu type for i386 arch */
12 typedef u16 __le16;
13 typedef u32 __le32;
14 typedef u64 __le64;
16 #include "crc32c.h"
17 #define btrfs_crc32c crc32c_le
19 #define BTRFS_SUPER_INFO_OFFSET (64 * 1024)
20 #define BTRFS_SUPER_INFO_SIZE 4096
21 #define BTRFS_MAX_LEAF_SIZE 4096
22 #define BTRFS_BLOCK_SHIFT 12
24 #define BTRFS_SUPER_MIRROR_MAX 3
25 #define BTRFS_SUPER_MIRROR_SHIFT 12
26 #define BTRFS_CSUM_SIZE 32
27 #define BTRFS_FSID_SIZE 16
28 #define BTRFS_LABEL_SIZE 256
29 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
30 #define BTRFS_UUID_SIZE 16
32 #define BTRFS_MAGIC "_BHRfS_M"
34 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
36 #define BTRFS_DEV_ITEM_KEY 216
37 #define BTRFS_CHUNK_ITEM_KEY 228
38 #define BTRFS_ROOT_REF_KEY 156
39 #define BTRFS_ROOT_ITEM_KEY 132
40 #define BTRFS_EXTENT_DATA_KEY 108
41 #define BTRFS_DIR_ITEM_KEY 84
42 #define BTRFS_INODE_ITEM_KEY 1
44 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
45 #define BTRFS_FS_TREE_OBJECTID 5ULL
47 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
49 #define BTRFS_FILE_EXTENT_INLINE 0
50 #define BTRFS_FILE_EXTENT_REG 1
51 #define BTRFS_FILE_EXTENT_PREALLOC 2
53 #define BTRFS_MAX_LEVEL 8
54 #define BTRFS_MAX_CHUNK_ENTRIES 256
56 #define BTRFS_FT_REG_FILE 1
57 #define BTRFS_FT_DIR 2
58 #define BTRFS_FT_SYMLINK 7
60 #define ROOT_DIR_WORD 0x002f
62 struct btrfs_dev_item {
63 __le64 devid;
64 __le64 total_bytes;
65 __le64 bytes_used;
66 __le32 io_align;
67 __le32 io_width;
68 __le32 sector_size;
69 __le64 type;
70 __le64 generation;
71 __le64 start_offset;
72 __le32 dev_group;
73 u8 seek_speed;
74 u8 bandwidth;
75 u8 uuid[BTRFS_UUID_SIZE];
76 u8 fsid[BTRFS_UUID_SIZE];
77 } __attribute__ ((__packed__));
79 struct btrfs_super_block {
80 u8 csum[BTRFS_CSUM_SIZE];
81 /* the first 3 fields must match struct btrfs_header */
82 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
83 __le64 bytenr; /* this block number */
84 __le64 flags;
86 /* allowed to be different from the btrfs_header from here own down */
87 __le64 magic;
88 __le64 generation;
89 __le64 root;
90 __le64 chunk_root;
91 __le64 log_root;
93 /* this will help find the new super based on the log root */
94 __le64 log_root_transid;
95 __le64 total_bytes;
96 __le64 bytes_used;
97 __le64 root_dir_objectid;
98 __le64 num_devices;
99 __le32 sectorsize;
100 __le32 nodesize;
101 __le32 leafsize;
102 __le32 stripesize;
103 __le32 sys_chunk_array_size;
104 __le64 chunk_root_generation;
105 __le64 compat_flags;
106 __le64 compat_ro_flags;
107 __le64 incompat_flags;
108 __le16 csum_type;
109 u8 root_level;
110 u8 chunk_root_level;
111 u8 log_root_level;
112 struct btrfs_dev_item dev_item;
114 char label[BTRFS_LABEL_SIZE];
116 /* future expansion */
117 __le64 reserved[32];
118 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
119 } __attribute__ ((__packed__));
121 struct btrfs_disk_key {
122 __le64 objectid;
123 u8 type;
124 __le64 offset;
125 } __attribute__ ((__packed__));
127 struct btrfs_stripe {
128 __le64 devid;
129 __le64 offset;
130 u8 dev_uuid[BTRFS_UUID_SIZE];
131 } __attribute__ ((__packed__));
133 struct btrfs_chunk {
134 __le64 length;
135 __le64 owner;
136 __le64 stripe_len;
137 __le64 type;
138 __le32 io_align;
139 __le32 io_width;
140 __le32 sector_size;
141 __le16 num_stripes;
142 __le16 sub_stripes;
143 struct btrfs_stripe stripe;
144 } __attribute__ ((__packed__));
146 struct btrfs_header {
147 /* these first four must match the super block */
148 u8 csum[BTRFS_CSUM_SIZE];
149 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
150 __le64 bytenr; /* which block this node is supposed to live in */
151 __le64 flags;
153 /* allowed to be different from the super from here on down */
154 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
155 __le64 generation;
156 __le64 owner;
157 __le32 nritems;
158 u8 level;
159 } __attribute__ ((__packed__));
161 struct btrfs_item {
162 struct btrfs_disk_key key;
163 __le32 offset;
164 __le32 size;
165 } __attribute__ ((__packed__));
167 struct btrfs_leaf {
168 struct btrfs_header header;
169 struct btrfs_item items[];
170 } __attribute__ ((__packed__));
172 struct btrfs_key_ptr {
173 struct btrfs_disk_key key;
174 __le64 blockptr;
175 __le64 generation;
176 } __attribute__ ((__packed__));
178 struct btrfs_node {
179 struct btrfs_header header;
180 struct btrfs_key_ptr ptrs[];
181 } __attribute__ ((__packed__));
183 /* remember how we get to a node/leaf */
184 struct btrfs_path {
185 u64 offsets[BTRFS_MAX_LEVEL];
186 int itemsnr[BTRFS_MAX_LEVEL];
187 int slots[BTRFS_MAX_LEVEL];
188 /* remember last slot's item and data */
189 struct btrfs_item item;
190 u8 data[BTRFS_MAX_LEAF_SIZE];
193 /* store logical offset to physical offset mapping */
194 struct btrfs_chunk_map_item {
195 u64 logical;
196 u64 length;
197 u64 devid;
198 u64 physical;
201 struct btrfs_chunk_map {
202 struct btrfs_chunk_map_item *map;
203 u32 map_length;
204 u32 cur_length;
207 struct btrfs_timespec {
208 __le64 sec;
209 __le32 nsec;
210 } __attribute__ ((__packed__));
212 struct btrfs_inode_item {
213 /* nfs style generation number */
214 __le64 generation;
215 /* transid that last touched this inode */
216 __le64 transid;
217 __le64 size;
218 __le64 nbytes;
219 __le64 block_group;
220 __le32 nlink;
221 __le32 uid;
222 __le32 gid;
223 __le32 mode;
224 __le64 rdev;
225 __le64 flags;
227 /* modification sequence number for NFS */
228 __le64 sequence;
231 * a little future expansion, for more than this we can
232 * just grow the inode item and version it
234 __le64 reserved[4];
235 struct btrfs_timespec atime;
236 struct btrfs_timespec ctime;
237 struct btrfs_timespec mtime;
238 struct btrfs_timespec otime;
239 } __attribute__ ((__packed__));
241 struct btrfs_root_item {
242 struct btrfs_inode_item inode;
243 __le64 generation;
244 __le64 root_dirid;
245 __le64 bytenr;
246 __le64 byte_limit;
247 __le64 bytes_used;
248 __le64 last_snapshot;
249 __le64 flags;
250 __le32 refs;
251 struct btrfs_disk_key drop_progress;
252 u8 drop_level;
253 u8 level;
254 } __attribute__ ((__packed__));
256 struct btrfs_dir_item {
257 struct btrfs_disk_key location;
258 __le64 transid;
259 __le16 data_len;
260 __le16 name_len;
261 u8 type;
262 } __attribute__ ((__packed__));
264 struct btrfs_file_extent_item {
265 __le64 generation;
266 __le64 ram_bytes;
267 u8 compression;
268 u8 encryption;
269 __le16 other_encoding; /* spare for later use */
270 u8 type;
271 __le64 disk_bytenr;
272 __le64 disk_num_bytes;
273 __le64 offset;
274 __le64 num_bytes;
275 } __attribute__ ((__packed__));
277 struct btrfs_root_ref {
278 __le64 dirid;
279 __le64 sequence;
280 __le16 name_len;
281 } __attribute__ ((__packed__));
284 * btrfs private inode information
286 struct btrfs_pvt_inode {
287 uint64_t offset;
290 #define PVT(i) ((struct btrfs_pvt_inode *)((i)->pvt))
292 #endif