linux/include/uapi/linux/btrfs_tree.h

/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _BTRFS_CTREE_H_
#define _BTRFS_CTREE_H_

#include <linux/btrfs.h>
#include <linux/types.h>
#ifdef __KERNEL__
#include <linux/stddef.h>
#else
#include <stddef.h>
#endif

/* ASCII for _BHRfS_M, no terminating nul */
#define BTRFS_MAGIC

#define BTRFS_MAX_LEVEL

/*
 * We can actually store much bigger names, but lets not confuse the rest of
 * linux.
 */
#define BTRFS_NAME_LEN

/*
 * Theoretical limit is larger, but we keep this down to a sane value. That
 * should limit greatly the possibility of collisions on inode ref items.
 */
#define BTRFS_LINK_MAX

/*
 * This header contains the structure definitions and constants used
 * by file system objects that can be retrieved using
 * the BTRFS_IOC_SEARCH_TREE ioctl.  That means basically anything that
 * is needed to describe a leaf node's key or item contents.
 */

/* holds pointers to all of the tree roots */
#define BTRFS_ROOT_TREE_OBJECTID

/* stores information about which extents are in use, and reference counts */
#define BTRFS_EXTENT_TREE_OBJECTID

/*
 * chunk tree stores translations from logical -> physical block numbering
 * the super block points to the chunk tree
 */
#define BTRFS_CHUNK_TREE_OBJECTID

/*
 * stores information about which areas of a given device are in use.
 * one per device.  The tree of tree roots points to the device tree
 */
#define BTRFS_DEV_TREE_OBJECTID

/* one per subvolume, storing files and directories */
#define BTRFS_FS_TREE_OBJECTID

/* directory objectid inside the root tree */
#define BTRFS_ROOT_TREE_DIR_OBJECTID

/* holds checksums of all the data extents */
#define BTRFS_CSUM_TREE_OBJECTID

/* holds quota configuration and tracking */
#define BTRFS_QUOTA_TREE_OBJECTID

/* for storing items that use the BTRFS_UUID_KEY* types */
#define BTRFS_UUID_TREE_OBJECTID

/* tracks free space in block groups. */
#define BTRFS_FREE_SPACE_TREE_OBJECTID

/* Holds the block group items for extent tree v2. */
#define BTRFS_BLOCK_GROUP_TREE_OBJECTID

/* Tracks RAID stripes in block groups. */
#define BTRFS_RAID_STRIPE_TREE_OBJECTID

/* device stats in the device tree */
#define BTRFS_DEV_STATS_OBJECTID

/* for storing balance parameters in the root tree */
#define BTRFS_BALANCE_OBJECTID

/* orphan objectid for tracking unlinked/truncated files */
#define BTRFS_ORPHAN_OBJECTID

/* does write ahead logging to speed up fsyncs */
#define BTRFS_TREE_LOG_OBJECTID
#define BTRFS_TREE_LOG_FIXUP_OBJECTID

/* for space balancing */
#define BTRFS_TREE_RELOC_OBJECTID
#define BTRFS_DATA_RELOC_TREE_OBJECTID

/*
 * extent checksums all have this objectid
 * this allows them to share the logging tree
 * for fsyncs
 */
#define BTRFS_EXTENT_CSUM_OBJECTID

/* For storing free space cache */
#define BTRFS_FREE_SPACE_OBJECTID

/*
 * The inode number assigned to the special inode for storing
 * free ino cache
 */
#define BTRFS_FREE_INO_OBJECTID

/* dummy objectid represents multiple objectids */
#define BTRFS_MULTIPLE_OBJECTIDS

/*
 * All files have objectids in this range.
 */
#define BTRFS_FIRST_FREE_OBJECTID
#define BTRFS_LAST_FREE_OBJECTID
#define BTRFS_FIRST_CHUNK_TREE_OBJECTID


/*
 * the device items go into the chunk tree.  The key is in the form
 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
 */
