1
2
3
4
5
6#ifndef __BTRFS_BTRFS_TREE_H__
7#define __BTRFS_BTRFS_TREE_H__
8
9#include <common.h>
10
11#define BTRFS_VOL_NAME_MAX 255
12#define BTRFS_NAME_MAX 255
13#define BTRFS_LABEL_SIZE 256
14#define BTRFS_FSID_SIZE 16
15#define BTRFS_UUID_SIZE 16
16
17
18
19
20
21
22
23
24
25#define BTRFS_ROOT_TREE_OBJECTID 1ULL
26
27
28#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
29
30
31
32
33
34#define BTRFS_CHUNK_TREE_OBJECTID 3ULL
35
36
37
38
39
40#define BTRFS_DEV_TREE_OBJECTID 4ULL
41
42
43#define BTRFS_FS_TREE_OBJECTID 5ULL
44
45
46#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
47
48
49#define BTRFS_CSUM_TREE_OBJECTID 7ULL
50
51
52#define BTRFS_QUOTA_TREE_OBJECTID 8ULL
53
54
55#define BTRFS_UUID_TREE_OBJECTID 9ULL
56
57
58#define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
59
60
61#define BTRFS_DEV_STATS_OBJECTID 0ULL
62
63
64#define BTRFS_BALANCE_OBJECTID -4ULL
65
66
67#define BTRFS_ORPHAN_OBJECTID -5ULL
68
69
70#define BTRFS_TREE_LOG_OBJECTID -6ULL
71#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
72
73
74#define BTRFS_TREE_RELOC_OBJECTID -8ULL
75#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
76
77
78
79
80
81
82#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
83
84
85#define BTRFS_FREE_SPACE_OBJECTID -11ULL
86
87
88
89
90
91#define BTRFS_FREE_INO_OBJECTID -12ULL
92
93
94#define BTRFS_MULTIPLE_OBJECTIDS -255ULL
95
96
97
98
99#define BTRFS_FIRST_FREE_OBJECTID 256ULL
100#define BTRFS_LAST_FREE_OBJECTID -256ULL
101#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
102
103
104
105
106
107
108#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
109
110#define BTRFS_BTREE_INODE_OBJECTID 1
111
112#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
113
114#define BTRFS_DEV_REPLACE_DEVID 0ULL
115
116
117
118
119
120
121#define BTRFS_INODE_ITEM_KEY 1
122#define BTRFS_INODE_REF_KEY 12
123#define BTRFS_INODE_EXTREF_KEY 13
124#define BTRFS_XATTR_ITEM_KEY 24
125#define BTRFS_ORPHAN_ITEM_KEY 48
126
127
128
129
130
131
132#define BTRFS_DIR_LOG_ITEM_KEY 60
133#define BTRFS_DIR_LOG_INDEX_KEY 72
134#define BTRFS_DIR_ITEM_KEY 84
135#define BTRFS_DIR_INDEX_KEY 96
136
137
138
139#define BTRFS_EXTENT_DATA_KEY 108
140
141
142
143
144
145#define BTRFS_EXTENT_CSUM_KEY 128
146
147
148
149
150
151#define BTRFS_ROOT_ITEM_KEY 132
152
153
154
155
156
157#define BTRFS_ROOT_BACKREF_KEY 144
158
159
160
161
162
163
164#define BTRFS_ROOT_REF_KEY 156
165
166
167
168
169
170#define BTRFS_EXTENT_ITEM_KEY 168
171
172
173
174
175
176#define BTRFS_METADATA_ITEM_KEY 169
177
178#define BTRFS_TREE_BLOCK_REF_KEY 176
179
180#define BTRFS_EXTENT_DATA_REF_KEY 178
181
182#define BTRFS_EXTENT_REF_V0_KEY 180
183
184#define BTRFS_SHARED_BLOCK_REF_KEY 182
185
186#define BTRFS_SHARED_DATA_REF_KEY 184
187
188
189
190
191
192#define BTRFS_BLOCK_GROUP_ITEM_KEY 192
193
194
195
196
197
198
199#define BTRFS_FREE_SPACE_INFO_KEY 198
200
201
202
203
204
205#define BTRFS_FREE_SPACE_EXTENT_KEY 199
206
207
208
209
210
211
212
213#define BTRFS_FREE_SPACE_BITMAP_KEY 200
214
215#define BTRFS_DEV_EXTENT_KEY 204
216#define BTRFS_DEV_ITEM_KEY 216
217#define BTRFS_CHUNK_ITEM_KEY 228
218
219
220
221
222
223
224#define BTRFS_QGROUP_STATUS_KEY 240
225
226
227
228
229#define BTRFS_QGROUP_INFO_KEY 242
230
231
232
233
234#define BTRFS_QGROUP_LIMIT_KEY 244
235
236
237
238
239
240
241#define BTRFS_QGROUP_RELATION_KEY 246
242
243
244
245
246#define BTRFS_BALANCE_ITEM_KEY 248
247
248
249
250
251
252
253
254
255
256
257
258
259#define BTRFS_TEMPORARY_ITEM_KEY 248
260
261
262
263
264#define BTRFS_DEV_STATS_KEY 249
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279#define BTRFS_PERSISTENT_ITEM_KEY 249
280
281
282
283
284
285#define BTRFS_DEV_REPLACE_KEY 250
286
287
288
289
290
291
292
293#if BTRFS_UUID_SIZE != 16
294#error "UUID items require BTRFS_UUID_SIZE == 16!"
295#endif
296#define BTRFS_UUID_KEY_SUBVOL 251
297#define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252
298
299
300
301
302
303
304#define BTRFS_STRING_ITEM_KEY 253
305
306
307
308
309#define BTRFS_CSUM_SIZE 32
310
311
312#define BTRFS_CSUM_TYPE_CRC32 0
313
314
315
316
317
318
319
320#define BTRFS_FT_UNKNOWN 0
321#define BTRFS_FT_REG_FILE 1
322#define BTRFS_FT_DIR 2
323#define BTRFS_FT_CHRDEV 3
324#define BTRFS_FT_BLKDEV 4
325#define BTRFS_FT_FIFO 5
326#define BTRFS_FT_SOCK 6
327#define BTRFS_FT_SYMLINK 7
328#define BTRFS_FT_XATTR 8
329#define BTRFS_FT_MAX 9
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345struct btrfs_key {
346 __u64 objectid;
347 __u8 type;
348 __u64 offset;
349} __attribute__ ((__packed__));
350
351struct btrfs_dev_item {
352
353 __u64 devid;
354
355
356 __u64 total_bytes;
357
358
359 __u64 bytes_used;
360
361
362 __u32 io_align;
363
364
365 __u32 io_width;
366
367
368 __u32 sector_size;
369
370
371 __u64 type;
372
373
374 __u64 generation;
375
376
377
378
379
380 __u64 start_offset;
381
382
383 __u32 dev_group;
384
385
386 __u8 seek_speed;
387
388
389 __u8 bandwidth;
390
391
392 __u8 uuid[BTRFS_UUID_SIZE];
393
394
395 __u8 fsid[BTRFS_UUID_SIZE];
396} __attribute__ ((__packed__));
397
398struct btrfs_stripe {
399 __u64 devid;
400 __u64 offset;
401 __u8 dev_uuid[BTRFS_UUID_SIZE];
402} __attribute__ ((__packed__));
403
404struct btrfs_chunk {
405
406 __u64 length;
407
408
409 __u64 owner;
410
411 __u64 stripe_len;
412 __u64 type;
413
414
415 __u32 io_align;
416
417
418 __u32 io_width;
419
420
421 __u32 sector_size;
422
423
424
425
426 __u16 num_stripes;
427
428
429 __u16 sub_stripes;
430 struct btrfs_stripe stripe;
431
432} __attribute__ ((__packed__));
433
434#define BTRFS_FREE_SPACE_EXTENT 1
435#define BTRFS_FREE_SPACE_BITMAP 2
436
437struct btrfs_free_space_entry {
438 __u64 offset;
439 __u64 bytes;
440 __u8 type;
441} __attribute__ ((__packed__));
442
443struct btrfs_free_space_header {
444 struct btrfs_key location;
445 __u64 generation;
446 __u64 num_entries;
447 __u64 num_bitmaps;
448} __attribute__ ((__packed__));
449
450#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
451#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
452
453
454
455#define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
456
457#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
458#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
459
460
461
462
463
464
465
466struct btrfs_extent_item {
467 __u64 refs;
468 __u64 generation;
469 __u64 flags;
470} __attribute__ ((__packed__));
471
472
473#define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
474#define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
475
476
477
478
479#define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
480
481
482
483
484
485#define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
486
487struct btrfs_tree_block_info {
488 struct btrfs_key key;
489 __u8 level;
490} __attribute__ ((__packed__));
491
492struct btrfs_extent_data_ref {
493 __u64 root;
494 __u64 objectid;
495 __u64 offset;
496 __u32 count;
497} __attribute__ ((__packed__));
498
499struct btrfs_shared_data_ref {
500 __u32 count;
501} __attribute__ ((__packed__));
502
503struct btrfs_extent_inline_ref {
504 __u8 type;
505 __u64 offset;
506} __attribute__ ((__packed__));
507
508
509
510
511
512struct btrfs_dev_extent {
513 __u64 chunk_tree;
514 __u64 chunk_objectid;
515 __u64 chunk_offset;
516 __u64 length;
517 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
518} __attribute__ ((__packed__));
519
520struct btrfs_inode_ref {
521 __u64 index;
522 __u16 name_len;
523
524} __attribute__ ((__packed__));
525
526struct btrfs_inode_extref {
527 __u64 parent_objectid;
528 __u64 index;
529 __u16 name_len;
530 __u8 name[0];
531
532} __attribute__ ((__packed__));
533
534struct btrfs_timespec {
535 __u64 sec;
536 __u32 nsec;
537} __attribute__ ((__packed__));
538
539struct btrfs_inode_item {
540
541 __u64 generation;
542
543 __u64 transid;
544 __u64 size;
545 __u64 nbytes;
546 __u64 block_group;
547 __u32 nlink;
548 __u32 uid;
549 __u32 gid;
550 __u32 mode;
551 __u64 rdev;
552 __u64 flags;
553
554
555 __u64 sequence;
556
557
558
559
560
561 __u64 reserved[4];
562 struct btrfs_timespec atime;
563 struct btrfs_timespec ctime;
564 struct btrfs_timespec mtime;
565 struct btrfs_timespec otime;
566} __attribute__ ((__packed__));
567
568struct btrfs_dir_log_item {
569 __u64 end;
570} __attribute__ ((__packed__));
571
572struct btrfs_dir_item {
573 struct btrfs_key location;
574 __u64 transid;
575 __u16 data_len;
576 __u16 name_len;
577 __u8 type;
578} __attribute__ ((__packed__));
579
580#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
581
582
583
584
585
586#define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
587
588struct btrfs_root_item {
589 struct btrfs_inode_item inode;
590 __u64 generation;
591 __u64 root_dirid;
592 __u64 bytenr;
593 __u64 byte_limit;
594 __u64 bytes_used;
595 __u64 last_snapshot;
596 __u64 flags;
597 __u32 refs;
598 struct btrfs_key drop_progress;
599 __u8 drop_level;
600 __u8 level;
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618 __u64 generation_v2;
619 __u8 uuid[BTRFS_UUID_SIZE];
620 __u8 parent_uuid[BTRFS_UUID_SIZE];
621 __u8 received_uuid[BTRFS_UUID_SIZE];
622 __u64 ctransid;
623 __u64 otransid;
624 __u64 stransid;
625 __u64 rtransid;
626 struct btrfs_timespec ctime;
627 struct btrfs_timespec otime;
628 struct btrfs_timespec stime;
629 struct btrfs_timespec rtime;
630 __u64 reserved[8];
631} __attribute__ ((__packed__));
632
633
634
635
636struct btrfs_root_ref {
637 __u64 dirid;
638 __u64 sequence;
639 __u16 name_len;
640} __attribute__ ((__packed__));
641
642#define BTRFS_FILE_EXTENT_INLINE 0
643#define BTRFS_FILE_EXTENT_REG 1
644#define BTRFS_FILE_EXTENT_PREALLOC 2
645
646enum btrfs_compression_type {
647 BTRFS_COMPRESS_NONE = 0,
648 BTRFS_COMPRESS_ZLIB = 1,
649 BTRFS_COMPRESS_LZO = 2,
650 BTRFS_COMPRESS_ZSTD = 3,
651 BTRFS_COMPRESS_TYPES = 3,
652 BTRFS_COMPRESS_LAST = 4,
653};
654
655struct btrfs_file_extent_item {
656
657
658
659 __u64 generation;
660
661
662
663
664
665
666
667 __u64 ram_bytes;
668
669
670
671
672
673
674
675
676 __u8 compression;
677 __u8 encryption;
678 __u16 other_encoding;
679
680
681 __u8 type;
682
683
684
685
686
687
688
689 __u64 disk_bytenr;
690 __u64 disk_num_bytes;
691
692
693
694
695
696
697
698 __u64 offset;
699
700
701
702
703 __u64 num_bytes;
704
705} __attribute__ ((__packed__));
706
707struct btrfs_csum_item {
708 __u8 csum;
709} __attribute__ ((__packed__));
710
711
712#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
713#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
714#define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
715#define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
716#define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
717#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
718#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
719#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
720#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
721#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
722 BTRFS_SPACE_INFO_GLOBAL_RSV)
723
724enum btrfs_raid_types {
725 BTRFS_RAID_RAID10,
726 BTRFS_RAID_RAID1,
727 BTRFS_RAID_DUP,
728 BTRFS_RAID_RAID0,
729 BTRFS_RAID_SINGLE,
730 BTRFS_RAID_RAID5,
731 BTRFS_RAID_RAID6,
732 BTRFS_NR_RAID_TYPES
733};
734
735#define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
736 BTRFS_BLOCK_GROUP_SYSTEM | \
737 BTRFS_BLOCK_GROUP_METADATA)
738
739#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
740 BTRFS_BLOCK_GROUP_RAID1 | \
741 BTRFS_BLOCK_GROUP_RAID5 | \
742 BTRFS_BLOCK_GROUP_RAID6 | \
743 BTRFS_BLOCK_GROUP_DUP | \
744 BTRFS_BLOCK_GROUP_RAID10)
745#define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
746 BTRFS_BLOCK_GROUP_RAID6)
747
748
749
750
751
752
753
754
755#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
756
757
758
759
760
761#define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
762
763#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
764 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
765
766#endif
767