[BTRFS]
[reactos.git] / reactos / drivers / filesystems / btrfs / btrfs.h
1 /* btrfs.h
2 * Generic btrfs header file. Thanks to whoever it was who wrote
3 * https://btrfs.wiki.kernel.org/index.php/On-disk_Format - you saved me a lot of time!
4 *
5 * I release this file, and this file only, into the public domain - do whatever
6 * you want with it. You don't have to, but I'd appreciate if you let me know if you
7 * use it anything cool - mark@harmstone.com. */
8
9 #ifndef BTRFS_H_DEFINED
10 #define BTRFS_H_DEFINED
11
12 static const UINT64 superblock_addrs[] = { 0x10000, 0x4000000, 0x4000000000, 0x4000000000000, 0 };
13
14 #define BTRFS_MAGIC 0x4d5f53665248425f
15 #define MAX_LABEL_SIZE 0x100
16 #define SUBVOL_ROOT_INODE 0x100
17
18 #define TYPE_INODE_ITEM 0x01
19 #define TYPE_INODE_REF 0x0C
20 #define TYPE_INODE_EXTREF 0x0D
21 #define TYPE_XATTR_ITEM 0x18
22 #define TYPE_DIR_ITEM 0x54
23 #define TYPE_DIR_INDEX 0x60
24 #define TYPE_EXTENT_DATA 0x6C
25 #define TYPE_EXTENT_CSUM 0x80
26 #define TYPE_ROOT_ITEM 0x84
27 #define TYPE_ROOT_BACKREF 0x90
28 #define TYPE_ROOT_REF 0x9C
29 #define TYPE_EXTENT_ITEM 0xA8
30 #define TYPE_METADATA_ITEM 0xA9
31 #define TYPE_TREE_BLOCK_REF 0xB0
32 #define TYPE_EXTENT_DATA_REF 0xB2
33 #define TYPE_EXTENT_REF_V0 0xB4
34 #define TYPE_SHARED_BLOCK_REF 0xB6
35 #define TYPE_SHARED_DATA_REF 0xB8
36 #define TYPE_BLOCK_GROUP_ITEM 0xC0
37 #define TYPE_DEV_EXTENT 0xCC
38 #define TYPE_DEV_ITEM 0xD8
39 #define TYPE_CHUNK_ITEM 0xE4
40
41 #define BTRFS_ROOT_ROOT 1
42 #define BTRFS_ROOT_EXTENT 2
43 #define BTRFS_ROOT_CHUNK 3
44 #define BTRFS_ROOT_DEVTREE 4
45 #define BTRFS_ROOT_FSTREE 5
46 #define BTRFS_ROOT_CHECKSUM 7
47
48 #define BTRFS_COMPRESSION_NONE 0
49 #define BTRFS_COMPRESSION_ZLIB 1
50 #define BTRFS_COMPRESSION_LZO 2
51
52 #define BTRFS_ENCRYPTION_NONE 0
53
54 #define BTRFS_ENCODING_NONE 0
55
56 #define EXTENT_TYPE_INLINE 0
57 #define EXTENT_TYPE_REGULAR 1
58 #define EXTENT_TYPE_PREALLOC 2
59
60 #define BLOCK_FLAG_DATA 0x001
61 #define BLOCK_FLAG_SYSTEM 0x002
62 #define BLOCK_FLAG_METADATA 0x004
63 #define BLOCK_FLAG_RAID0 0x008
64 #define BLOCK_FLAG_RAID1 0x010
65 #define BLOCK_FLAG_DUPLICATE 0x020
66 #define BLOCK_FLAG_RAID10 0x040
67 #define BLOCK_FLAG_RAID5 0x080
68 #define BLOCK_FLAG_RAID6 0x100
69
70 #define FREE_SPACE_CACHE_ID 0xFFFFFFFFFFFFFFF5
71 #define EXTENT_CSUM_ID 0xFFFFFFFFFFFFFFF6
72
73 #define BTRFS_INODE_NODATASUM 0x001
74 #define BTRFS_INODE_NODATACOW 0x002
75 #define BTRFS_INODE_READONLY 0x004
76 #define BTRFS_INODE_NOCOMPRESS 0x008
77 #define BTRFS_INODE_PREALLOC 0x010
78 #define BTRFS_INODE_SYNC 0x020
79 #define BTRFS_INODE_IMMUTABLE 0x040
80 #define BTRFS_INODE_APPEND 0x080
81 #define BTRFS_INODE_NODUMP 0x100
82 #define BTRFS_INODE_NOATIME 0x200
83 #define BTRFS_INODE_DIRSYNC 0x400
84 #define BTRFS_INODE_COMPRESS 0x800
85
86 #define BTRFS_SUBVOL_READONLY 0x1
87
88 #define BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE 0x1
89
90 #define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF 0x0001
91 #define BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL 0x0002
92 #define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS 0x0004
93 #define BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO 0x0008
94 #define BTRFS_INCOMPAT_FLAGS_COMPRESS_LZOV2 0x0010
95 #define BTRFS_INCOMPAT_FLAGS_BIG_METADATA 0x0020
96 #define BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF 0x0040
97 #define BTRFS_INCOMPAT_FLAGS_RAID56 0x0080
98 #define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA 0x0100
99 #define BTRFS_INCOMPAT_FLAGS_NO_HOLES 0x0200
100
101 #pragma pack(push, 1)
102
103 typedef struct {
104 UINT8 uuid[16];
105 } BTRFS_UUID;
106
107 typedef struct {
108 UINT64 obj_id;
109 UINT8 obj_type;
110 UINT64 offset;
111 } KEY;
112
113 #define HEADER_FLAG_MIXED_BACKREF 0x100000000000000
114 #define HEADER_FLAG_SHARED_BACKREF 0x000000000000002
115
116 typedef struct {
117 UINT8 csum[32];
118 BTRFS_UUID fs_uuid;
119 UINT64 address;
120 UINT64 flags;
121 BTRFS_UUID chunk_tree_uuid;
122 UINT64 generation;
123 UINT64 tree_id;
124 UINT32 num_items;
125 UINT8 level;
126 } tree_header;
127
128 typedef struct {
129 KEY key;
130 UINT32 offset;
131 UINT32 size;
132 } leaf_node;
133
134 typedef struct {
135 KEY key;
136 UINT64 address;
137 UINT64 generation;
138 } internal_node;
139
140 typedef struct {
141 UINT64 dev_id;
142 UINT64 num_bytes;
143 UINT64 bytes_used;
144 UINT32 optimal_io_align;
145 UINT32 optimal_io_width;
146 UINT32 minimal_io_size;
147 UINT64 type;
148 UINT64 generation;
149 UINT64 start_offset;
150 UINT32 dev_group;
151 UINT8 seek_speed;
152 UINT8 bandwidth;
153 BTRFS_UUID device_uuid;
154 BTRFS_UUID fs_uuid;
155 } DEV_ITEM;
156
157 #define SYS_CHUNK_ARRAY_SIZE 0x800
158
159 typedef struct {
160 UINT8 checksum[32];
161 BTRFS_UUID uuid;
162 UINT64 sb_phys_addr;
163 UINT64 flags;
164 UINT64 magic;
165 UINT64 generation;
166 UINT64 root_tree_addr;
167 UINT64 chunk_tree_addr;
168 UINT64 log_tree_addr;
169 UINT64 log_root_transid;
170 UINT64 total_bytes;
171 UINT64 bytes_used;
172 UINT64 root_dir_objectid;
173 UINT64 num_devices;
174 UINT32 sector_size;
175 UINT32 node_size;
176 UINT32 leaf_size;
177 UINT32 stripe_size;
178 UINT32 n;
179 UINT64 chunk_root_generation;
180 UINT64 compat_flags;
181 UINT64 compat_ro_flags;
182 UINT64 incompat_flags;
183 UINT16 csum_type;
184 UINT8 root_level;
185 UINT8 chunk_root_level;
186 UINT8 log_root_level;
187 DEV_ITEM dev_item;
188 char label[MAX_LABEL_SIZE];
189 UINT64 cache_generation;
190 UINT64 uuid_tree_generation;
191 UINT64 reserved[30];
192 UINT8 sys_chunk_array[SYS_CHUNK_ARRAY_SIZE];
193 // struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
194 UINT8 reserved2[1237];
195 } superblock;
196
197 #define BTRFS_TYPE_UNKNOWN 0
198 #define BTRFS_TYPE_FILE 1
199 #define BTRFS_TYPE_DIRECTORY 2
200 #define BTRFS_TYPE_CHARDEV 3
201 #define BTRFS_TYPE_BLOCKDEV 4
202 #define BTRFS_TYPE_FIFO 5
203 #define BTRFS_TYPE_SOCKET 6
204 #define BTRFS_TYPE_SYMLINK 7
205 #define BTRFS_TYPE_EA 8
206
207 typedef struct {
208 KEY key;
209 UINT64 transid;
210 UINT16 m;
211 UINT16 n;
212 UINT8 type;
213 char name[1];
214 } DIR_ITEM;
215
216 typedef struct {
217 UINT64 seconds;
218 UINT32 nanoseconds;
219 } BTRFS_TIME;
220
221 typedef struct {
222 UINT64 generation;
223 UINT64 transid;
224 UINT64 st_size;
225 UINT64 st_blocks;
226 UINT64 block_group;
227 UINT32 st_nlink;
228 UINT32 st_uid;
229 UINT32 st_gid;
230 UINT32 st_mode;
231 UINT64 st_rdev;
232 UINT64 flags;
233 UINT64 sequence;
234 UINT8 reserved[32];
235 BTRFS_TIME st_atime;
236 BTRFS_TIME st_ctime;
237 BTRFS_TIME st_mtime;
238 BTRFS_TIME otime;
239 } INODE_ITEM;
240
241 typedef struct {
242 INODE_ITEM inode;
243 UINT64 generation;
244 UINT64 objid;
245 UINT64 block_number;
246 UINT64 byte_limit;
247 UINT64 bytes_used;
248 UINT64 last_snapshot_generation;
249 UINT64 flags;
250 UINT32 num_references;
251 KEY drop_progress;
252 UINT8 drop_level;
253 UINT8 root_level;
254 UINT64 generation2;
255 BTRFS_UUID uuid;
256 BTRFS_UUID parent_uuid;
257 BTRFS_UUID received_uuid;
258 UINT64 ctransid;
259 UINT64 otransid;
260 UINT64 stransid;
261 UINT64 rtransid;
262 BTRFS_TIME ctime;
263 BTRFS_TIME otime;
264 BTRFS_TIME stime;
265 BTRFS_TIME rtime;
266 UINT64 reserved[8];
267 } ROOT_ITEM;
268
269 typedef struct {
270 UINT64 size;
271 UINT64 root_id;
272 UINT64 stripe_length;
273 UINT64 type;
274 UINT32 opt_io_alignment;
275 UINT32 opt_io_width;
276 UINT32 sector_size;
277 UINT16 num_stripes;
278 UINT16 sub_stripes;
279 } CHUNK_ITEM;
280
281 typedef struct {
282 UINT64 dev_id;
283 UINT64 offset;
284 BTRFS_UUID dev_uuid;
285 } CHUNK_ITEM_STRIPE;
286
287 typedef struct {
288 UINT64 generation;
289 UINT64 decoded_size;
290 UINT8 compression;
291 UINT8 encryption;
292 UINT16 encoding;
293 UINT8 type;
294 UINT8 data[1];
295 } EXTENT_DATA;
296
297 typedef struct {
298 UINT64 address;
299 UINT64 size;
300 UINT64 offset;
301 UINT64 num_bytes;
302 } EXTENT_DATA2;
303
304 typedef struct {
305 UINT64 index;
306 UINT16 n;
307 char name[1];
308 } INODE_REF;
309
310 typedef struct {
311 UINT64 dir;
312 UINT64 index;
313 UINT16 n;
314 char name[1];
315 } INODE_EXTREF;
316
317 #define EXTENT_ITEM_DATA 0x001
318 #define EXTENT_ITEM_TREE_BLOCK 0x002
319 #define EXTENT_ITEM_SHARED_BACKREFS 0x100
320
321 typedef struct {
322 UINT64 refcount;
323 UINT64 generation;
324 UINT64 flags;
325 } EXTENT_ITEM;
326
327 typedef struct {
328 UINT32 refcount;
329 } EXTENT_ITEM_V0;
330
331 typedef struct {
332 EXTENT_ITEM extent_item;
333 KEY firstitem;
334 UINT8 level;
335 } EXTENT_ITEM_TREE;
336
337 typedef struct {
338 UINT64 offset;
339 } TREE_BLOCK_REF;
340
341 typedef struct {
342 UINT64 root;
343 UINT64 objid;
344 UINT64 offset;
345 UINT32 count;
346 } EXTENT_DATA_REF;
347
348 typedef struct {
349 UINT64 used;
350 UINT64 chunk_tree;
351 UINT64 flags;
352 } BLOCK_GROUP_ITEM;
353
354 typedef struct {
355 UINT64 root;
356 UINT64 gen;
357 UINT64 objid;
358 UINT64 count;
359 } EXTENT_REF_V0;
360
361 typedef struct {
362 UINT64 offset;
363 } SHARED_BLOCK_REF;
364
365 typedef struct {
366 UINT64 offset;
367 UINT32 count;
368 } SHARED_DATA_REF;
369
370 #define FREE_SPACE_EXTENT 1
371 #define FREE_SPACE_BITMAP 2
372
373 typedef struct {
374 UINT64 offset;
375 UINT64 size;
376 UINT8 type;
377 } FREE_SPACE_ENTRY;
378
379 typedef struct {
380 KEY key;
381 UINT64 generation;
382 UINT64 num_entries;
383 UINT64 num_bitmaps;
384 } FREE_SPACE_ITEM;
385
386 typedef struct {
387 UINT64 dir;
388 UINT64 index;
389 UINT16 n;
390 char name[1];
391 } ROOT_REF;
392
393 typedef struct {
394 UINT64 chunktree;
395 UINT64 objid;
396 UINT64 address;
397 UINT64 length;
398 BTRFS_UUID chunktree_uuid;
399 } DEV_EXTENT;
400
401 #pragma pack(pop)
402
403 #endif