1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _BTRFS_CTREE_H_
3 #define _BTRFS_CTREE_H_
5 #include <linux/btrfs.h>
6 #include <linux/types.h>
8 #include <linux/stddef.h>
13 /* ASCII for _BHRfS_M, no terminating nul */
14 #define BTRFS_MAGIC 0x4D5F53665248425FULL
16 #define BTRFS_MAX_LEVEL 8
19 * We can actually store much bigger names, but lets not confuse the rest of
22 #define BTRFS_NAME_LEN 255
25 * Theoretical limit is larger, but we keep this down to a sane value. That
26 * should limit greatly the possibility of collisions on inode ref items.
28 #define BTRFS_LINK_MAX 65535U
31 * This header contains the structure definitions and constants used
32 * by file system objects that can be retrieved using
33 * the BTRFS_IOC_SEARCH_TREE ioctl. That means basically anything that
34 * is needed to describe a leaf node's key or item contents.
37 /* holds pointers to all of the tree roots */
38 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
40 /* stores information about which extents are in use, and reference counts */
41 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
44 * chunk tree stores translations from logical -> physical block numbering
45 * the super block points to the chunk tree
47 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
50 * stores information about which areas of a given device are in use.
51 * one per device. The tree of tree roots points to the device tree
53 #define BTRFS_DEV_TREE_OBJECTID 4ULL
55 /* one per subvolume, storing files and directories */
56 #define BTRFS_FS_TREE_OBJECTID 5ULL
58 /* directory objectid inside the root tree */
59 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
61 /* holds checksums of all the data extents */
62 #define BTRFS_CSUM_TREE_OBJECTID 7ULL
64 /* holds quota configuration and tracking */
65 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
67 /* for storing items that use the BTRFS_UUID_KEY* types */
68 #define BTRFS_UUID_TREE_OBJECTID 9ULL
70 /* tracks free space in block groups. */
71 #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
73 /* Holds the block group items for extent tree v2. */
74 #define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL
76 /* device stats in the device tree */
77 #define BTRFS_DEV_STATS_OBJECTID 0ULL
79 /* for storing balance parameters in the root tree */
80 #define BTRFS_BALANCE_OBJECTID -4ULL
82 /* orphan objectid for tracking unlinked/truncated files */
83 #define BTRFS_ORPHAN_OBJECTID -5ULL
85 /* does write ahead logging to speed up fsyncs */
86 #define BTRFS_TREE_LOG_OBJECTID -6ULL
87 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
89 /* for space balancing */
90 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
91 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
94 * extent checksums all have this objectid
95 * this allows them to share the logging tree
98 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
100 /* For storing free space cache */
101 #define BTRFS_FREE_SPACE_OBJECTID -11ULL
104 * The inode number assigned to the special inode for storing
107 #define BTRFS_FREE_INO_OBJECTID -12ULL
109 /* dummy objectid represents multiple objectids */
110 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
113 * All files have objectids in this range.
115 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
116 #define BTRFS_LAST_FREE_OBJECTID -256ULL
117 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
121 * the device items go into the chunk tree. The key is in the form
122 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
124 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
126 #define BTRFS_BTREE_INODE_OBJECTID 1
128 #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
130 #define BTRFS_DEV_REPLACE_DEVID 0ULL
133 * inode items have the data typically returned from stat and store other
134 * info about object characteristics. There is one for every file and dir in
137 #define BTRFS_INODE_ITEM_KEY 1
138 #define BTRFS_INODE_REF_KEY 12
139 #define BTRFS_INODE_EXTREF_KEY 13
140 #define BTRFS_XATTR_ITEM_KEY 24
143 * fs verity items are stored under two different key types on disk.
144 * The descriptor items:
145 * [ inode objectid, BTRFS_VERITY_DESC_ITEM_KEY, offset ]
147 * At offset 0, we store a btrfs_verity_descriptor_item which tracks the size
148 * of the descriptor item and some extra data for encryption.
149 * Starting at offset 1, these hold the generic fs verity descriptor. The
150 * latter are opaque to btrfs, we just read and write them as a blob for the
151 * higher level verity code. The most common descriptor size is 256 bytes.
153 * The merkle tree items:
154 * [ inode objectid, BTRFS_VERITY_MERKLE_ITEM_KEY, offset ]
156 * These also start at offset 0, and correspond to the merkle tree bytes. When
157 * fsverity asks for page 0 of the merkle tree, we pull up one page starting at
158 * offset 0 for this key type. These are also opaque to btrfs, we're blindly
159 * storing whatever fsverity sends down.
161 #define BTRFS_VERITY_DESC_ITEM_KEY 36
162 #define BTRFS_VERITY_MERKLE_ITEM_KEY 37
164 #define BTRFS_ORPHAN_ITEM_KEY 48
165 /* reserve 2-15 close to the inode for later flexibility */
168 * dir items are the name -> inode pointers in a directory. There is one
169 * for every name in a directory. BTRFS_DIR_LOG_ITEM_KEY is no longer used
170 * but it's still defined here for documentation purposes and to help avoid
171 * having its numerical value reused in the future.
173 #define BTRFS_DIR_LOG_ITEM_KEY 60
174 #define BTRFS_DIR_LOG_INDEX_KEY 72
175 #define BTRFS_DIR_ITEM_KEY 84
176 #define BTRFS_DIR_INDEX_KEY 96
178 * extent data is for file data
180 #define BTRFS_EXTENT_DATA_KEY 108
183 * extent csums are stored in a separate tree and hold csums for
184 * an entire extent on disk.
186 #define BTRFS_EXTENT_CSUM_KEY 128
189 * root items point to tree roots. They are typically in the root
190 * tree used by the super block to find all the other trees
192 #define BTRFS_ROOT_ITEM_KEY 132
195 * root backrefs tie subvols and snapshots to the directory entries that
198 #define BTRFS_ROOT_BACKREF_KEY 144
201 * root refs make a fast index for listing all of the snapshots and
202 * subvolumes referenced by a given root. They point directly to the
203 * directory item in the root that references the subvol
205 #define BTRFS_ROOT_REF_KEY 156
208 * extent items are in the extent map tree. These record which blocks
209 * are used, and how many references there are to each block
211 #define BTRFS_EXTENT_ITEM_KEY 168
214 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
215 * the length, so we save the level in key->offset instead of the length.
217 #define BTRFS_METADATA_ITEM_KEY 169
219 #define BTRFS_TREE_BLOCK_REF_KEY 176
221 #define BTRFS_EXTENT_DATA_REF_KEY 178
224 * Obsolete key. Defintion removed in 6.6, value may be reused in the future.
226 * #define BTRFS_EXTENT_REF_V0_KEY 180
229 #define BTRFS_SHARED_BLOCK_REF_KEY 182
231 #define BTRFS_SHARED_DATA_REF_KEY 184
234 * block groups give us hints into the extent allocation trees. Which
235 * blocks are free etc etc
237 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
240 * Every block group is represented in the free space tree by a free space info
241 * item, which stores some accounting information. It is keyed on
242 * (block_group_start, FREE_SPACE_INFO, block_group_length).
244 #define BTRFS_FREE_SPACE_INFO_KEY 198
247 * A free space extent tracks an extent of space that is free in a block group.
248 * It is keyed on (start, FREE_SPACE_EXTENT, length).
250 #define BTRFS_FREE_SPACE_EXTENT_KEY 199
253 * When a block group becomes very fragmented, we convert it to use bitmaps
254 * instead of extents. A free space bitmap is keyed on
255 * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
256 * (length / sectorsize) bits.
258 #define BTRFS_FREE_SPACE_BITMAP_KEY 200
260 #define BTRFS_DEV_EXTENT_KEY 204
261 #define BTRFS_DEV_ITEM_KEY 216
262 #define BTRFS_CHUNK_ITEM_KEY 228
265 * Records the overall state of the qgroups.
266 * There's only one instance of this key present,
267 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
269 #define BTRFS_QGROUP_STATUS_KEY 240
271 * Records the currently used space of the qgroup.
272 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
274 #define BTRFS_QGROUP_INFO_KEY 242
276 * Contains the user configured limits for the qgroup.
277 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
279 #define BTRFS_QGROUP_LIMIT_KEY 244
281 * Records the child-parent relationship of qgroups. For
282 * each relation, 2 keys are present:
283 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
284 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
286 #define BTRFS_QGROUP_RELATION_KEY 246
289 * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
291 #define BTRFS_BALANCE_ITEM_KEY 248
294 * The key type for tree items that are stored persistently, but do not need to
295 * exist for extended period of time. The items can exist in any tree.
297 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
301 * - balance status item
302 * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
304 #define BTRFS_TEMPORARY_ITEM_KEY 248
307 * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
309 #define BTRFS_DEV_STATS_KEY 249
312 * The key type for tree items that are stored persistently and usually exist
313 * for a long period, eg. filesystem lifetime. The item kinds can be status
314 * information, stats or preference values. The item can exist in any tree.
316 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
320 * - device statistics, store IO stats in the device tree, one key for all
322 * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
324 #define BTRFS_PERSISTENT_ITEM_KEY 249
327 * Persistently stores the device replace state in the device tree.
328 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
330 #define BTRFS_DEV_REPLACE_KEY 250
333 * Stores items that allow to quickly map UUIDs to something else.
334 * These items are part of the filesystem UUID tree.
335 * The key is built like this:
336 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
338 #if BTRFS_UUID_SIZE != 16
339 #error "UUID items require BTRFS_UUID_SIZE == 16!"
341 #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
342 #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
343 * received subvols */
346 * string items are for debugging. They just store a short string of
349 #define BTRFS_STRING_ITEM_KEY 253
351 /* Maximum metadata block size (nodesize) */
352 #define BTRFS_MAX_METADATA_BLOCKSIZE 65536
354 /* 32 bytes in various csum fields */
355 #define BTRFS_CSUM_SIZE 32
358 enum btrfs_csum_type {
359 BTRFS_CSUM_TYPE_CRC32 = 0,
360 BTRFS_CSUM_TYPE_XXHASH = 1,
361 BTRFS_CSUM_TYPE_SHA256 = 2,
362 BTRFS_CSUM_TYPE_BLAKE2 = 3,
366 * flags definitions for directory entry item type
369 * struct btrfs_dir_item.type
371 * Values 0..7 must match common file type values in fs_types.h.
373 #define BTRFS_FT_UNKNOWN 0
374 #define BTRFS_FT_REG_FILE 1
375 #define BTRFS_FT_DIR 2
376 #define BTRFS_FT_CHRDEV 3
377 #define BTRFS_FT_BLKDEV 4
378 #define BTRFS_FT_FIFO 5
379 #define BTRFS_FT_SOCK 6
380 #define BTRFS_FT_SYMLINK 7
381 #define BTRFS_FT_XATTR 8
382 #define BTRFS_FT_MAX 9
383 /* Directory contains encrypted data */
384 #define BTRFS_FT_ENCRYPTED 0x80
386 static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags)
388 return flags & ~BTRFS_FT_ENCRYPTED;
394 #define BTRFS_INODE_NODATASUM (1U << 0)
395 #define BTRFS_INODE_NODATACOW (1U << 1)
396 #define BTRFS_INODE_READONLY (1U << 2)
397 #define BTRFS_INODE_NOCOMPRESS (1U << 3)
398 #define BTRFS_INODE_PREALLOC (1U << 4)
399 #define BTRFS_INODE_SYNC (1U << 5)
400 #define BTRFS_INODE_IMMUTABLE (1U << 6)
401 #define BTRFS_INODE_APPEND (1U << 7)
402 #define BTRFS_INODE_NODUMP (1U << 8)
403 #define BTRFS_INODE_NOATIME (1U << 9)
404 #define BTRFS_INODE_DIRSYNC (1U << 10)
405 #define BTRFS_INODE_COMPRESS (1U << 11)
407 #define BTRFS_INODE_ROOT_ITEM_INIT (1U << 31)
409 #define BTRFS_INODE_FLAG_MASK \
410 (BTRFS_INODE_NODATASUM | \
411 BTRFS_INODE_NODATACOW | \
412 BTRFS_INODE_READONLY | \
413 BTRFS_INODE_NOCOMPRESS | \
414 BTRFS_INODE_PREALLOC | \
416 BTRFS_INODE_IMMUTABLE | \
417 BTRFS_INODE_APPEND | \
418 BTRFS_INODE_NODUMP | \
419 BTRFS_INODE_NOATIME | \
420 BTRFS_INODE_DIRSYNC | \
421 BTRFS_INODE_COMPRESS | \
422 BTRFS_INODE_ROOT_ITEM_INIT)
424 #define BTRFS_INODE_RO_VERITY (1U << 0)
426 #define BTRFS_INODE_RO_FLAG_MASK (BTRFS_INODE_RO_VERITY)
429 * The key defines the order in the tree, and so it also defines (optimal)
432 * objectid corresponds to the inode number.
434 * type tells us things about the object, and is a kind of stream selector.
435 * so for a given inode, keys with type of 1 might refer to the inode data,
436 * type of 2 may point to file data in the btree and type == 3 may point to
439 * offset is the starting byte offset for this key in the stream.
441 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
442 * in cpu native order. Otherwise they are identical and their sizes
443 * should be the same (ie both packed)
445 struct btrfs_disk_key {
449 } __attribute__ ((__packed__));
455 } __attribute__ ((__packed__));
458 * Every tree block (leaf or node) starts with this header.
460 struct btrfs_header {
461 /* These first four must match the super block */
462 __u8 csum[BTRFS_CSUM_SIZE];
463 /* FS specific uuid */
464 __u8 fsid[BTRFS_FSID_SIZE];
465 /* Which block this node is supposed to live in */
469 /* Allowed to be different from the super from here on down */
470 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
475 } __attribute__ ((__packed__));
478 * This is a very generous portion of the super block, giving us room to
479 * translate 14 chunks with 3 stripes each.
481 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
484 * Just in case we somehow lose the roots and are not able to mount, we store
485 * an array of the roots from previous transactions in the super.
487 #define BTRFS_NUM_BACKUP_ROOTS 4
488 struct btrfs_root_backup {
490 __le64 tree_root_gen;
493 __le64 chunk_root_gen;
496 __le64 extent_root_gen;
505 __le64 csum_root_gen;
513 __u8 tree_root_level;
514 __u8 chunk_root_level;
515 __u8 extent_root_level;
518 __u8 csum_root_level;
519 /* future and to align */
521 } __attribute__ ((__packed__));
524 * A leaf is full of items. offset and size tell us where to find the item in
525 * the leaf (relative to the start of the data area)
528 struct btrfs_disk_key key;
531 } __attribute__ ((__packed__));
534 * Leaves have an item area and a data area:
535 * [item0, item1....itemN] [free space] [dataN...data1, data0]
537 * The data is separate from the items to get the keys closer together during
541 struct btrfs_header header;
542 struct btrfs_item items[];
543 } __attribute__ ((__packed__));
546 * All non-leaf blocks are nodes, they hold only keys and pointers to other
549 struct btrfs_key_ptr {
550 struct btrfs_disk_key key;
553 } __attribute__ ((__packed__));
556 struct btrfs_header header;
557 struct btrfs_key_ptr ptrs[];
558 } __attribute__ ((__packed__));
560 struct btrfs_dev_item {
561 /* the internal btrfs device id */
564 /* size of the device */
570 /* optimal io alignment for this device */
573 /* optimal io width for this device */
576 /* minimal io size for this device */
579 /* type and info about this device */
582 /* expected generation for this device */
586 * starting byte of this partition on the device,
587 * to allow for stripe alignment in the future
591 /* grouping information for allocation decisions */
594 /* seek speed 0-100 where 100 is fastest */
597 /* bandwidth 0-100 where 100 is fastest */
600 /* btrfs generated uuid for this device */
601 __u8 uuid[BTRFS_UUID_SIZE];
603 /* uuid of FS who owns this device */
604 __u8 fsid[BTRFS_UUID_SIZE];
605 } __attribute__ ((__packed__));
607 struct btrfs_stripe {
610 __u8 dev_uuid[BTRFS_UUID_SIZE];
611 } __attribute__ ((__packed__));
614 /* size of this chunk in bytes */
617 /* objectid of the root referencing this chunk */
623 /* optimal io alignment for this chunk */
626 /* optimal io width for this chunk */
629 /* minimal io size for this chunk */
632 /* 2^16 stripes is quite a lot, a second limit is the size of a single
637 /* sub stripes only matter for raid10 */
639 struct btrfs_stripe stripe;
640 /* additional stripes go here */
641 } __attribute__ ((__packed__));
644 * The super block basically lists the main trees of the FS.
646 struct btrfs_super_block {
647 /* The first 4 fields must match struct btrfs_header */
648 __u8 csum[BTRFS_CSUM_SIZE];
649 /* FS specific UUID, visible to user */
650 __u8 fsid[BTRFS_FSID_SIZE];
651 /* This block number */
655 /* Allowed to be different from the btrfs_header from here own down */
663 * This member has never been utilized since the very beginning, thus
664 * it's always 0 regardless of kernel version. We always use
665 * generation + 1 to read log tree root. So here we mark it deprecated.
667 __le64 __unused_log_root_transid;
670 __le64 root_dir_objectid;
674 __le32 __unused_leafsize;
676 __le32 sys_chunk_array_size;
677 __le64 chunk_root_generation;
679 __le64 compat_ro_flags;
680 __le64 incompat_flags;
683 __u8 chunk_root_level;
685 struct btrfs_dev_item dev_item;
687 char label[BTRFS_LABEL_SIZE];
689 __le64 cache_generation;
690 __le64 uuid_tree_generation;
692 /* The UUID written into btree blocks */
693 __u8 metadata_uuid[BTRFS_FSID_SIZE];
695 __u64 nr_global_roots;
697 /* Future expansion */
699 __u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
700 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
702 /* Padded to 4096 bytes */
704 } __attribute__ ((__packed__));
706 #define BTRFS_FREE_SPACE_EXTENT 1
707 #define BTRFS_FREE_SPACE_BITMAP 2
709 struct btrfs_free_space_entry {
713 } __attribute__ ((__packed__));
715 struct btrfs_free_space_header {
716 struct btrfs_disk_key location;
720 } __attribute__ ((__packed__));
722 #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
723 #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
725 /* Super block flags */
726 /* Errors detected */
727 #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
729 #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
730 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
731 #define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
732 #define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
733 #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
737 * items in the extent btree are used to record the objectid of the
738 * owner of the block and the number of references
741 struct btrfs_extent_item {
745 } __attribute__ ((__packed__));
747 struct btrfs_extent_item_v0 {
749 } __attribute__ ((__packed__));
752 #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
753 #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
755 /* following flags only apply to tree blocks */
757 /* use full backrefs for extent pointers in the block */
758 #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
760 #define BTRFS_BACKREF_REV_MAX 256
761 #define BTRFS_BACKREF_REV_SHIFT 56
762 #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
763 BTRFS_BACKREF_REV_SHIFT)
765 #define BTRFS_OLD_BACKREF_REV 0
766 #define BTRFS_MIXED_BACKREF_REV 1
769 * this flag is only used internally by scrub and may be changed at any time
770 * it is only declared here to avoid collisions
772 #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
774 struct btrfs_tree_block_info {
775 struct btrfs_disk_key key;
777 } __attribute__ ((__packed__));
779 struct btrfs_extent_data_ref {
784 } __attribute__ ((__packed__));
786 struct btrfs_shared_data_ref {
788 } __attribute__ ((__packed__));
790 struct btrfs_extent_inline_ref {
793 } __attribute__ ((__packed__));
795 /* dev extents record free space on individual devices. The owner
796 * field points back to the chunk allocation mapping tree that allocated
797 * the extent. The chunk tree uuid field is a way to double check the owner
799 struct btrfs_dev_extent {
801 __le64 chunk_objectid;
804 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
805 } __attribute__ ((__packed__));
807 struct btrfs_inode_ref {
811 } __attribute__ ((__packed__));
813 struct btrfs_inode_extref {
814 __le64 parent_objectid;
819 } __attribute__ ((__packed__));
821 struct btrfs_timespec {
824 } __attribute__ ((__packed__));
826 struct btrfs_inode_item {
827 /* nfs style generation number */
829 /* transid that last touched this inode */
841 /* modification sequence number for NFS */
845 * a little future expansion, for more than this we can
846 * just grow the inode item and version it
849 struct btrfs_timespec atime;
850 struct btrfs_timespec ctime;
851 struct btrfs_timespec mtime;
852 struct btrfs_timespec otime;
853 } __attribute__ ((__packed__));
855 struct btrfs_dir_log_item {
857 } __attribute__ ((__packed__));
859 struct btrfs_dir_item {
860 struct btrfs_disk_key location;
865 } __attribute__ ((__packed__));
867 #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
870 * Internal in-memory flag that a subvolume has been marked for deletion but
871 * still visible as a directory
873 #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
875 struct btrfs_root_item {
876 struct btrfs_inode_item inode;
882 __le64 last_snapshot;
885 struct btrfs_disk_key drop_progress;
890 * The following fields appear after subvol_uuids+subvol_times
895 * This generation number is used to test if the new fields are valid
896 * and up to date while reading the root item. Every time the root item
897 * is written out, the "generation" field is copied into this field. If
898 * anyone ever mounted the fs with an older kernel, we will have
899 * mismatching generation values here and thus must invalidate the
900 * new fields. See btrfs_update_root and btrfs_find_last_root for
902 * the offset of generation_v2 is also used as the start for the memset
903 * when invalidating the fields.
905 __le64 generation_v2;
906 __u8 uuid[BTRFS_UUID_SIZE];
907 __u8 parent_uuid[BTRFS_UUID_SIZE];
908 __u8 received_uuid[BTRFS_UUID_SIZE];
909 __le64 ctransid; /* updated when an inode changes */
910 __le64 otransid; /* trans when created */
911 __le64 stransid; /* trans when sent. non-zero for received subvol */
912 __le64 rtransid; /* trans when received. non-zero for received subvol */
913 struct btrfs_timespec ctime;
914 struct btrfs_timespec otime;
915 struct btrfs_timespec stime;
916 struct btrfs_timespec rtime;
917 __le64 reserved[8]; /* for future */
918 } __attribute__ ((__packed__));
921 * Btrfs root item used to be smaller than current size. The old format ends
922 * at where member generation_v2 is.
924 static inline __u32 btrfs_legacy_root_item_size(void)
926 return offsetof(struct btrfs_root_item, generation_v2);
930 * this is used for both forward and backward root refs
932 struct btrfs_root_ref {
936 } __attribute__ ((__packed__));
938 struct btrfs_disk_balance_args {
940 * profiles to operate on, single is denoted by
941 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
947 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
948 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
961 /* devid subset filter [pstart..pend) */
965 /* btrfs virtual address space subset filter [vstart..vend) */
970 * profile to convert to, single is denoted by
971 * BTRFS_AVAIL_ALLOC_BIT_SINGLE
975 /* BTRFS_BALANCE_ARGS_* */
979 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
980 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
992 * Process chunks that cross stripes_min..stripes_max devices,
993 * BTRFS_BALANCE_ARGS_STRIPES_RANGE
999 } __attribute__ ((__packed__));
1002 * store balance parameters to disk so that balance can be properly
1003 * resumed after crash or unmount
1005 struct btrfs_balance_item {
1006 /* BTRFS_BALANCE_* */
1009 struct btrfs_disk_balance_args data;
1010 struct btrfs_disk_balance_args meta;
1011 struct btrfs_disk_balance_args sys;
1014 } __attribute__ ((__packed__));
1017 BTRFS_FILE_EXTENT_INLINE = 0,
1018 BTRFS_FILE_EXTENT_REG = 1,
1019 BTRFS_FILE_EXTENT_PREALLOC = 2,
1020 BTRFS_NR_FILE_EXTENT_TYPES = 3,
1023 struct btrfs_file_extent_item {
1025 * transaction id that created this extent
1029 * max number of bytes to hold this extent in ram
1030 * when we split a compressed extent we can't know how big
1031 * each of the resulting pieces will be. So, this is
1032 * an upper limit on the size of the extent in ram instead of
1038 * 32 bits for the various ways we might encode the data,
1039 * including compression and encryption. If any of these
1040 * are set to something a given disk format doesn't understand
1041 * it is treated like an incompat flag for reading and writing,
1046 __le16 other_encoding; /* spare for later use */
1048 /* are we inline data or a real extent? */
1052 * disk space consumed by the extent, checksum blocks are included
1055 * At this offset in the structure, the inline extent data start.
1058 __le64 disk_num_bytes;
1060 * the logical offset in file blocks (no csums)
1061 * this extent record is for. This allows a file extent to point
1062 * into the middle of an existing extent on disk, sharing it
1063 * between two snapshots (useful if some bytes in the middle of the
1064 * extent have changed
1068 * the logical number of file blocks (no csums included). This
1069 * always reflects the size uncompressed and without encoding.
1073 } __attribute__ ((__packed__));
1075 struct btrfs_csum_item {
1077 } __attribute__ ((__packed__));
1079 struct btrfs_dev_stats_item {
1081 * grow this item struct at the end for future enhancements and keep
1082 * the existing values unchanged
1084 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
1085 } __attribute__ ((__packed__));
1087 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
1088 #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
1090 struct btrfs_dev_replace_item {
1092 * grow this item struct at the end for future enhancements and keep
1093 * the existing values unchanged
1097 __le64 cursor_right;
1098 __le64 cont_reading_from_srcdev_mode;
1100 __le64 replace_state;
1101 __le64 time_started;
1102 __le64 time_stopped;
1103 __le64 num_write_errors;
1104 __le64 num_uncorrectable_read_errors;
1105 } __attribute__ ((__packed__));
1107 /* different types of block groups (and chunks) */
1108 #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
1109 #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
1110 #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
1111 #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
1112 #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
1113 #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
1114 #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
1115 #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
1116 #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
1117 #define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
1118 #define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
1119 #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
1120 BTRFS_SPACE_INFO_GLOBAL_RSV)
1122 #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
1123 BTRFS_BLOCK_GROUP_SYSTEM | \
1124 BTRFS_BLOCK_GROUP_METADATA)
1126 #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
1127 BTRFS_BLOCK_GROUP_RAID1 | \
1128 BTRFS_BLOCK_GROUP_RAID1C3 | \
1129 BTRFS_BLOCK_GROUP_RAID1C4 | \
1130 BTRFS_BLOCK_GROUP_RAID5 | \
1131 BTRFS_BLOCK_GROUP_RAID6 | \
1132 BTRFS_BLOCK_GROUP_DUP | \
1133 BTRFS_BLOCK_GROUP_RAID10)
1134 #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
1135 BTRFS_BLOCK_GROUP_RAID6)
1137 #define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
1138 BTRFS_BLOCK_GROUP_RAID1C3 | \
1139 BTRFS_BLOCK_GROUP_RAID1C4)
1142 * We need a bit for restriper to be able to tell when chunks of type
1143 * SINGLE are available. This "extended" profile format is used in
1144 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
1145 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
1146 * to avoid remappings between two formats in future.
1148 #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
1151 * A fake block group type that is used to communicate global block reserve
1152 * size to userspace via the SPACE_INFO ioctl.
1154 #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
1156 #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
1157 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
1159 static inline __u64 chunk_to_extended(__u64 flags)
1161 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
1162 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1166 static inline __u64 extended_to_chunk(__u64 flags)
1168 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1171 struct btrfs_block_group_item {
1173 __le64 chunk_objectid;
1175 } __attribute__ ((__packed__));
1177 struct btrfs_free_space_info {
1178 __le32 extent_count;
1180 } __attribute__ ((__packed__));
1182 #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
1184 #define BTRFS_QGROUP_LEVEL_SHIFT 48
1185 static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
1187 return (__u16)(qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT);
1191 * is subvolume quota turned on?
1193 #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
1195 * RESCAN is set during the initialization phase
1197 #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
1199 * Some qgroup entries are known to be out of date,
1200 * either because the configuration has changed in a way that
1201 * makes a rescan necessary, or because the fs has been mounted
1202 * with a non-qgroup-aware version.
1203 * Turning qouta off and on again makes it inconsistent, too.
1205 #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
1207 #define BTRFS_QGROUP_STATUS_FLAGS_MASK (BTRFS_QGROUP_STATUS_FLAG_ON | \
1208 BTRFS_QGROUP_STATUS_FLAG_RESCAN | \
1209 BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
1211 #define BTRFS_QGROUP_STATUS_VERSION 1
1213 struct btrfs_qgroup_status_item {
1216 * the generation is updated during every commit. As older
1217 * versions of btrfs are not aware of qgroups, it will be
1218 * possible to detect inconsistencies by checking the
1219 * generation on mount time
1223 /* flag definitions see above */
1227 * only used during scanning to record the progress
1228 * of the scan. It contains a logical address
1231 } __attribute__ ((__packed__));
1233 struct btrfs_qgroup_info_item {
1239 } __attribute__ ((__packed__));
1241 struct btrfs_qgroup_limit_item {
1243 * only updated when any of the other values change
1250 } __attribute__ ((__packed__));
1252 struct btrfs_verity_descriptor_item {
1253 /* Size of the verity descriptor in bytes */
1256 * When we implement support for fscrypt, we will need to encrypt the
1257 * Merkle tree for encrypted verity files. These 128 bits are for the
1258 * eventual storage of an fscrypt initialization vector.
1262 } __attribute__ ((__packed__));
1264 #endif /* _BTRFS_CTREE_H_ */