1
2#ifndef _BTRFS_CTREE_H_
3#define _BTRFS_CTREE_H_
4
5#include <linux/btrfs.h>
6#include <linux/types.h>
7
8
9
10
11
12
13
14
15
16#define BTRFS_ROOT_TREE_OBJECTID 1ULL
17
18
19#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
20
21
22
23
24
25#define BTRFS_CHUNK_TREE_OBJECTID 3ULL
26
27
28
29
30
31#define BTRFS_DEV_TREE_OBJECTID 4ULL
32
33
34#define BTRFS_FS_TREE_OBJECTID 5ULL
35
36
37#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
38
39
40#define BTRFS_CSUM_TREE_OBJECTID 7ULL
41
42
43#define BTRFS_QUOTA_TREE_OBJECTID 8ULL
44
45
46#define BTRFS_UUID_TREE_OBJECTID 9ULL
47
48
49#define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
50
51
52#define BTRFS_DEV_STATS_OBJECTID 0ULL
53
54
55#define BTRFS_BALANCE_OBJECTID -4ULL
56
57
58#define BTRFS_ORPHAN_OBJECTID -5ULL
59
60
61#define BTRFS_TREE_LOG_OBJECTID -6ULL
62#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
63
64
65#define BTRFS_TREE_RELOC_OBJECTID -8ULL
66#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
67
68
69
70
71
72
73#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
74
75
76#define BTRFS_FREE_SPACE_OBJECTID -11ULL
77
78
79
80
81
82#define BTRFS_FREE_INO_OBJECTID -12ULL
83
84
85#define BTRFS_MULTIPLE_OBJECTIDS -255ULL
86
87
88
89
90#define BTRFS_FIRST_FREE_OBJECTID 256ULL
91#define BTRFS_LAST_FREE_OBJECTID -256ULL
92#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
93
94
95
96
97
98
99#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
100
101#define BTRFS_BTREE_INODE_OBJECTID 1
102
103#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
104
105#define BTRFS_DEV_REPLACE_DEVID 0ULL
106
107
108
109
110
111
112#define BTRFS_INODE_ITEM_KEY 1
113#define BTRFS_INODE_REF_KEY 12
114#define BTRFS_INODE_EXTREF_KEY 13
115#define BTRFS_XATTR_ITEM_KEY 24
116#define BTRFS_ORPHAN_ITEM_KEY 48
117
118
119
120
121
122
123#define BTRFS_DIR_LOG_ITEM_KEY 60
124#define BTRFS_DIR_LOG_INDEX_KEY 72
125#define BTRFS_DIR_ITEM_KEY 84
126#define BTRFS_DIR_INDEX_KEY 96
127
128
129
130#define BTRFS_EXTENT_DATA_KEY 108
131
132
133
134
135
136#define BTRFS_EXTENT_CSUM_KEY 128
137
138
139
140
141
142#define BTRFS_ROOT_ITEM_KEY 132
143
144
145
146
147
148#define BTRFS_ROOT_BACKREF_KEY 144
149
150
151
152
153
154
155#define BTRFS_ROOT_REF_KEY 156
156
157
158
159
160
161#define BTRFS_EXTENT_ITEM_KEY 168
162
163
164
165
166
167#define BTRFS_METADATA_ITEM_KEY 169
168
169#define BTRFS_TREE_BLOCK_REF_KEY 176
170
171#define BTRFS_EXTENT_DATA_REF_KEY 178
172
173#define BTRFS_EXTENT_REF_V0_KEY 180
174
175#define BTRFS_SHARED_BLOCK_REF_KEY 182
176
177#define BTRFS_SHARED_DATA_REF_KEY 184
178
179
180
181
182
183#define BTRFS_BLOCK_GROUP_ITEM_KEY 192
184
185
186
187
188
189
190#define BTRFS_FREE_SPACE_INFO_KEY 198
191
192
193
194
195
196#define BTRFS_FREE_SPACE_EXTENT_KEY 199
197
198
199
200
201
202
203
204#define BTRFS_FREE_SPACE_BITMAP_KEY 200
205
206#define BTRFS_DEV_EXTENT_KEY 204
207#define BTRFS_DEV_ITEM_KEY 216
208#define BTRFS_CHUNK_ITEM_KEY 228
209
210
211
212
213
214
215#define BTRFS_QGROUP_STATUS_KEY 240
216
217
218
219
220#define BTRFS_QGROUP_INFO_KEY 242
221
222
223
224
225#define BTRFS_QGROUP_LIMIT_KEY 244
226
227
228
229
230
231
232#define BTRFS_QGROUP_RELATION_KEY 246
233
234
235
236
237#define BTRFS_BALANCE_ITEM_KEY 248
238
239
240
241
242
243
244
245
246
247
248
249
250#define BTRFS_TEMPORARY_ITEM_KEY 248
251
252
253
254
255#define BTRFS_DEV_STATS_KEY 249
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270#define BTRFS_PERSISTENT_ITEM_KEY 249
271
272
273
274
275
276#define BTRFS_DEV_REPLACE_KEY 250
277
278
279
280
281
282
283
284#if BTRFS_UUID_SIZE != 16
285#error "UUID items require BTRFS_UUID_SIZE == 16!"
286#endif
287#define BTRFS_UUID_KEY_SUBVOL 251
288#define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252
289
290
291
292
293
294
295#define BTRFS_STRING_ITEM_KEY 253
296
297
298
299
300#define BTRFS_CSUM_SIZE 32
301
302
303enum btrfs_csum_type {
304 BTRFS_CSUM_TYPE_CRC32 = 0,
305 BTRFS_CSUM_TYPE_XXHASH = 1,
306 BTRFS_CSUM_TYPE_SHA256 = 2,
307 BTRFS_CSUM_TYPE_BLAKE2 = 3,
308};
309
310
311
312
313
314
315
316
317
318#define BTRFS_FT_UNKNOWN 0
319#define BTRFS_FT_REG_FILE 1
320#define BTRFS_FT_DIR 2
321#define BTRFS_FT_CHRDEV 3
322#define BTRFS_FT_BLKDEV 4
323#define BTRFS_FT_FIFO 5
324#define BTRFS_FT_SOCK 6
325#define BTRFS_FT_SYMLINK 7
326#define BTRFS_FT_XATTR 8
327#define BTRFS_FT_MAX 9
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346struct btrfs_disk_key {
347 __le64 objectid;
348 __u8 type;
349 __le64 offset;
350} __attribute__ ((__packed__));
351
352struct btrfs_key {
353 __u64 objectid;
354 __u8 type;
355 __u64 offset;
356} __attribute__ ((__packed__));
357
358struct btrfs_dev_item {
359
360 __le64 devid;
361
362
363 __le64 total_bytes;
364
365
366 __le64 bytes_used;
367
368
369 __le32 io_align;
370
371
372 __le32 io_width;
373
374
375 __le32 sector_size;
376
377
378 __le64 type;
379
380
381 __le64 generation;
382
383
384
385
386
387 __le64 start_offset;
388
389
390 __le32 dev_group;
391
392
393 __u8 seek_speed;
394
395
396 __u8 bandwidth;
397
398
399 __u8 uuid[BTRFS_UUID_SIZE];
400
401
402 __u8 fsid[BTRFS_UUID_SIZE];
403} __attribute__ ((__packed__));
404
405struct btrfs_stripe {
406 __le64 devid;
407 __le64 offset;
408 __u8 dev_uuid[BTRFS_UUID_SIZE];
409} __attribute__ ((__packed__));
410
411struct btrfs_chunk {
412
413 __le64 length;
414
415
416 __le64 owner;
417
418 __le64 stripe_len;
419 __le64 type;
420
421
422 __le32 io_align;
423
424
425 __le32 io_width;
426
427
428 __le32 sector_size;
429
430
431
432
433 __le16 num_stripes;
434
435
436 __le16 sub_stripes;
437 struct btrfs_stripe stripe;
438
439} __attribute__ ((__packed__));
440
441#define BTRFS_FREE_SPACE_EXTENT 1
442#define BTRFS_FREE_SPACE_BITMAP 2
443
444struct btrfs_free_space_entry {
445 __le64 offset;
446 __le64 bytes;
447 __u8 type;
448} __attribute__ ((__packed__));
449
450struct btrfs_free_space_header {
451 struct btrfs_disk_key location;
452 __le64 generation;
453 __le64 num_entries;
454 __le64 num_bitmaps;
455} __attribute__ ((__packed__));
456
457#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
458#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
459
460
461
462#define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
463
464#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
465#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
466#define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
467#define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
468#define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
469
470
471
472
473
474
475
476struct btrfs_extent_item {
477 __le64 refs;
478 __le64 generation;
479 __le64 flags;
480} __attribute__ ((__packed__));
481
482struct btrfs_extent_item_v0 {
483 __le32 refs;
484} __attribute__ ((__packed__));
485
486
487#define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
488#define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
489
490
491
492
493#define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
494
495
496
497
498
499#define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
500
501struct btrfs_tree_block_info {
502 struct btrfs_disk_key key;
503 __u8 level;
504} __attribute__ ((__packed__));
505
506struct btrfs_extent_data_ref {
507 __le64 root;
508 __le64 objectid;
509 __le64 offset;
510 __le32 count;
511} __attribute__ ((__packed__));
512
513struct btrfs_shared_data_ref {
514 __le32 count;
515} __attribute__ ((__packed__));
516
517struct btrfs_extent_inline_ref {
518 __u8 type;
519 __le64 offset;
520} __attribute__ ((__packed__));
521
522
523
524
525
526struct btrfs_dev_extent {
527 __le64 chunk_tree;
528 __le64 chunk_objectid;
529 __le64 chunk_offset;
530 __le64 length;
531 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
532} __attribute__ ((__packed__));
533
534struct btrfs_inode_ref {
535 __le64 index;
536 __le16 name_len;
537
538} __attribute__ ((__packed__));
539
540struct btrfs_inode_extref {
541 __le64 parent_objectid;
542 __le64 index;
543 __le16 name_len;
544 __u8 name[0];
545
546} __attribute__ ((__packed__));
547
548struct btrfs_timespec {
549 __le64 sec;
550 __le32 nsec;
551} __attribute__ ((__packed__));
552
553struct btrfs_inode_item {
554
555 __le64 generation;
556
557 __le64 transid;
558 __le64 size;
559 __le64 nbytes;
560 __le64 block_group;
561 __le32 nlink;
562 __le32 uid;
563 __le32 gid;
564 __le32 mode;
565 __le64 rdev;
566 __le64 flags;
567
568
569 __le64 sequence;
570
571
572
573
574
575 __le64 reserved[4];
576 struct btrfs_timespec atime;
577 struct btrfs_timespec ctime;
578 struct btrfs_timespec mtime;
579 struct btrfs_timespec otime;
580} __attribute__ ((__packed__));
581
582struct btrfs_dir_log_item {
583 __le64 end;
584} __attribute__ ((__packed__));
585
586struct btrfs_dir_item {
587 struct btrfs_disk_key location;
588 __le64 transid;
589 __le16 data_len;
590 __le16 name_len;
591 __u8 type;
592} __attribute__ ((__packed__));
593
594#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
595
596
597
598
599
600#define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
601
602struct btrfs_root_item {
603 struct btrfs_inode_item inode;
604 __le64 generation;
605 __le64 root_dirid;
606 __le64 bytenr;
607 __le64 byte_limit;
608 __le64 bytes_used;
609 __le64 last_snapshot;
610 __le64 flags;
611 __le32 refs;
612 struct btrfs_disk_key drop_progress;
613 __u8 drop_level;
614 __u8 level;
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632 __le64 generation_v2;
633 __u8 uuid[BTRFS_UUID_SIZE];
634 __u8 parent_uuid[BTRFS_UUID_SIZE];
635 __u8 received_uuid[BTRFS_UUID_SIZE];
636 __le64 ctransid;
637 __le64 otransid;
638 __le64 stransid;
639 __le64 rtransid;
640 struct btrfs_timespec ctime;
641 struct btrfs_timespec otime;
642 struct btrfs_timespec stime;
643 struct btrfs_timespec rtime;
644 __le64 reserved[8];
645} __attribute__ ((__packed__));
646
647
648
649
650struct btrfs_root_ref {
651 __le64 dirid;
652 __le64 sequence;
653 __le16 name_len;
654} __attribute__ ((__packed__));
655
656struct btrfs_disk_balance_args {
657
658
659
660
661 __le64 profiles;
662
663
664
665
666
667
668 union {
669 __le64 usage;
670 struct {
671 __le32 usage_min;
672 __le32 usage_max;
673 };
674 };
675
676
677 __le64 devid;
678
679
680 __le64 pstart;
681 __le64 pend;
682
683
684 __le64 vstart;
685 __le64 vend;
686
687
688
689
690
691 __le64 target;
692
693
694 __le64 flags;
695
696
697
698
699
700
701 union {
702 __le64 limit;
703 struct {
704 __le32 limit_min;
705 __le32 limit_max;
706 };
707 };
708
709
710
711
712
713 __le32 stripes_min;
714 __le32 stripes_max;
715
716 __le64 unused[6];
717} __attribute__ ((__packed__));
718
719
720
721
722
723struct btrfs_balance_item {
724
725 __le64 flags;
726
727 struct btrfs_disk_balance_args data;
728 struct btrfs_disk_balance_args meta;
729 struct btrfs_disk_balance_args sys;
730
731 __le64 unused[4];
732} __attribute__ ((__packed__));
733
734enum {
735 BTRFS_FILE_EXTENT_INLINE = 0,
736 BTRFS_FILE_EXTENT_REG = 1,
737 BTRFS_FILE_EXTENT_PREALLOC = 2,
738 BTRFS_NR_FILE_EXTENT_TYPES = 3,
739};
740
741struct btrfs_file_extent_item {
742
743
744
745 __le64 generation;
746
747
748
749
750
751
752
753 __le64 ram_bytes;
754
755
756
757
758
759
760
761
762 __u8 compression;
763 __u8 encryption;
764 __le16 other_encoding;
765
766
767 __u8 type;
768
769
770
771
772
773
774
775 __le64 disk_bytenr;
776 __le64 disk_num_bytes;
777
778
779
780
781
782
783
784 __le64 offset;
785
786
787
788
789 __le64 num_bytes;
790
791} __attribute__ ((__packed__));
792
793struct btrfs_csum_item {
794 __u8 csum;
795} __attribute__ ((__packed__));
796
797struct btrfs_dev_stats_item {
798
799
800
801
802 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
803} __attribute__ ((__packed__));
804
805#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
806#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
807
808struct btrfs_dev_replace_item {
809
810
811
812
813 __le64 src_devid;
814 __le64 cursor_left;
815 __le64 cursor_right;
816 __le64 cont_reading_from_srcdev_mode;
817
818 __le64 replace_state;
819 __le64 time_started;
820 __le64 time_stopped;
821 __le64 num_write_errors;
822 __le64 num_uncorrectable_read_errors;
823} __attribute__ ((__packed__));
824
825
826#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
827#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
828#define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
829#define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
830#define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
831#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
832#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
833#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
834#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
835#define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
836#define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
837#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
838 BTRFS_SPACE_INFO_GLOBAL_RSV)
839
840enum btrfs_raid_types {
841 BTRFS_RAID_RAID10,
842 BTRFS_RAID_RAID1,
843 BTRFS_RAID_DUP,
844 BTRFS_RAID_RAID0,
845 BTRFS_RAID_SINGLE,
846 BTRFS_RAID_RAID5,
847 BTRFS_RAID_RAID6,
848 BTRFS_RAID_RAID1C3,
849 BTRFS_RAID_RAID1C4,
850 BTRFS_NR_RAID_TYPES
851};
852
853#define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
854 BTRFS_BLOCK_GROUP_SYSTEM | \
855 BTRFS_BLOCK_GROUP_METADATA)
856
857#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
858 BTRFS_BLOCK_GROUP_RAID1 | \
859 BTRFS_BLOCK_GROUP_RAID1C3 | \
860 BTRFS_BLOCK_GROUP_RAID1C4 | \
861 BTRFS_BLOCK_GROUP_RAID5 | \
862 BTRFS_BLOCK_GROUP_RAID6 | \
863 BTRFS_BLOCK_GROUP_DUP | \
864 BTRFS_BLOCK_GROUP_RAID10)
865#define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
866 BTRFS_BLOCK_GROUP_RAID6)
867
868#define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
869 BTRFS_BLOCK_GROUP_RAID1C3 | \
870 BTRFS_BLOCK_GROUP_RAID1C4)
871
872
873
874
875
876
877
878
879#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
880
881
882
883
884
885#define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
886
887#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
888 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
889
890static inline __u64 chunk_to_extended(__u64 flags)
891{
892 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
893 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
894
895 return flags;
896}
897static inline __u64 extended_to_chunk(__u64 flags)
898{
899 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
900}
901
902struct btrfs_block_group_item {
903 __le64 used;
904 __le64 chunk_objectid;
905 __le64 flags;
906} __attribute__ ((__packed__));
907
908struct btrfs_free_space_info {
909 __le32 extent_count;
910 __le32 flags;
911} __attribute__ ((__packed__));
912
913#define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
914
915#define BTRFS_QGROUP_LEVEL_SHIFT 48
916static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
917{
918 return (__u16)(qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT);
919}
920
921
922
923
924#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
925
926
927
928#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
929
930
931
932
933
934
935
936#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
937
938#define BTRFS_QGROUP_STATUS_VERSION 1
939
940struct btrfs_qgroup_status_item {
941 __le64 version;
942
943
944
945
946
947
948 __le64 generation;
949
950
951 __le64 flags;
952
953
954
955
956
957 __le64 rescan;
958} __attribute__ ((__packed__));
959
960struct btrfs_qgroup_info_item {
961 __le64 generation;
962 __le64 rfer;
963 __le64 rfer_cmpr;
964 __le64 excl;
965 __le64 excl_cmpr;
966} __attribute__ ((__packed__));
967
968struct btrfs_qgroup_limit_item {
969
970
971
972 __le64 flags;
973 __le64 max_rfer;
974 __le64 max_excl;
975 __le64 rsv_rfer;
976 __le64 rsv_excl;
977} __attribute__ ((__packed__));
978
979#endif
980