#define BTRFS_DEV_ITEMS_OBJECTID

#define BTRFS_BTREE_INODE_OBJECTID

#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID

#define BTRFS_DEV_REPLACE_DEVID

/*
 * inode items have the data typically returned from stat and store other
 * info about object characteristics.  There is one for every file and dir in
 * the FS
 */
#define BTRFS_INODE_ITEM_KEY
#define BTRFS_INODE_REF_KEY
#define BTRFS_INODE_EXTREF_KEY
#define BTRFS_XATTR_ITEM_KEY

/*
 * fs verity items are stored under two different key types on disk.
 * The descriptor items:
 * [ inode objectid, BTRFS_VERITY_DESC_ITEM_KEY, offset ]
 *
 * At offset 0, we store a btrfs_verity_descriptor_item which tracks the size
 * of the descriptor item and some extra data for encryption.
 * Starting at offset 1, these hold the generic fs verity descriptor.  The
 * latter are opaque to btrfs, we just read and write them as a blob for the
 * higher level verity code.  The most common descriptor size is 256 bytes.
 *
 * The merkle tree items:
 * [ inode objectid, BTRFS_VERITY_MERKLE_ITEM_KEY, offset ]
 *
 * These also start at offset 0, and correspond to the merkle tree bytes.  When
 * fsverity asks for page 0 of the merkle tree, we pull up one page starting at
 * offset 0 for this key type.  These are also opaque to btrfs, we're blindly
 * storing whatever fsverity sends down.
 */
#define BTRFS_VERITY_DESC_ITEM_KEY
#define BTRFS_VERITY_MERKLE_ITEM_KEY

#define BTRFS_ORPHAN_ITEM_KEY
/* reserve 2-15 close to the inode for later flexibility */

/*
 * dir items are the name -> inode pointers in a directory.  There is one
 * for every name in a directory.  BTRFS_DIR_LOG_ITEM_KEY is no longer used
 * but it's still defined here for documentation purposes and to help avoid
 * having its numerical value reused in the future.
 */
#define BTRFS_DIR_LOG_ITEM_KEY
#define BTRFS_DIR_LOG_INDEX_KEY
#define BTRFS_DIR_ITEM_KEY
#define BTRFS_DIR_INDEX_KEY
/*
 * extent data is for file data
 */
#define BTRFS_EXTENT_DATA_KEY

/*
 * extent csums are stored in a separate tree and hold csums for
 * an entire extent on disk.
 */
#define BTRFS_EXTENT_CSUM_KEY

/*
 * root items point to tree roots.  They are typically in the root
 * tree used by the super block to find all the other trees
 */
#define BTRFS_ROOT_ITEM_KEY

/*
 * root backrefs tie subvols and snapshots to the directory entries that
 * reference them
 */
#define BTRFS_ROOT_BACKREF_KEY

/*
 * root refs make a fast index for listing all of the snapshots and
 * subvolumes referenced by a given root.  They point directly to the
 * directory item in the root that references the subvol
 */
#define BTRFS_ROOT_REF_KEY

/*
 * extent items are in the extent map tree.  These record which blocks
 * are used, and how many references there are to each block
 */
#define BTRFS_EXTENT_ITEM_KEY

/*
 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
 * the length, so we save the level in key->offset instead of the length.
 */
#define BTRFS_METADATA_ITEM_KEY

/*
 * Special inline ref key which stores the id of the subvolume which originally
 * created the extent. This subvolume owns the extent permanently from the
 * perspective of simple quotas. Needed to know which subvolume to free quota
 * usage from when the extent is deleted.
 *
 * Stored as an inline ref rather to avoid wasting space on a separate item on
 * top of the existing extent item. However, unlike the other inline refs,
 * there is one one owner ref per extent rather than one per extent.
 *
 * Because of this, it goes at the front of the list of inline refs, and thus
 * must have a lower type value than any other inline ref type (to satisfy the
 * disk format rule that inline refs have non-decreasing type).
 */
