[BTRFS] Upgrade to 1.0.2
[reactos.git] / 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_FREE_SPACE_INFO 0xC6
38 #define TYPE_FREE_SPACE_EXTENT 0xC7
39 #define TYPE_FREE_SPACE_BITMAP 0xC8
40 #define TYPE_DEV_EXTENT 0xCC
41 #define TYPE_DEV_ITEM 0xD8
42 #define TYPE_CHUNK_ITEM 0xE4
43 #define TYPE_TEMP_ITEM 0xF8
44 #define TYPE_DEV_STATS 0xF9
45 #define TYPE_SUBVOL_UUID 0xFB
46 #define TYPE_SUBVOL_REC_UUID 0xFC
47
48 #define BTRFS_ROOT_ROOT 1
49 #define BTRFS_ROOT_EXTENT 2
50 #define BTRFS_ROOT_CHUNK 3
51 #define BTRFS_ROOT_DEVTREE 4
52 #define BTRFS_ROOT_FSTREE 5
53 #define BTRFS_ROOT_CHECKSUM 7
54 #define BTRFS_ROOT_UUID 9
55 #define BTRFS_ROOT_FREE_SPACE 0xa
56 #define BTRFS_ROOT_DATA_RELOC 0xFFFFFFFFFFFFFFF7
57
58 #define BTRFS_COMPRESSION_NONE 0
59 #define BTRFS_COMPRESSION_ZLIB 1
60 #define BTRFS_COMPRESSION_LZO 2
61
62 #define BTRFS_ENCRYPTION_NONE 0
63
64 #define BTRFS_ENCODING_NONE 0
65
66 #define EXTENT_TYPE_INLINE 0
67 #define EXTENT_TYPE_REGULAR 1
68 #define EXTENT_TYPE_PREALLOC 2
69
70 #define BLOCK_FLAG_DATA 0x001
71 #define BLOCK_FLAG_SYSTEM 0x002
72 #define BLOCK_FLAG_METADATA 0x004
73 #define BLOCK_FLAG_RAID0 0x008
74 #define BLOCK_FLAG_RAID1 0x010
75 #define BLOCK_FLAG_DUPLICATE 0x020
76 #define BLOCK_FLAG_RAID10 0x040
77 #define BLOCK_FLAG_RAID5 0x080
78 #define BLOCK_FLAG_RAID6 0x100
79
80 #define FREE_SPACE_CACHE_ID 0xFFFFFFFFFFFFFFF5
81 #define EXTENT_CSUM_ID 0xFFFFFFFFFFFFFFF6
82 #define BALANCE_ITEM_ID 0xFFFFFFFFFFFFFFFC
83
84 #define BTRFS_INODE_NODATASUM 0x001
85 #define BTRFS_INODE_NODATACOW 0x002
86 #define BTRFS_INODE_READONLY 0x004
87 #define BTRFS_INODE_NOCOMPRESS 0x008
88 #define BTRFS_INODE_PREALLOC 0x010
89 #define BTRFS_INODE_SYNC 0x020
90 #define BTRFS_INODE_IMMUTABLE 0x040
91 #define BTRFS_INODE_APPEND 0x080
92 #define BTRFS_INODE_NODUMP 0x100
93 #define BTRFS_INODE_NOATIME 0x200
94 #define BTRFS_INODE_DIRSYNC 0x400
95 #define BTRFS_INODE_COMPRESS 0x800
96
97 #define BTRFS_SUBVOL_READONLY 0x1
98
99 #define BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE 0x1
100 #define BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE_VALID 0x2
101
102 #define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF 0x0001
103 #define BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL 0x0002
104 #define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS 0x0004
105 #define BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO 0x0008
106 #define BTRFS_INCOMPAT_FLAGS_COMPRESS_LZOV2 0x0010
107 #define BTRFS_INCOMPAT_FLAGS_BIG_METADATA 0x0020
108 #define BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF 0x0040
109 #define BTRFS_INCOMPAT_FLAGS_RAID56 0x0080
110 #define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA 0x0100
111 #define BTRFS_INCOMPAT_FLAGS_NO_HOLES 0x0200
112
113 #define BTRFS_SUPERBLOCK_FLAGS_SEEDING 0x100000000
114
115 #pragma pack(push, 1)
116
117 typedef struct {
118 UINT8 uuid[16];
119 } BTRFS_UUID;
120
121 typedef struct {
122 UINT64 obj_id;
123 UINT8 obj_type;
124 UINT64 offset;
125 } KEY;
126
127 #define HEADER_FLAG_WRITTEN 0x000000000000001
128 #define HEADER_FLAG_SHARED_BACKREF 0x000000000000002
129 #define HEADER_FLAG_MIXED_BACKREF 0x100000000000000
130
131 typedef struct {
132 UINT8 csum[32];
133 BTRFS_UUID fs_uuid;
134 UINT64 address;
135 UINT64 flags;
136 BTRFS_UUID chunk_tree_uuid;
137 UINT64 generation;
138 UINT64 tree_id;
139 UINT32 num_items;
140 UINT8 level;
141 } tree_header;
142
143 typedef struct {
144 KEY key;
145 UINT32 offset;
146 UINT32 size;
147 } leaf_node;
148
149 typedef struct {
150 KEY key;
151 UINT64 address;
152 UINT64 generation;
153 } internal_node;
154
155 typedef struct {
156 UINT64 dev_id;
157 UINT64 num_bytes;
158 UINT64 bytes_used;
159 UINT32 optimal_io_align;
160 UINT32 optimal_io_width;
161 UINT32 minimal_io_size;
162 UINT64 type;
163 UINT64 generation;
164 UINT64 start_offset;
165 UINT32 dev_group;
166 UINT8 seek_speed;
167 UINT8 bandwidth;
168 BTRFS_UUID device_uuid;
169 BTRFS_UUID fs_uuid;
170 } DEV_ITEM;
171
172 #define SYS_CHUNK_ARRAY_SIZE 0x800
173 #define BTRFS_NUM_BACKUP_ROOTS 4
174
175 typedef struct {
176 UINT64 root_tree_addr;
177 UINT64 root_tree_generation;
178 UINT64 chunk_tree_addr;
179 UINT64 chunk_tree_generation;
180 UINT64 extent_tree_addr;
181 UINT64 extent_tree_generation;
182 UINT64 fs_tree_addr;
183 UINT64 fs_tree_generation;
184 UINT64 dev_root_addr;
185 UINT64 dev_root_generation;
186 UINT64 csum_root_addr;
187 UINT64 csum_root_generation;
188 UINT64 total_bytes;
189 UINT64 bytes_used;
190 UINT64 num_devices;
191 UINT64 reserved[4];
192 UINT8 root_level;
193 UINT8 chunk_root_level;
194 UINT8 extent_root_level;
195 UINT8 fs_root_level;
196 UINT8 dev_root_level;
197 UINT8 csum_root_level;
198 UINT8 reserved2[10];
199 } superblock_backup;
200
201 typedef struct {
202 UINT8 checksum[32];
203 BTRFS_UUID uuid;
204 UINT64 sb_phys_addr;
205 UINT64 flags;
206 UINT64 magic;
207 UINT64 generation;
208 UINT64 root_tree_addr;
209 UINT64 chunk_tree_addr;
210 UINT64 log_tree_addr;
211 UINT64 log_root_transid;
212 UINT64 total_bytes;
213 UINT64 bytes_used;
214 UINT64 root_dir_objectid;
215 UINT64 num_devices;
216 UINT32 sector_size;
217 UINT32 node_size;
218 UINT32 leaf_size;
219 UINT32 stripe_size;
220 UINT32 n;
221 UINT64 chunk_root_generation;
222 UINT64 compat_flags;
223 UINT64 compat_ro_flags;
224 UINT64 incompat_flags;
225 UINT16 csum_type;
226 UINT8 root_level;
227 UINT8 chunk_root_level;
228 UINT8 log_root_level;
229 DEV_ITEM dev_item;
230 char label[MAX_LABEL_SIZE];
231 UINT64 cache_generation;
232 UINT64 uuid_tree_generation;
233 UINT64 reserved[30];
234 UINT8 sys_chunk_array[SYS_CHUNK_ARRAY_SIZE];
235 superblock_backup backup[BTRFS_NUM_BACKUP_ROOTS];
236 UINT8 reserved2[565];
237 } superblock;
238
239 #define BTRFS_TYPE_UNKNOWN 0
240 #define BTRFS_TYPE_FILE 1
241 #define BTRFS_TYPE_DIRECTORY 2
242 #define BTRFS_TYPE_CHARDEV 3
243 #define BTRFS_TYPE_BLOCKDEV 4
244 #define BTRFS_TYPE_FIFO 5
245 #define BTRFS_TYPE_SOCKET 6
246 #define BTRFS_TYPE_SYMLINK 7
247 #define BTRFS_TYPE_EA 8
248
249 typedef struct {
250 KEY key;
251 UINT64 transid;
252 UINT16 m;
253 UINT16 n;
254 UINT8 type;
255 char name[1];
256 } DIR_ITEM;
257
258 typedef struct {
259 UINT64 seconds;
260 UINT32 nanoseconds;
261 } BTRFS_TIME;
262
263 typedef struct {
264 UINT64 generation;
265 UINT64 transid;
266 UINT64 st_size;
267 UINT64 st_blocks;
268 UINT64 block_group;
269 UINT32 st_nlink;
270 UINT32 st_uid;
271 UINT32 st_gid;
272 UINT32 st_mode;
273 UINT64 st_rdev;
274 UINT64 flags;
275 UINT64 sequence;
276 UINT8 reserved[32];
277 BTRFS_TIME st_atime;
278 BTRFS_TIME st_ctime;
279 BTRFS_TIME st_mtime;
280 BTRFS_TIME otime;
281 } INODE_ITEM;
282
283 typedef struct {
284 INODE_ITEM inode;
285 UINT64 generation;
286 UINT64 objid;
287 UINT64 block_number;
288 UINT64 byte_limit;
289 UINT64 bytes_used;
290 UINT64 last_snapshot_generation;
291 UINT64 flags;
292 UINT32 num_references;
293 KEY drop_progress;
294 UINT8 drop_level;
295 UINT8 root_level;
296 UINT64 generation2;
297 BTRFS_UUID uuid;
298 BTRFS_UUID parent_uuid;
299 BTRFS_UUID received_uuid;
300 UINT64 ctransid;
301 UINT64 otransid;
302 UINT64 stransid;
303 UINT64 rtransid;
304 BTRFS_TIME ctime;
305 BTRFS_TIME otime;
306 BTRFS_TIME stime;
307 BTRFS_TIME rtime;
308 UINT64 reserved[8];
309 } ROOT_ITEM;
310
311 typedef struct {
312 UINT64 size;
313 UINT64 root_id;
314 UINT64 stripe_length;
315 UINT64 type;
316 UINT32 opt_io_alignment;
317 UINT32 opt_io_width;
318 UINT32 sector_size;
319 UINT16 num_stripes;
320 UINT16 sub_stripes;
321 } CHUNK_ITEM;
322
323 typedef struct {
324 UINT64 dev_id;
325 UINT64 offset;
326 BTRFS_UUID dev_uuid;
327 } CHUNK_ITEM_STRIPE;
328
329 typedef struct {
330 UINT64 generation;
331 UINT64 decoded_size;
332 UINT8 compression;
333 UINT8 encryption;
334 UINT16 encoding;
335 UINT8 type;
336 UINT8 data[1];
337 } EXTENT_DATA;
338
339 typedef struct {
340 UINT64 address;
341 UINT64 size;
342 UINT64 offset;
343 UINT64 num_bytes;
344 } EXTENT_DATA2;
345
346 typedef struct {
347 UINT64 index;
348 UINT16 n;
349 char name[1];
350 } INODE_REF;
351
352 typedef struct {
353 UINT64 dir;
354 UINT64 index;
355 UINT16 n;
356 char name[1];
357 } INODE_EXTREF;
358
359 #define EXTENT_ITEM_DATA 0x001
360 #define EXTENT_ITEM_TREE_BLOCK 0x002
361 #define EXTENT_ITEM_SHARED_BACKREFS 0x100
362
363 typedef struct {
364 UINT64 refcount;
365 UINT64 generation;
366 UINT64 flags;
367 } EXTENT_ITEM;
368
369 typedef struct {
370 KEY firstitem;
371 UINT8 level;
372 } EXTENT_ITEM2;
373
374 typedef struct {
375 UINT32 refcount;
376 } EXTENT_ITEM_V0;
377
378 typedef struct {
379 EXTENT_ITEM extent_item;
380 KEY firstitem;
381 UINT8 level;
382 } EXTENT_ITEM_TREE;
383
384 typedef struct {
385 UINT64 offset;
386 } TREE_BLOCK_REF;
387
388 typedef struct {
389 UINT64 root;
390 UINT64 objid;
391 UINT64 offset;
392 UINT32 count;
393 } EXTENT_DATA_REF;
394
395 typedef struct {
396 UINT64 used;
397 UINT64 chunk_tree;
398 UINT64 flags;
399 } BLOCK_GROUP_ITEM;
400
401 typedef struct {
402 UINT64 root;
403 UINT64 gen;
404 UINT64 objid;
405 UINT32 count;
406 } EXTENT_REF_V0;
407
408 typedef struct {
409 UINT64 offset;
410 } SHARED_BLOCK_REF;
411
412 typedef struct {
413 UINT64 offset;
414 UINT32 count;
415 } SHARED_DATA_REF;
416
417 #define FREE_SPACE_EXTENT 1
418 #define FREE_SPACE_BITMAP 2
419
420 typedef struct {
421 UINT64 offset;
422 UINT64 size;
423 UINT8 type;
424 } FREE_SPACE_ENTRY;
425
426 typedef struct {
427 KEY key;
428 UINT64 generation;
429 UINT64 num_entries;
430 UINT64 num_bitmaps;
431 } FREE_SPACE_ITEM;
432
433 typedef struct {
434 UINT64 dir;
435 UINT64 index;
436 UINT16 n;
437 char name[1];
438 } ROOT_REF;
439
440 typedef struct {
441 UINT64 chunktree;
442 UINT64 objid;
443 UINT64 address;
444 UINT64 length;
445 BTRFS_UUID chunktree_uuid;
446 } DEV_EXTENT;
447
448 #define BALANCE_FLAGS_DATA 0x1
449 #define BALANCE_FLAGS_SYSTEM 0x2
450 #define BALANCE_FLAGS_METADATA 0x4
451
452 #define BALANCE_ARGS_FLAGS_PROFILES 0x001
453 #define BALANCE_ARGS_FLAGS_USAGE 0x002
454 #define BALANCE_ARGS_FLAGS_DEVID 0x004
455 #define BALANCE_ARGS_FLAGS_DRANGE 0x008
456 #define BALANCE_ARGS_FLAGS_VRANGE 0x010
457 #define BALANCE_ARGS_FLAGS_LIMIT 0x020
458 #define BALANCE_ARGS_FLAGS_LIMIT_RANGE 0x040
459 #define BALANCE_ARGS_FLAGS_STRIPES_RANGE 0x080
460 #define BALANCE_ARGS_FLAGS_CONVERT 0x100
461 #define BALANCE_ARGS_FLAGS_SOFT 0x200
462 #define BALANCE_ARGS_FLAGS_USAGE_RANGE 0x400
463
464 typedef struct {
465 UINT64 profiles;
466
467 union {
468 UINT64 usage;
469 struct {
470 UINT32 usage_start;
471 UINT32 usage_end;
472 };
473 };
474
475 UINT64 devid;
476 UINT64 drange_start;
477 UINT64 drange_end;
478 UINT64 vrange_start;
479 UINT64 vrange_end;
480 UINT64 convert;
481 UINT64 flags;
482
483 union {
484 UINT64 limit;
485 struct {
486 UINT32 limit_start;
487 UINT32 limit_end;
488 };
489 };
490
491 UINT32 stripes_start;
492 UINT32 stripes_end;
493 UINT8 reserved[48];
494 } BALANCE_ARGS;
495
496 typedef struct {
497 UINT64 flags;
498 BALANCE_ARGS data;
499 BALANCE_ARGS metadata;
500 BALANCE_ARGS system;
501 UINT8 reserved[32];
502 } BALANCE_ITEM;
503
504 #define BTRFS_FREE_SPACE_USING_BITMAPS 1
505
506 typedef struct {
507 UINT32 count;
508 UINT32 flags;
509 } FREE_SPACE_INFO;
510
511 #define BTRFS_DEV_STAT_WRITE_ERRORS 0
512 #define BTRFS_DEV_STAT_READ_ERRORS 1
513 #define BTRFS_DEV_STAT_FLUSH_ERRORS 2
514 #define BTRFS_DEV_STAT_CORRUPTION_ERRORS 3
515 #define BTRFS_DEV_STAT_GENERATION_ERRORS 4
516
517 #define BTRFS_SEND_CMD_SUBVOL 1
518 #define BTRFS_SEND_CMD_SNAPSHOT 2
519 #define BTRFS_SEND_CMD_MKFILE 3
520 #define BTRFS_SEND_CMD_MKDIR 4
521 #define BTRFS_SEND_CMD_MKNOD 5
522 #define BTRFS_SEND_CMD_MKFIFO 6
523 #define BTRFS_SEND_CMD_MKSOCK 7
524 #define BTRFS_SEND_CMD_SYMLINK 8
525 #define BTRFS_SEND_CMD_RENAME 9
526 #define BTRFS_SEND_CMD_LINK 10
527 #define BTRFS_SEND_CMD_UNLINK 11
528 #define BTRFS_SEND_CMD_RMDIR 12
529 #define BTRFS_SEND_CMD_SET_XATTR 13
530 #define BTRFS_SEND_CMD_REMOVE_XATTR 14
531 #define BTRFS_SEND_CMD_WRITE 15
532 #define BTRFS_SEND_CMD_CLONE 16
533 #define BTRFS_SEND_CMD_TRUNCATE 17
534 #define BTRFS_SEND_CMD_CHMOD 18
535 #define BTRFS_SEND_CMD_CHOWN 19
536 #define BTRFS_SEND_CMD_UTIMES 20
537 #define BTRFS_SEND_CMD_END 21
538 #define BTRFS_SEND_CMD_UPDATE_EXTENT 22
539
540 #define BTRFS_SEND_TLV_UUID 1
541 #define BTRFS_SEND_TLV_TRANSID 2
542 #define BTRFS_SEND_TLV_INODE 3
543 #define BTRFS_SEND_TLV_SIZE 4
544 #define BTRFS_SEND_TLV_MODE 5
545 #define BTRFS_SEND_TLV_UID 6
546 #define BTRFS_SEND_TLV_GID 7
547 #define BTRFS_SEND_TLV_RDEV 8
548 #define BTRFS_SEND_TLV_CTIME 9
549 #define BTRFS_SEND_TLV_MTIME 10
550 #define BTRFS_SEND_TLV_ATIME 11
551 #define BTRFS_SEND_TLV_OTIME 12
552 #define BTRFS_SEND_TLV_XATTR_NAME 13
553 #define BTRFS_SEND_TLV_XATTR_DATA 14
554 #define BTRFS_SEND_TLV_PATH 15
555 #define BTRFS_SEND_TLV_PATH_TO 16
556 #define BTRFS_SEND_TLV_PATH_LINK 17
557 #define BTRFS_SEND_TLV_OFFSET 18
558 #define BTRFS_SEND_TLV_DATA 19
559 #define BTRFS_SEND_TLV_CLONE_UUID 20
560 #define BTRFS_SEND_TLV_CLONE_CTRANSID 21
561 #define BTRFS_SEND_TLV_CLONE_PATH 22
562 #define BTRFS_SEND_TLV_CLONE_OFFSET 23
563 #define BTRFS_SEND_TLV_CLONE_LENGTH 24
564
565 #define BTRFS_SEND_MAGIC "btrfs-stream"
566
567 typedef struct {
568 UINT8 magic[13];
569 UINT32 version;
570 } btrfs_send_header;
571
572 typedef struct {
573 UINT32 length;
574 UINT16 cmd;
575 UINT32 csum;
576 } btrfs_send_command;
577
578 typedef struct {
579 UINT16 type;
580 UINT16 length;
581 } btrfs_send_tlv;
582
583 #pragma pack(pop)
584
585 #endif