1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * Copied from kernel/include/uapi/linux/btrfs_btree.h.
5 * Only modified the header.
7 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
8 #ifndef __BTRFS_TREE_H__
9 #define __BTRFS_TREE_H__
11 #include <linux/types.h>
13 #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
16 * The max metadata block size (node size).
18 * This limit is somewhat artificial. The memmove and tree block locking cost
19 * go up with larger node size.
21 #define BTRFS_MAX_METADATA_BLOCKSIZE 65536
24 * We can actually store much bigger names, but lets not confuse the rest
27 * btrfs_dir_item::name_len follows this limitation.
29 #define BTRFS_NAME_LEN 255
32 * Objectids start from here.
34 * Check btrfs_disk_key for the meaning of objectids.
38 * Root tree holds pointers to all of the tree roots.
39 * Without special mention, the root tree contains the root bytenr of all other
40 * trees, except the chunk tree and the log tree.
42 * The super block contains the root bytenr of this tree.
44 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
47 * Extent tree stores information about which extents are in use, and backrefs
50 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
53 * Chunk tree stores btrfs logical address -> physical address mapping.
55 * The super block contains part of chunk tree for bootstrap, and contains
56 * the root bytenr of this tree.
58 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
61 * Device tree stores info about which areas of a given device are in use,
62 * and physical address -> btrfs logical address mapping.
64 #define BTRFS_DEV_TREE_OBJECTID 4ULL
66 /* The fs tree is the first subvolume tree, storing files and directories. */
67 #define BTRFS_FS_TREE_OBJECTID 5ULL
69 /* Shows the directory objectid inside the root tree. */
70 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
72 /* Csum tree holds checksums of all the data extents. */
73 #define BTRFS_CSUM_TREE_OBJECTID 7ULL
75 /* Quota tree holds quota configuration and tracking. */
76 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
78 /* UUID tree stores items that use the BTRFS_UUID_KEY* types. */
79 #define BTRFS_UUID_TREE_OBJECTID 9ULL
81 /* Free space cache tree (v2 space cache) tracks free space in block groups. */
82 #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
84 /* Indicates device stats in the device tree. */
85 #define BTRFS_DEV_STATS_OBJECTID 0ULL
87 /* For storing balance parameters in the root tree. */
88 #define BTRFS_BALANCE_OBJECTID -4ULL
90 /* Orhpan objectid for tracking unlinked/truncated files. */
91 #define BTRFS_ORPHAN_OBJECTID -5ULL
93 /* Does write ahead logging to speed up fsyncs. */
94 #define BTRFS_TREE_LOG_OBJECTID -6ULL
95 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
97 /* For space balancing. */
98 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
99 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
101 /* Extent checksums, shared between the csum tree and log trees. */
102 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
104 /* For storing free space cache (v1 space cache). */
105 #define BTRFS_FREE_SPACE_OBJECTID -11ULL
107 /* The inode number assigned to the special inode for storing free ino cache. */
108 #define BTRFS_FREE_INO_OBJECTID -12ULL
110 /* Dummy objectid represents multiple objectids. */
111 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
113 /* All files have objectids in this range. */
114 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
115 #define BTRFS_LAST_FREE_OBJECTID -256ULL
116 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
120 * The device items go into the chunk tree.
122 * The key is in the form
123 * (BTRFS_DEV_ITEMS_OBJECTID, BTRFS_DEV_ITEM_KEY, <device_id>)
125 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
127 #define BTRFS_BTREE_INODE_OBJECTID 1
129 #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
131 #define BTRFS_DEV_REPLACE_DEVID 0ULL
134 * Types start from here.
136 * Check btrfs_disk_key for details about types.
140 * Inode items have the data typically returned from stat and store other
141 * info about object characteristics.
143 * There is one for every file and dir in the FS.
145 #define BTRFS_INODE_ITEM_KEY 1
146 /* reserve 2-11 close to the inode for later flexibility */
147 #define BTRFS_INODE_REF_KEY 12
148 #define BTRFS_INODE_EXTREF_KEY 13
149 #define BTRFS_XATTR_ITEM_KEY 24
150 #define BTRFS_ORPHAN_ITEM_KEY 48
153 * Dir items are the name -> inode pointers in a directory.
155 * There is one for every name in a directory.
157 #define BTRFS_DIR_LOG_ITEM_KEY 60
158 #define BTRFS_DIR_LOG_INDEX_KEY 72
159 #define BTRFS_DIR_ITEM_KEY 84
160 #define BTRFS_DIR_INDEX_KEY 96
162 /* Stores info (position, size ...) about a data extent of a file */
163 #define BTRFS_EXTENT_DATA_KEY 108
166 * Extent csums are stored in a separate tree and hold csums for
167 * an entire extent on disk.
169 #define BTRFS_EXTENT_CSUM_KEY 128
172 * Root items point to tree roots.
174 * They are typically in the root tree used by the super block to find all the
177 #define BTRFS_ROOT_ITEM_KEY 132
180 * Root backrefs tie subvols and snapshots to the directory entries that
183 #define BTRFS_ROOT_BACKREF_KEY 144
186 * Root refs make a fast index for listing all of the snapshots and
187 * subvolumes referenced by a given root. They point directly to the
188 * directory item in the root that references the subvol.
190 #define BTRFS_ROOT_REF_KEY 156
193 * Extent items are in the extent tree.
195 * These record which blocks are used, and how many references there are.
197 #define BTRFS_EXTENT_ITEM_KEY 168
200 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
201 * the length, so we save the level in key->offset instead of the length.
203 #define BTRFS_METADATA_ITEM_KEY 169
205 #define BTRFS_TREE_BLOCK_REF_KEY 176
207 #define BTRFS_EXTENT_DATA_REF_KEY 178
209 #define BTRFS_EXTENT_REF_V0_KEY 180
211 #define BTRFS_SHARED_BLOCK_REF_KEY 182
213 #define BTRFS_SHARED_DATA_REF_KEY 184
216 * Block groups give us hints into the extent allocation trees.
218 * Stores how many free space there is in a block group.
220 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
223 * Every block group is represented in the free space tree by a free space info
224 * item, which stores some accounting information. It is keyed on
225 * (block_group_start, FREE_SPACE_INFO, block_group_length).
227 #define BTRFS_FREE_SPACE_INFO_KEY 198
230 * A free space extent tracks an extent of space that is free in a block group.
231 * It is keyed on (start, FREE_SPACE_EXTENT, length).
233 #define BTRFS_FREE_SPACE_EXTENT_KEY 199
236 * When a block group becomes very fragmented, we convert it to use bitmaps
237 * instead of extents.
239 * A free space bitmap is keyed on (start, FREE_SPACE_BITMAP, length).
240 * The corresponding item is a bitmap with (length / sectorsize) bits.
242 #define BTRFS_FREE_SPACE_BITMAP_KEY 200
244 #define BTRFS_DEV_EXTENT_KEY 204
245 #define BTRFS_DEV_ITEM_KEY 216
246 #define BTRFS_CHUNK_ITEM_KEY 228
249 * Records the overall state of the qgroups.
251 * There's only one instance of this key present,
252 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
254 #define BTRFS_QGROUP_STATUS_KEY 240
256 * Records the currently used space of the qgroup.
258 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
260 #define BTRFS_QGROUP_INFO_KEY 242
263 * Contains the user configured limits for the qgroup.
265 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
267 #define BTRFS_QGROUP_LIMIT_KEY 244
270 * Records the child-parent relationship of qgroups. For
271 * each relation, 2 keys are present:
272 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
273 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
275 #define BTRFS_QGROUP_RELATION_KEY 246
277 /* Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. */
278 #define BTRFS_BALANCE_ITEM_KEY 248
281 * The key type for tree items that are stored persistently, but do not need to
282 * exist for extended period of time. The items can exist in any tree.
284 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
288 * - balance status item
289 * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
291 #define BTRFS_TEMPORARY_ITEM_KEY 248
293 /* Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY */
294 #define BTRFS_DEV_STATS_KEY 249
297 * The key type for tree items that are stored persistently and usually exist
298 * for a long period, eg. filesystem lifetime. The item kinds can be status
299 * information, stats or preference values. The item can exist in any tree.
301 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
305 * - device statistics, store IO stats in the device tree, one key for all
307 * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
309 #define BTRFS_PERSISTENT_ITEM_KEY 249
312 * Persistently stores the device replace state in the device tree.
314 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
316 #define BTRFS_DEV_REPLACE_KEY 250
319 * Stores items that allow to quickly map UUIDs to something else.
321 * These items are part of the filesystem UUID tree.
322 * The key is built like this:
323 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
325 #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
326 #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
327 * received subvols */
330 * String items are for debugging.
332 * They just store a short string of data in the FS.
334 #define BTRFS_STRING_ITEM_KEY 253
337 /* 32 bytes in various csum fields */
338 #define BTRFS_CSUM_SIZE 32
341 enum btrfs_csum_type
{
342 BTRFS_CSUM_TYPE_CRC32
= 0,
343 BTRFS_CSUM_TYPE_XXHASH
= 1,
344 BTRFS_CSUM_TYPE_SHA256
= 2,
345 BTRFS_CSUM_TYPE_BLAKE2
= 3,
349 * Flags definitions for directory entry item type.
352 * struct btrfs_dir_item.type
354 * Values 0..7 must match common file type values in fs_types.h.
356 #define BTRFS_FT_UNKNOWN 0
357 #define BTRFS_FT_REG_FILE 1
358 #define BTRFS_FT_DIR 2
359 #define BTRFS_FT_CHRDEV 3
360 #define BTRFS_FT_BLKDEV 4
361 #define BTRFS_FT_FIFO 5
362 #define BTRFS_FT_SOCK 6
363 #define BTRFS_FT_SYMLINK 7
364 #define BTRFS_FT_XATTR 8
365 #define BTRFS_FT_MAX 9
367 #define BTRFS_FSID_SIZE 16
368 #define BTRFS_UUID_SIZE 16
371 * The key defines the order in the tree, and so it also defines (optimal)
374 * Objectid and offset are interpreted based on type.
375 * While normally for objectid, it either represents a root number, or an
378 * Type tells us things about the object, and is a kind of stream selector.
379 * Check the following URL for full references about btrfs_disk_key/btrfs_key:
380 * https://btrfs.wiki.kernel.org/index.php/Btree_Items
382 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
383 * in cpu native order. Otherwise they are identical and their sizes
384 * should be the same (ie both packed)
386 struct btrfs_disk_key
{
390 } __attribute__ ((__packed__
));
396 } __attribute__ ((__packed__
));
398 struct btrfs_dev_item
{
399 /* The internal btrfs device id */
402 /* Size of the device */
408 /* Optimal io alignment for this device */
411 /* Optimal io width for this device */
414 /* Minimal io size for this device */
417 /* Type and info about this device */
420 /* Expected generation for this device */
424 * Starting byte of this partition on the device,
425 * to allow for stripe alignment in the future.
429 /* Grouping information for allocation decisions */
432 /* Optimal seek speed 0-100 where 100 is fastest */
435 /* Optimal bandwidth 0-100 where 100 is fastest */
438 /* Btrfs generated uuid for this device */
439 __u8 uuid
[BTRFS_UUID_SIZE
];
441 /* UUID of FS who owns this device */
442 __u8 fsid
[BTRFS_UUID_SIZE
];
443 } __attribute__ ((__packed__
));
445 struct btrfs_stripe
{
448 __u8 dev_uuid
[BTRFS_UUID_SIZE
];
449 } __attribute__ ((__packed__
));
452 /* Size of this chunk in bytes */
455 /* Objectid of the root referencing this chunk */
461 /* Optimal io alignment for this chunk */
464 /* Optimal io width for this chunk */
467 /* Minimal io size for this chunk */
471 * 2^16 stripes is quite a lot, a second limit is the size of a single
476 /* Sub stripes only matter for raid10 */
478 struct btrfs_stripe stripe
;
479 /* additional stripes go here */
480 } __attribute__ ((__packed__
));
482 #define BTRFS_FREE_SPACE_EXTENT 1
483 #define BTRFS_FREE_SPACE_BITMAP 2
485 struct btrfs_free_space_entry
{
489 } __attribute__ ((__packed__
));
491 struct btrfs_free_space_header
{
492 struct btrfs_disk_key location
;
496 } __attribute__ ((__packed__
));
498 #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
499 #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
501 /* Super block flags */
502 /* Errors detected */
503 #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
505 #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
506 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
507 #define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
508 #define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
509 #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
513 * Items in the extent tree are used to record the objectid of the
514 * owner of the block and the number of references.
516 struct btrfs_extent_item
{
520 } __attribute__ ((__packed__
));
522 struct btrfs_extent_item_v0
{
524 } __attribute__ ((__packed__
));
527 #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
528 #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
530 /* Use full backrefs for extent pointers in the block */
531 #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
534 * This flag is only used internally by scrub and may be changed at any time
535 * it is only declared here to avoid collisions.
537 #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
539 struct btrfs_tree_block_info
{
540 struct btrfs_disk_key key
;
542 } __attribute__ ((__packed__
));
544 struct btrfs_extent_data_ref
{
549 } __attribute__ ((__packed__
));
551 struct btrfs_shared_data_ref
{
553 } __attribute__ ((__packed__
));
555 struct btrfs_extent_inline_ref
{
558 } __attribute__ ((__packed__
));
560 /* Old style backrefs item */
561 struct btrfs_extent_ref_v0
{
566 } __attribute__ ((__packed__
));
569 /* Dev extents record used space on individual devices.
571 * The owner field points back to the chunk allocation mapping tree that
572 * allocated the extent.
573 * The chunk tree uuid field is a way to double check the owner.
575 struct btrfs_dev_extent
{
577 __le64 chunk_objectid
;
580 __u8 chunk_tree_uuid
[BTRFS_UUID_SIZE
];
581 } __attribute__ ((__packed__
));
583 struct btrfs_inode_ref
{
587 } __attribute__ ((__packed__
));
589 struct btrfs_inode_extref
{
590 __le64 parent_objectid
;
595 } __attribute__ ((__packed__
));
597 struct btrfs_timespec
{
600 } __attribute__ ((__packed__
));
603 #define BTRFS_INODE_NODATASUM (1 << 0)
604 #define BTRFS_INODE_NODATACOW (1 << 1)
605 #define BTRFS_INODE_READONLY (1 << 2)
606 #define BTRFS_INODE_NOCOMPRESS (1 << 3)
607 #define BTRFS_INODE_PREALLOC (1 << 4)
608 #define BTRFS_INODE_SYNC (1 << 5)
609 #define BTRFS_INODE_IMMUTABLE (1 << 6)
610 #define BTRFS_INODE_APPEND (1 << 7)
611 #define BTRFS_INODE_NODUMP (1 << 8)
612 #define BTRFS_INODE_NOATIME (1 << 9)
613 #define BTRFS_INODE_DIRSYNC (1 << 10)
614 #define BTRFS_INODE_COMPRESS (1 << 11)
616 #define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31)
618 #define BTRFS_INODE_FLAG_MASK \
619 (BTRFS_INODE_NODATASUM | \
620 BTRFS_INODE_NODATACOW | \
621 BTRFS_INODE_READONLY | \
622 BTRFS_INODE_NOCOMPRESS | \
623 BTRFS_INODE_PREALLOC | \
625 BTRFS_INODE_IMMUTABLE | \
626 BTRFS_INODE_APPEND | \
627 BTRFS_INODE_NODUMP | \
628 BTRFS_INODE_NOATIME | \
629 BTRFS_INODE_DIRSYNC | \
630 BTRFS_INODE_COMPRESS | \
631 BTRFS_INODE_ROOT_ITEM_INIT)
633 struct btrfs_inode_item
{
634 /* Nfs style generation number */
636 /* Transid that last touched this inode */
648 /* Modification sequence number for NFS */
652 * A little future expansion, for more than this we can just grow the
653 * inode item and version it
656 struct btrfs_timespec atime
;
657 struct btrfs_timespec ctime
;
658 struct btrfs_timespec mtime
;
659 struct btrfs_timespec otime
;
660 } __attribute__ ((__packed__
));
662 struct btrfs_dir_log_item
{
664 } __attribute__ ((__packed__
));
666 struct btrfs_dir_item
{
667 struct btrfs_disk_key location
;
672 } __attribute__ ((__packed__
));
674 #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
677 * Internal in-memory flag that a subvolume has been marked for deletion but
678 * still visible as a directory
680 #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
682 struct btrfs_root_item
{
683 struct btrfs_inode_item inode
;
689 __le64 last_snapshot
;
692 struct btrfs_disk_key drop_progress
;
697 * The following fields appear after subvol_uuids+subvol_times
702 * This generation number is used to test if the new fields are valid
703 * and up to date while reading the root item. Every time the root item
704 * is written out, the "generation" field is copied into this field. If
705 * anyone ever mounted the fs with an older kernel, we will have
706 * mismatching generation values here and thus must invalidate the
707 * new fields. See btrfs_update_root and btrfs_find_last_root for
709 * The offset of generation_v2 is also used as the start for the memset
710 * when invalidating the fields.
712 __le64 generation_v2
;
713 __u8 uuid
[BTRFS_UUID_SIZE
];
714 __u8 parent_uuid
[BTRFS_UUID_SIZE
];
715 __u8 received_uuid
[BTRFS_UUID_SIZE
];
716 __le64 ctransid
; /* Updated when an inode changes */
717 __le64 otransid
; /* Trans when created */
718 __le64 stransid
; /* Trans when sent. Non-zero for received subvol. */
719 __le64 rtransid
; /* Trans when received. Non-zero for received subvol.*/
720 struct btrfs_timespec ctime
;
721 struct btrfs_timespec otime
;
722 struct btrfs_timespec stime
;
723 struct btrfs_timespec rtime
;
724 __le64 reserved
[8]; /* For future */
725 } __attribute__ ((__packed__
));
727 /* This is used for both forward and backward root refs */
728 struct btrfs_root_ref
{
732 } __attribute__ ((__packed__
));
734 struct btrfs_disk_balance_args
{
736 * Profiles to operate on.
738 * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
744 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
745 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
758 /* Devid subset filter [pstart..pend) */
762 /* Btrfs virtual address space subset filter [vstart..vend) */
767 * Profile to convert to.
769 * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
773 /* BTRFS_BALANCE_ARGS_* */
777 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'.
778 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
790 * Process chunks that cross stripes_min..stripes_max devices,
791 * BTRFS_BALANCE_ARGS_STRIPES_RANGE.
797 } __attribute__ ((__packed__
));
800 * Stores balance parameters to disk so that balance can be properly
801 * resumed after crash or unmount.
803 struct btrfs_balance_item
{
804 /* BTRFS_BALANCE_* */
807 struct btrfs_disk_balance_args data
;
808 struct btrfs_disk_balance_args meta
;
809 struct btrfs_disk_balance_args sys
;
812 } __attribute__ ((__packed__
));
815 BTRFS_FILE_EXTENT_INLINE
= 0,
816 BTRFS_FILE_EXTENT_REG
= 1,
817 BTRFS_FILE_EXTENT_PREALLOC
= 2,
818 BTRFS_NR_FILE_EXTENT_TYPES
= 3,
821 enum btrfs_compression_type
{
822 BTRFS_COMPRESS_NONE
= 0,
823 BTRFS_COMPRESS_ZLIB
= 1,
824 BTRFS_COMPRESS_LZO
= 2,
825 BTRFS_COMPRESS_ZSTD
= 3,
826 BTRFS_NR_COMPRESS_TYPES
= 4,
829 struct btrfs_file_extent_item
{
830 /* Transaction id that created this extent */
833 * Max number of bytes to hold this extent in ram.
835 * When we split a compressed extent we can't know how big each of the
836 * resulting pieces will be. So, this is an upper limit on the size of
837 * the extent in ram instead of an exact limit.
842 * 32 bits for the various ways we might encode the data,
843 * including compression and encryption. If any of these
844 * are set to something a given disk format doesn't understand
845 * it is treated like an incompat flag for reading and writing,
850 __le16 other_encoding
; /* Spare for later use */
852 /* Are we inline data or a real extent? */
856 * Disk space consumed by the extent, checksum blocks are not included
859 * At this offset in the structure, the inline extent data start.
862 __le64 disk_num_bytes
;
865 * The logical offset inside the file extent.
867 * This allows a file extent to point into the middle of an existing
868 * extent on disk, sharing it between two snapshots (useful if some
869 * bytes in the middle of the extent have changed).
874 * The logical number of bytes this file extent is referencing (no
877 * This always reflects the size uncompressed and without encoding.
881 } __attribute__ ((__packed__
));
883 struct btrfs_csum_item
{
885 } __attribute__ ((__packed__
));
887 enum btrfs_dev_stat_values
{
888 /* Disk I/O failure stats */
889 BTRFS_DEV_STAT_WRITE_ERRS
, /* EIO or EREMOTEIO from lower layers */
890 BTRFS_DEV_STAT_READ_ERRS
, /* EIO or EREMOTEIO from lower layers */
891 BTRFS_DEV_STAT_FLUSH_ERRS
, /* EIO or EREMOTEIO from lower layers */
893 /* Stats for indirect indications for I/O failures */
894 BTRFS_DEV_STAT_CORRUPTION_ERRS
, /* Checksum error, bytenr error or
895 * contents is illegal: this is an
896 * indication that the block was damaged
897 * during read or write, or written to
898 * wrong location or read from wrong
900 BTRFS_DEV_STAT_GENERATION_ERRS
, /* An indication that blocks have not
903 BTRFS_DEV_STAT_VALUES_MAX
906 struct btrfs_dev_stats_item
{
908 * Grow this item struct at the end for future enhancements and keep
909 * the existing values unchanged.
911 __le64 values
[BTRFS_DEV_STAT_VALUES_MAX
];
912 } __attribute__ ((__packed__
));
914 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
915 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
917 struct btrfs_dev_replace_item
{
919 * Grow this item struct at the end for future enhancements and keep
920 * the existing values unchanged.
925 __le64 cont_reading_from_srcdev_mode
;
927 __le64 replace_state
;
930 __le64 num_write_errors
;
931 __le64 num_uncorrectable_read_errors
;
932 } __attribute__ ((__packed__
));
934 /* Different types of block groups (and chunks) */
935 #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
936 #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
937 #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
938 #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
939 #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
940 #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
941 #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
942 #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
943 #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
944 #define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
945 #define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
946 #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
947 BTRFS_SPACE_INFO_GLOBAL_RSV)
949 enum btrfs_raid_types
{
962 #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
963 BTRFS_BLOCK_GROUP_SYSTEM | \
964 BTRFS_BLOCK_GROUP_METADATA)
966 #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
967 BTRFS_BLOCK_GROUP_RAID1 | \
968 BTRFS_BLOCK_GROUP_RAID1C3 | \
969 BTRFS_BLOCK_GROUP_RAID1C4 | \
970 BTRFS_BLOCK_GROUP_RAID5 | \
971 BTRFS_BLOCK_GROUP_RAID6 | \
972 BTRFS_BLOCK_GROUP_DUP | \
973 BTRFS_BLOCK_GROUP_RAID10)
974 #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
975 BTRFS_BLOCK_GROUP_RAID6)
977 #define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
978 BTRFS_BLOCK_GROUP_RAID1C3 | \
979 BTRFS_BLOCK_GROUP_RAID1C4)
982 * We need a bit for restriper to be able to tell when chunks of type
983 * SINGLE are available. This "extended" profile format is used in
984 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
985 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
986 * to avoid remappings between two formats in future.
988 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
991 * A fake block group type that is used to communicate global block reserve
992 * size to userspace via the SPACE_INFO ioctl.
994 #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
996 #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
997 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
999 static inline __u64
chunk_to_extended(__u64 flags
)
1001 if ((flags
& BTRFS_BLOCK_GROUP_PROFILE_MASK
) == 0)
1002 flags
|= BTRFS_AVAIL_ALLOC_BIT_SINGLE
;
1006 static inline __u64
extended_to_chunk(__u64 flags
)
1008 return flags
& ~BTRFS_AVAIL_ALLOC_BIT_SINGLE
;
1011 struct btrfs_block_group_item
{
1013 __le64 chunk_objectid
;
1015 } __attribute__ ((__packed__
));
1017 struct btrfs_free_space_info
{
1018 __le32 extent_count
;
1020 } __attribute__ ((__packed__
));
1022 #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
1024 #define BTRFS_QGROUP_LEVEL_SHIFT 48
1025 static inline __u64
btrfs_qgroup_level(__u64 qgroupid
)
1027 return qgroupid
>> BTRFS_QGROUP_LEVEL_SHIFT
;
1030 /* Is subvolume quota turned on? */
1031 #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
1033 /* Is qgroup rescan running? */
1034 #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
1037 * Some qgroup entries are known to be out of date, either because the
1038 * configuration has changed in a way that makes a rescan necessary, or
1039 * because the fs has been mounted with a non-qgroup-aware version.
1041 #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
1043 #define BTRFS_QGROUP_STATUS_VERSION 1
1045 struct btrfs_qgroup_status_item
{
1048 * The generation is updated during every commit. As older
1049 * versions of btrfs are not aware of qgroups, it will be
1050 * possible to detect inconsistencies by checking the
1051 * generation on mount time.
1055 /* Flag definitions see above */
1059 * Only used during scanning to record the progress of the scan.
1060 * It contains a logical address.
1063 } __attribute__ ((__packed__
));
1065 struct btrfs_qgroup_info_item
{
1071 } __attribute__ ((__packed__
));
1074 * Flags definition for qgroup limits
1077 * struct btrfs_qgroup_limit.flags
1078 * struct btrfs_qgroup_limit_item.flags
1080 #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
1081 #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
1082 #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
1083 #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
1084 #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
1085 #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
1087 struct btrfs_qgroup_limit_item
{
1088 /* Only updated when any of the other values change. */
1094 } __attribute__ ((__packed__
));
1097 * Just in case we somehow lose the roots and are not able to mount,
1098 * we store an array of the roots from previous transactions in the super.
1100 #define BTRFS_NUM_BACKUP_ROOTS 4
1101 struct btrfs_root_backup
{
1103 __le64 tree_root_gen
;
1106 __le64 chunk_root_gen
;
1109 __le64 extent_root_gen
;
1115 __le64 dev_root_gen
;
1118 __le64 csum_root_gen
;
1124 __le64 unused_64
[4];
1127 u8 chunk_root_level
;
1128 u8 extent_root_level
;
1132 /* future and to align */
1134 } __attribute__ ((__packed__
));
1137 * This is a very generous portion of the super block, giving us room to
1138 * translate 14 chunks with 3 stripes each.
1140 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
1142 #define BTRFS_LABEL_SIZE 256
1144 /* The super block basically lists the main trees of the FS. */
1145 struct btrfs_super_block
{
1146 /* The first 4 fields must match struct btrfs_header */
1147 u8 csum
[BTRFS_CSUM_SIZE
];
1148 /* FS specific UUID, visible to user */
1149 u8 fsid
[BTRFS_FSID_SIZE
];
1150 __le64 bytenr
; /* this block number */
1153 /* Allowed to be different from the btrfs_header from here own down. */
1160 /* This will help find the new super based on the log root. */
1161 __le64 log_root_transid
;
1164 __le64 root_dir_objectid
;
1168 __le32 __unused_leafsize
;
1170 __le32 sys_chunk_array_size
;
1171 __le64 chunk_root_generation
;
1172 __le64 compat_flags
;
1173 __le64 compat_ro_flags
;
1174 __le64 incompat_flags
;
1177 u8 chunk_root_level
;
1179 struct btrfs_dev_item dev_item
;
1181 char label
[BTRFS_LABEL_SIZE
];
1183 __le64 cache_generation
;
1184 __le64 uuid_tree_generation
;
1186 /* The UUID written into btree blocks */
1187 u8 metadata_uuid
[BTRFS_FSID_SIZE
];
1189 /* Future expansion */
1190 __le64 reserved
[28];
1191 u8 sys_chunk_array
[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE
];
1192 struct btrfs_root_backup super_roots
[BTRFS_NUM_BACKUP_ROOTS
];
1193 } __attribute__ ((__packed__
));
1199 * struct btrfs_super_block::(compat|compat_ro|incompat)_flags
1200 * struct btrfs_ioctl_feature_flags
1202 #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0)
1205 * Older kernels (< 4.9) on big-endian systems produced broken free space tree
1206 * bitmaps, and btrfs-progs also used to corrupt the free space tree (versions
1207 * < 4.7.3). If this bit is clear, then the free space tree cannot be trusted.
1208 * btrfs-progs can also intentionally clear this bit to ask the kernel to
1209 * rebuild the free space tree, however this might not work on older kernels
1210 * that do not know about this bit. If not sure, clear the cache manually on
1211 * first mount when booting older kernel versions.
1213 #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID (1ULL << 1)
1215 #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
1216 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
1217 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
1218 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
1219 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD (1ULL << 4)
1222 * Older kernels tried to do bigger metadata blocks, but the
1223 * code was pretty buggy. Lets not let them try anymore.
1225 #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
1227 #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
1228 #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
1229 #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
1230 #define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)
1231 #define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10)
1232 #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11)
1235 * Compat flags that we support.
1237 * If any incompat flags are set other than the ones specified below then we
1238 * will fail to mount.
1240 #define BTRFS_FEATURE_COMPAT_SUPP 0ULL
1241 #define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL
1242 #define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL
1244 #define BTRFS_FEATURE_COMPAT_RO_SUPP \
1245 (BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE | \
1246 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID)
1248 #define BTRFS_FEATURE_COMPAT_RO_SAFE_SET 0ULL
1249 #define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL
1251 #define BTRFS_FEATURE_INCOMPAT_SUPP \
1252 (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
1253 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
1254 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
1255 BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \
1256 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
1257 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD | \
1258 BTRFS_FEATURE_INCOMPAT_RAID56 | \
1259 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
1260 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \
1261 BTRFS_FEATURE_INCOMPAT_NO_HOLES | \
1262 BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \
1263 BTRFS_FEATURE_INCOMPAT_RAID1C34)
1265 #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \
1266 (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
1267 #define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR 0ULL
1269 #define BTRFS_BACKREF_REV_MAX 256
1270 #define BTRFS_BACKREF_REV_SHIFT 56
1271 #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
1272 BTRFS_BACKREF_REV_SHIFT)
1274 #define BTRFS_OLD_BACKREF_REV 0
1275 #define BTRFS_MIXED_BACKREF_REV 1
1277 #define BTRFS_MAX_LEVEL 8
1279 /* Every tree block (leaf or node) starts with this header. */
1280 struct btrfs_header
{
1281 /* These first four must match the super block */
1282 u8 csum
[BTRFS_CSUM_SIZE
];
1283 u8 fsid
[BTRFS_FSID_SIZE
]; /* FS specific uuid */
1284 __le64 bytenr
; /* Which block this node is supposed to live in */
1287 /* Allowed to be different from the super from here on down. */
1288 u8 chunk_tree_uuid
[BTRFS_UUID_SIZE
];
1293 } __attribute__ ((__packed__
));
1296 * A leaf is full of items. Offset and size tell us where to find
1297 * the item in the leaf (relative to the start of the data area).
1300 struct btrfs_disk_key key
;
1303 } __attribute__ ((__packed__
));
1306 * leaves have an item area and a data area:
1307 * [item0, item1....itemN] [free space] [dataN...data1, data0]
1309 * The data is separate from the items to get the keys closer together
1313 struct btrfs_header header
;
1314 struct btrfs_item items
[];
1315 } __attribute__ ((__packed__
));
1318 * All non-leaf blocks are nodes, they hold only keys and pointers to children
1321 struct btrfs_key_ptr
{
1322 struct btrfs_disk_key key
;
1325 } __attribute__ ((__packed__
));
1328 struct btrfs_header header
;
1329 struct btrfs_key_ptr ptrs
[];
1330 } __attribute__ ((__packed__
));
1332 #endif /* __BTRFS_TREE_H__ */