#define BTRFS_EXTENT_OWNER_REF_KEY

#define BTRFS_TREE_BLOCK_REF_KEY

#define BTRFS_EXTENT_DATA_REF_KEY

/*
 * Obsolete key. Defintion removed in 6.6, value may be reused in the future.
 *
 * #define BTRFS_EXTENT_REF_V0_KEY	180
 */

#define BTRFS_SHARED_BLOCK_REF_KEY

#define BTRFS_SHARED_DATA_REF_KEY

/*
 * block groups give us hints into the extent allocation trees.  Which
 * blocks are free etc etc
 */
#define BTRFS_BLOCK_GROUP_ITEM_KEY

/*
 * Every block group is represented in the free space tree by a free space info
 * item, which stores some accounting information. It is keyed on
 * (block_group_start, FREE_SPACE_INFO, block_group_length).
 */
#define BTRFS_FREE_SPACE_INFO_KEY

/*
 * A free space extent tracks an extent of space that is free in a block group.
 * It is keyed on (start, FREE_SPACE_EXTENT, length).
 */
#define BTRFS_FREE_SPACE_EXTENT_KEY

/*
 * When a block group becomes very fragmented, we convert it to use bitmaps
 * instead of extents. A free space bitmap is keyed on
 * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
 * (length / sectorsize) bits.
 */
#define BTRFS_FREE_SPACE_BITMAP_KEY

#define BTRFS_DEV_EXTENT_KEY
#define BTRFS_DEV_ITEM_KEY
#define BTRFS_CHUNK_ITEM_KEY

#define BTRFS_RAID_STRIPE_KEY

/*
 * Records the overall state of the qgroups.
 * There's only one instance of this key present,
 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
 */
#define BTRFS_QGROUP_STATUS_KEY
/*
 * Records the currently used space of the qgroup.
 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
 */
#define BTRFS_QGROUP_INFO_KEY
/*
 * Contains the user configured limits for the qgroup.
 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
 */
#define BTRFS_QGROUP_LIMIT_KEY
/*
 * Records the child-parent relationship of qgroups. For
 * each relation, 2 keys are present:
 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
 */
#define BTRFS_QGROUP_RELATION_KEY

/*
 * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
 */
#define BTRFS_BALANCE_ITEM_KEY

/*
 * The key type for tree items that are stored persistently, but do not need to
 * exist for extended period of time. The items can exist in any tree.
 *
 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
 *
 * Existing items:
 *
 * - balance status item
 *   (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
 */
#define BTRFS_TEMPORARY_ITEM_KEY

/*
 * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
 */
#define BTRFS_DEV_STATS_KEY

/*
 * The key type for tree items that are stored persistently and usually exist
 * for a long period, eg. filesystem lifetime. The item kinds can be status
 * information, stats or preference values. The item can exist in any tree.
 *
 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
 *
 * Existing items:
 *
 * - device statistics, store IO stats in the device tree, one key for all
 *   stats
 *   (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
 */
#define BTRFS_PERSISTENT_ITEM_KEY

/*
 * Persistently stores the device replace state in the device tree.
 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
 */
#define BTRFS_DEV_REPLACE_KEY

/*
 * Stores items that allow to quickly map UUIDs to something else.
 * These items are part of the filesystem UUID tree.
 * The key is built like this:
 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
 */
#if BTRFS_UUID_SIZE != 16
#error "UUID items require BTRFS_UUID_SIZE == 16!"
#endif
#define BTRFS_UUID_KEY_SUBVOL
#define BTRFS_UUID_KEY_RECEIVED_SUBVOL

/*
 * string items are for debugging.  They just store a short string of
 * data in the FS
 */
#define BTRFS_STRING_ITEM_KEY

/* Maximum metadata block size (nodesize) */
#define BTRFS_MAX_METADATA_BLOCKSIZE

