This source file includes following definitions.
- chunk_to_extended
- extended_to_chunk
- btrfs_qgroup_level
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
303 enum btrfs_csum_type {
304 BTRFS_CSUM_TYPE_CRC32 = 0,
305 };
306
307
308
309
310
311
312
313
314
315 #define BTRFS_FT_UNKNOWN 0
316 #define BTRFS_FT_REG_FILE 1
317 #define BTRFS_FT_DIR 2
318 #define BTRFS_FT_CHRDEV 3
319 #define BTRFS_FT_BLKDEV 4
320 #define BTRFS_FT_FIFO 5
321 #define BTRFS_FT_SOCK 6
322 #define BTRFS_FT_SYMLINK 7
323 #define BTRFS_FT_XATTR 8
324 #define BTRFS_FT_MAX 9
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343 struct btrfs_disk_key {
344 __le64 objectid;
345 __u8 type;
346 __le64 offset;
347 } __attribute__ ((__packed__));
348
349 struct btrfs_key {
350 __u64 objectid;
351 __u8 type;
352 __u64 offset;
353 } __attribute__ ((__packed__));
354
355 struct btrfs_dev_item {
356
357 __le64 devid;
358
359
360 __le64 total_bytes;
361
362
363 __le64 bytes_used;
364
365
366 __le32 io_align;
367
368
369 __le32 io_width;
370
371
372 __le32 sector_size;
373
374
375 __le64 type;
376
377
378 __le64 generation;
379
380
381
382
383
384 __le64 start_offset;
385
386
387 __le32 dev_group;
388
389
390 __u8 seek_speed;
391
392
393 __u8 bandwidth;
394
395
396 __u8 uuid[BTRFS_UUID_SIZE];
397
398
399 __u8 fsid[BTRFS_UUID_SIZE];
400 } __attribute__ ((__packed__));
401
402 struct btrfs_stripe {
403 __le64 devid;
404 __le64 offset;
405 __u8 dev_uuid[BTRFS_UUID_SIZE];
406 } __attribute__ ((__packed__));
407
408 struct btrfs_chunk {
409
410 __le64 length;
411
412
413 __le64 owner;
414
415 __le64 stripe_len;
416 __le64 type;
417
418
419 __le32 io_align;
420
421
422 __le32 io_width;
423
424
425 __le32 sector_size;
426
427
428
429
430 __le16 num_stripes;
431
432
433 __le16 sub_stripes;
434 struct btrfs_stripe stripe;
435
436 } __attribute__ ((__packed__));
437
438 #define BTRFS_FREE_SPACE_EXTENT 1
439 #define BTRFS_FREE_SPACE_BITMAP 2
440
441 struct btrfs_free_space_entry {
442 __le64 offset;
443 __le64 bytes;
444 __u8 type;
445 } __attribute__ ((__packed__));
446
447 struct btrfs_free_space_header {
448 struct btrfs_disk_key location;
449 __le64 generation;
450 __le64 num_entries;
451 __le64 num_bitmaps;
452 } __attribute__ ((__packed__));
453
454 #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
455 #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
456
457
458
459 #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
460
461 #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
462 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
463 #define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
464 #define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
465 #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
466
467
468
469
470
471
472
473 struct btrfs_extent_item {
474 __le64 refs;
475 __le64 generation;
476 __le64 flags;
477 } __attribute__ ((__packed__));
478
479 struct btrfs_extent_item_v0 {
480 __le32 refs;
481 } __attribute__ ((__packed__));
482
483
484 #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
485 #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
486
487
488
489
490 #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
491
492
493
494
495
496 #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
497
498 struct btrfs_tree_block_info {
499 struct btrfs_disk_key key;
500 __u8 level;
501 } __attribute__ ((__packed__));
502
503 struct btrfs_extent_data_ref {
504 __le64 root;
505 __le64 objectid;
506 __le64 offset;
507 __le32 count;
508 } __attribute__ ((__packed__));
509
510 struct btrfs_shared_data_ref {
511 __le32 count;
512 } __attribute__ ((__packed__));
513
514 struct btrfs_extent_inline_ref {
515 __u8 type;
516 __le64 offset;
517 } __attribute__ ((__packed__));
518
519
520 struct btrfs_extent_ref_v0 {
521 __le64 root;
522 __le64 generation;
523 __le64 objectid;
524 __le32 count;
525 } __attribute__ ((__packed__));
526
527
528
529
530
531
532 struct btrfs_dev_extent {
533 __le64 chunk_tree;
534 __le64 chunk_objectid;
535 __le64 chunk_offset;
536 __le64 length;
537 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
538 } __attribute__ ((__packed__));
539
540 struct btrfs_inode_ref {
541 __le64 index;
542 __le16 name_len;
543
544 } __attribute__ ((__packed__));
545
546 struct btrfs_inode_extref {
547 __le64 parent_objectid;
548 __le64 index;
549 __le16 name_len;
550 __u8 name[0];
551
552 } __attribute__ ((__packed__));
553
554 struct btrfs_timespec {
555 __le64 sec;
556 __le32 nsec;
557 } __attribute__ ((__packed__));
558
559 struct btrfs_inode_item {
560
561 __le64 generation;
562
563 __le64 transid;
564 __le64 size;
565 __le64 nbytes;
566 __le64 block_group;
567 __le32 nlink;
568 __le32 uid;
569 __le32 gid;
570 __le32 mode;
571 __le64 rdev;
572 __le64 flags;
573
574
575 __le64 sequence;
576
577
578
579
580
581 __le64 reserved[4];
582 struct btrfs_timespec atime;
583 struct btrfs_timespec ctime;
584 struct btrfs_timespec mtime;
585 struct btrfs_timespec otime;
586 } __attribute__ ((__packed__));
587
588 struct btrfs_dir_log_item {
589 __le64 end;
590 } __attribute__ ((__packed__));
591
592 struct btrfs_dir_item {
593 struct btrfs_disk_key location;
594 __le64 transid;
595 __le16 data_len;
596 __le16 name_len;
597 __u8 type;
598 } __attribute__ ((__packed__));
599
600 #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
601
602
603
604
605
606 #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
607
608 struct btrfs_root_item {
609 struct btrfs_inode_item inode;
610 __le64 generation;
611 __le64 root_dirid;
612 __le64 bytenr;
613 __le64 byte_limit;
614 __le64 bytes_used;
615 __le64 last_snapshot;
616 __le64 flags;
617 __le32 refs;
618 struct btrfs_disk_key drop_progress;
619 __u8 drop_level;
620 __u8 level;
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638 __le64 generation_v2;
639 __u8 uuid[BTRFS_UUID_SIZE];
640 __u8 parent_uuid[BTRFS_UUID_SIZE];
641 __u8 received_uuid[BTRFS_UUID_SIZE];
642 __le64 ctransid;
643 __le64 otransid;
644 __le64 stransid;
645 __le64 rtransid;
646 struct btrfs_timespec ctime;
647 struct btrfs_timespec otime;
648 struct btrfs_timespec stime;
649 struct btrfs_timespec rtime;
650 __le64 reserved[8];
651 } __attribute__ ((__packed__));
652
653
654
655
656 struct btrfs_root_ref {
657 __le64 dirid;
658 __le64 sequence;
659 __le16 name_len;
660 } __attribute__ ((__packed__));
661
662 struct btrfs_disk_balance_args {
663
664
665
666
667 __le64 profiles;
668
669
670
671
672
673
674 union {
675 __le64 usage;
676 struct {
677 __le32 usage_min;
678 __le32 usage_max;
679 };
680 };
681
682
683 __le64 devid;
684
685
686 __le64 pstart;
687 __le64 pend;
688
689
690 __le64 vstart;
691 __le64 vend;
692
693
694
695
696
697 __le64 target;
698
699
700 __le64 flags;
701
702
703
704
705
706
707 union {
708 __le64 limit;
709 struct {
710 __le32 limit_min;
711 __le32 limit_max;
712 };
713 };
714
715
716
717
718
719 __le32 stripes_min;
720 __le32 stripes_max;
721
722 __le64 unused[6];
723 } __attribute__ ((__packed__));
724
725
726
727
728
729 struct btrfs_balance_item {
730
731 __le64 flags;
732
733 struct btrfs_disk_balance_args data;
734 struct btrfs_disk_balance_args meta;
735 struct btrfs_disk_balance_args sys;
736
737 __le64 unused[4];
738 } __attribute__ ((__packed__));
739
740 #define BTRFS_FILE_EXTENT_INLINE 0
741 #define BTRFS_FILE_EXTENT_REG 1
742 #define BTRFS_FILE_EXTENT_PREALLOC 2
743 #define BTRFS_FILE_EXTENT_TYPES 2
744
745 struct btrfs_file_extent_item {
746
747
748
749 __le64 generation;
750
751
752
753
754
755
756
757 __le64 ram_bytes;
758
759
760
761
762
763
764
765
766 __u8 compression;
767 __u8 encryption;
768 __le16 other_encoding;
769
770
771 __u8 type;
772
773
774
775
776
777
778
779 __le64 disk_bytenr;
780 __le64 disk_num_bytes;
781
782
783
784
785
786
787
788 __le64 offset;
789
790
791
792
793 __le64 num_bytes;
794
795 } __attribute__ ((__packed__));
796
797 struct btrfs_csum_item {
798 __u8 csum;
799 } __attribute__ ((__packed__));
800
801 struct btrfs_dev_stats_item {
802
803
804
805
806 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
807 } __attribute__ ((__packed__));
808
809 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
810 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
811
812 struct btrfs_dev_replace_item {
813
814
815
816
817 __le64 src_devid;
818 __le64 cursor_left;
819 __le64 cursor_right;
820 __le64 cont_reading_from_srcdev_mode;
821
822 __le64 replace_state;
823 __le64 time_started;
824 __le64 time_stopped;
825 __le64 num_write_errors;
826 __le64 num_uncorrectable_read_errors;
827 } __attribute__ ((__packed__));
828
829
830 #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
831 #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
832 #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
833 #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
834 #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
835 #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
836 #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
837 #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
838 #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
839 #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
840 BTRFS_SPACE_INFO_GLOBAL_RSV)
841
842 enum btrfs_raid_types {
843 BTRFS_RAID_RAID10,
844 BTRFS_RAID_RAID1,
845 BTRFS_RAID_DUP,
846 BTRFS_RAID_RAID0,
847 BTRFS_RAID_SINGLE,
848 BTRFS_RAID_RAID5,
849 BTRFS_RAID_RAID6,
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_RAID5 | \
860 BTRFS_BLOCK_GROUP_RAID6 | \
861 BTRFS_BLOCK_GROUP_DUP | \
862 BTRFS_BLOCK_GROUP_RAID10)
863 #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
864 BTRFS_BLOCK_GROUP_RAID6)
865
866 #define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1)
867
868
869
870
871
872
873
874
875 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
876
877
878
879
880
881 #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
882
883 #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
884 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
885
886 static inline __u64 chunk_to_extended(__u64 flags)
887 {
888 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
889 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
890
891 return flags;
892 }
893 static inline __u64 extended_to_chunk(__u64 flags)
894 {
895 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
896 }
897
898 struct btrfs_block_group_item {
899 __le64 used;
900 __le64 chunk_objectid;
901 __le64 flags;
902 } __attribute__ ((__packed__));
903
904 struct btrfs_free_space_info {
905 __le32 extent_count;
906 __le32 flags;
907 } __attribute__ ((__packed__));
908
909 #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
910
911 #define BTRFS_QGROUP_LEVEL_SHIFT 48
912 static inline __u64 btrfs_qgroup_level(__u64 qgroupid)
913 {
914 return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
915 }
916
917
918
919
920 #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
921
922
923
924 #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
925
926
927
928
929
930
931
932 #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
933
934 #define BTRFS_QGROUP_STATUS_VERSION 1
935
936 struct btrfs_qgroup_status_item {
937 __le64 version;
938
939
940
941
942
943
944 __le64 generation;
945
946
947 __le64 flags;
948
949
950
951
952
953 __le64 rescan;
954 } __attribute__ ((__packed__));
955
956 struct btrfs_qgroup_info_item {
957 __le64 generation;
958 __le64 rfer;
959 __le64 rfer_cmpr;
960 __le64 excl;
961 __le64 excl_cmpr;
962 } __attribute__ ((__packed__));
963
964 struct btrfs_qgroup_limit_item {
965
966
967
968 __le64 flags;
969 __le64 max_rfer;
970 __le64 max_excl;
971 __le64 rsv_rfer;
972 __le64 rsv_excl;
973 } __attribute__ ((__packed__));
974
975 #endif