/* 32 bytes in various csum fields */
#define BTRFS_CSUM_SIZE

/* csum types */
enum btrfs_csum_type {};

/*
 * flags definitions for directory entry item type
 *
 * Used by:
 * struct btrfs_dir_item.type
 *
 * Values 0..7 must match common file type values in fs_types.h.
 */
#define BTRFS_FT_UNKNOWN
#define BTRFS_FT_REG_FILE
#define BTRFS_FT_DIR
#define BTRFS_FT_CHRDEV
#define BTRFS_FT_BLKDEV
#define BTRFS_FT_FIFO
#define BTRFS_FT_SOCK
#define BTRFS_FT_SYMLINK
#define BTRFS_FT_XATTR
#define BTRFS_FT_MAX
/* Directory contains encrypted data */
#define BTRFS_FT_ENCRYPTED

static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags)
{}

/*
 * Inode flags
 */
#define BTRFS_INODE_NODATASUM
#define BTRFS_INODE_NODATACOW
#define BTRFS_INODE_READONLY
#define BTRFS_INODE_NOCOMPRESS
#define BTRFS_INODE_PREALLOC
#define BTRFS_INODE_SYNC
#define BTRFS_INODE_IMMUTABLE
#define BTRFS_INODE_APPEND
#define BTRFS_INODE_NODUMP
#define BTRFS_INODE_NOATIME
#define BTRFS_INODE_DIRSYNC
#define BTRFS_INODE_COMPRESS

#define BTRFS_INODE_ROOT_ITEM_INIT

#define BTRFS_INODE_FLAG_MASK

#define BTRFS_INODE_RO_VERITY

#define BTRFS_INODE_RO_FLAG_MASK

/*
 * The key defines the order in the tree, and so it also defines (optimal)
 * block layout.
 *
 * objectid corresponds to the inode number.
 *
 * type tells us things about the object, and is a kind of stream selector.
 * so for a given inode, keys with type of 1 might refer to the inode data,
 * type of 2 may point to file data in the btree and type == 3 may point to
 * extents.
 *
 * offset is the starting byte offset for this key in the stream.
 *
 * btrfs_disk_key is in disk byte order.  struct btrfs_key is always
 * in cpu native order.  Otherwise they are identical and their sizes
 * should be the same (ie both packed)
 */
struct btrfs_disk_key {} __attribute__ ((packed));

struct btrfs_key {} __attribute__ ((packed));

/*
 * Every tree block (leaf or node) starts with this header.
 */
struct btrfs_header {} __attribute__ ((packed));

/*
 * This is a very generous portion of the super block, giving us room to
 * translate 14 chunks with 3 stripes each.
 */
#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE

/*
 * Just in case we somehow lose the roots and are not able to mount, we store
 * an array of the roots from previous transactions in the super.
 */
#define BTRFS_NUM_BACKUP_ROOTS
struct btrfs_root_backup {} __attribute__ ((packed));

/*
 * A leaf is full of items. offset and size tell us where to find the item in
 * the leaf (relative to the start of the data area)
 */
struct btrfs_item {} __attribute__ ((packed));

/*
 * Leaves have an item area and a data area:
 * [item0, item1....itemN] [free space] [dataN...data1, data0]
 *
 * The data is separate from the items to get the keys closer together during
 * searches.
 */
struct btrfs_leaf {} __attribute__ ((packed));

/*
 * All non-leaf blocks are nodes, they hold only keys and pointers to other
 * blocks.
 */
struct btrfs_key_ptr {} __attribute__ ((packed));

struct btrfs_node {} __attribute__ ((packed));

struct btrfs_dev_item {} __attribute__ ((packed));

struct btrfs_stripe {} __attribute__ ((packed));

struct btrfs_chunk {} __attribute__ ((packed));

/*
 * The super block basically lists the main trees of the FS.
 */
struct btrfs_super_block {} __attribute__ ((packed));

#define BTRFS_FREE_SPACE_EXTENT
#define BTRFS_FREE_SPACE_BITMAP

struct btrfs_free_space_entry {} __attribute__ ((packed));

struct btrfs_free_space_header {} __attribute__ ((packed));

struct btrfs_raid_stride {} __attribute__ ((packed));

struct btrfs_stripe_extent {} __attribute__ ((packed));

#define BTRFS_HEADER_FLAG_WRITTEN
#define BTRFS_HEADER_FLAG_RELOC

/* Super block flags */
/* Errors detected */
#define BTRFS_SUPER_FLAG_ERROR

#define BTRFS_SUPER_FLAG_SEEDING
#define BTRFS_SUPER_FLAG_METADUMP
#define BTRFS_SUPER_FLAG_METADUMP_V2
#define BTRFS_SUPER_FLAG_CHANGING_FSID
#define BTRFS_SUPER_FLAG_CHANGING_FSID_V2

/*
 * Those are temporaray flags utilized by btrfs-progs to do offline conversion.
 * They are rejected by kernel.
 * But still keep them all here to avoid conflicts.
 */
#define BTRFS_SUPER_FLAG_CHANGING_BG_TREE
#define BTRFS_SUPER_FLAG_CHANGING_DATA_CSUM
#define BTRFS_SUPER_FLAG_CHANGING_META_CSUM

/*
 * items in the extent btree are used to record the objectid of the
 * owner of the block and the number of references
 */

struct btrfs_extent_item {} __attribute__ ((packed));

struct btrfs_extent_item_v0 {} __attribute__ ((packed));


#define BTRFS_EXTENT_FLAG_DATA
#define BTRFS_EXTENT_FLAG_TREE_BLOCK

/* following flags only apply to tree blocks */

/* use full backrefs for extent pointers in the block */
#define BTRFS_BLOCK_FLAG_FULL_BACKREF

#define BTRFS_BACKREF_REV_MAX
#define BTRFS_BACKREF_REV_SHIFT
#define BTRFS_BACKREF_REV_MASK

#define BTRFS_OLD_BACKREF_REV
#define BTRFS_MIXED_BACKREF_REV

/*
 * this flag is only used internally by scrub and may be changed at any time
 * it is only declared here to avoid collisions
 */
#define BTRFS_EXTENT_FLAG_SUPER

struct btrfs_tree_block_info {} __attribute__ ((packed));

struct btrfs_extent_data_ref {} __attribute__ ((packed));

struct btrfs_shared_data_ref {} __attribute__ ((packed));

struct btrfs_extent_owner_ref {} __attribute__ ((packed));

struct btrfs_extent_inline_ref {} __attribute__ ((packed));

/* dev extents record free space on individual devices.  The owner
 * field points back to the chunk allocation mapping tree that allocated
 * the extent.  The chunk tree uuid field is a way to double check the owner
 */
struct btrfs_dev_extent {} __attribute__ ((packed));

struct btrfs_inode_ref {} __attribute__ ((packed));

struct btrfs_inode_extref {} __attribute__ ((packed));

struct btrfs_timespec {} __attribute__ ((packed));

struct btrfs_inode_item {} __attribute__ ((packed));

struct btrfs_dir_log_item {} __attribute__ ((packed));

struct btrfs_dir_item {} __attribute__ ((packed));

#define BTRFS_ROOT_SUBVOL_RDONLY

/*
 * Internal in-memory flag that a subvolume has been marked for deletion but
 * still visible as a directory
 */
#define BTRFS_ROOT_SUBVOL_DEAD

struct btrfs_root_item {} __attribute__ ((packed));

/*
 * Btrfs root item used to be smaller than current size.  The old format ends
 * at where member generation_v2 is.
 */
static inline __u32 btrfs_legacy_root_item_size(void)
{}

/*
 * this is used for both forward and backward root refs
 */
struct btrfs_root_ref {} __attribute__ ((packed));

struct btrfs_disk_balance_args {} __attribute__ ((packed));

/*
 * store balance parameters to disk so that balance can be properly
 * resumed after crash or unmount
 */
struct btrfs_balance_item {} __attribute__ ((packed));

enum {};

struct btrfs_file_extent_item {} __attribute__ ((packed));

struct btrfs_csum_item {} __attribute__ ((packed));

struct btrfs_dev_stats_item {} __attribute__ ((packed));

#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS
#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID

struct btrfs_dev_replace_item {} __attribute__ ((packed));

/* different types of block groups (and chunks) */
#define BTRFS_BLOCK_GROUP_DATA
#define BTRFS_BLOCK_GROUP_SYSTEM
#define BTRFS_BLOCK_GROUP_METADATA
#define BTRFS_BLOCK_GROUP_RAID0
#define BTRFS_BLOCK_GROUP_RAID1
#define BTRFS_BLOCK_GROUP_DUP
#define BTRFS_BLOCK_GROUP_RAID10
#define BTRFS_BLOCK_GROUP_RAID5
#define BTRFS_BLOCK_GROUP_RAID6
#define BTRFS_BLOCK_GROUP_RAID1C3
#define BTRFS_BLOCK_GROUP_RAID1C4
#define BTRFS_BLOCK_GROUP_RESERVED

#define BTRFS_BLOCK_GROUP_TYPE_MASK

#define BTRFS_BLOCK_GROUP_PROFILE_MASK
#define BTRFS_BLOCK_GROUP_RAID56_MASK

#define BTRFS_BLOCK_GROUP_RAID1_MASK

/*
 * We need a bit for restriper to be able to tell when chunks of type
 * SINGLE are available.  This "extended" profile format is used in
 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
 * (on-disk).  The corresponding on-disk bit in chunk.type is reserved
 * to avoid remappings between two formats in future.
 */
#define BTRFS_AVAIL_ALLOC_BIT_SINGLE

/*
 * A fake block group type that is used to communicate global block reserve
 * size to userspace via the SPACE_INFO ioctl.
 */
#define BTRFS_SPACE_INFO_GLOBAL_RSV

#define BTRFS_EXTENDED_PROFILE_MASK

static inline __u64 chunk_to_extended(__u64 flags)
{}
static inline __u64 extended_to_chunk(__u64 flags)
{}

struct btrfs_block_group_item {} __attribute__ ((packed));

struct btrfs_free_space_info {} __attribute__ ((packed));

#define BTRFS_FREE_SPACE_USING_BITMAPS

#define BTRFS_QGROUP_LEVEL_SHIFT
static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
{}

/*
 * is subvolume quota turned on?
 */
#define BTRFS_QGROUP_STATUS_FLAG_ON
/*
 * RESCAN is set during the initialization phase
 */
#define BTRFS_QGROUP_STATUS_FLAG_RESCAN
/*
 * Some qgroup entries are known to be out of date,
 * either because the configuration has changed in a way that
 * makes a rescan necessary, or because the fs has been mounted
 * with a non-qgroup-aware version.
 * Turning qouta off and on again makes it inconsistent, too.
 */
#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT

/*
 * Whether or not this filesystem is using simple quotas.  Not exactly the
 * incompat bit, because we support using simple quotas, disabling it, then
 * going back to full qgroup quotas.
 */
#define BTRFS_QGROUP_STATUS_FLAG_SIMPLE_MODE

#define BTRFS_QGROUP_STATUS_FLAGS_MASK

#define BTRFS_QGROUP_STATUS_VERSION

struct btrfs_qgroup_status_item {} __attribute__ ((packed));

struct btrfs_qgroup_info_item {} __attribute__ ((packed));

struct btrfs_qgroup_limit_item {} __attribute__ ((packed));

struct btrfs_verity_descriptor_item {} __attribute__ ((packed));

#endif /* _BTRFS_CTREE_H_ */