linux/include/uapi/linux/btrfs_tree.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
   2#ifndef _BTRFS_CTREE_H_
   3#define _BTRFS_CTREE_H_
   4
   5#include <linux/btrfs.h>
   6#include <linux/types.h>
   7#ifdef __KERNEL__
   8#include <linux/stddef.h>
   9#else
  10#include <stddef.h>
  11#endif
  12
  13/*
  14 * This header contains the structure definitions and constants used
  15 * by file system objects that can be retrieved using
  16 * the BTRFS_IOC_SEARCH_TREE ioctl.  That means basically anything that
  17 * is needed to describe a leaf node's key or item contents.
  18 */
  19
  20/* holds pointers to all of the tree roots */
  21#define BTRFS_ROOT_TREE_OBJECTID 1ULL
  22
  23/* stores information about which extents are in use, and reference counts */
  24#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
  25
  26/*
  27 * chunk tree stores translations from logical -> physical block numbering
  28 * the super block points to the chunk tree
  29 */
  30#define BTRFS_CHUNK_TREE_OBJECTID 3ULL
  31
  32/*
  33 * stores information about which areas of a given device are in use.
  34 * one per device.  The tree of tree roots points to the device tree
  35 */
  36#define BTRFS_DEV_TREE_OBJECTID 4ULL
  37
  38/* one per subvolume, storing files and directories */
  39#define BTRFS_FS_TREE_OBJECTID 5ULL
  40
  41/* directory objectid inside the root tree */
  42#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
  43
  44/* holds checksums of all the data extents */
  45#define BTRFS_CSUM_TREE_OBJECTID 7ULL
  46
  47/* holds quota configuration and tracking */
  48#define BTRFS_QUOTA_TREE_OBJECTID 8ULL
  49
  50/* for storing items that use the BTRFS_UUID_KEY* types */
  51#define BTRFS_UUID_TREE_OBJECTID 9ULL
  52
  53/* tracks free space in block groups. */
  54#define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
  55
  56/* device stats in the device tree */
  57#define BTRFS_DEV_STATS_OBJECTID 0ULL
  58
  59/* for storing balance parameters in the root tree */
  60#define BTRFS_BALANCE_OBJECTID -4ULL
  61
  62/* orphan objectid for tracking unlinked/truncated files */
  63#define BTRFS_ORPHAN_OBJECTID -5ULL
  64
  65/* does write ahead logging to speed up fsyncs */
  66#define BTRFS_TREE_LOG_OBJECTID -6ULL
  67#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
  68
  69/* for space balancing */
  70#define BTRFS_TREE_RELOC_OBJECTID -8ULL
  71#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
  72
  73/*
  74 * extent checksums all have this objectid
  75 * this allows them to share the logging tree
  76 * for fsyncs
  77 */
  78#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
  79
  80/* For storing free space cache */
  81#define BTRFS_FREE_SPACE_OBJECTID -11ULL
  82
  83/*
  84 * The inode number assigned to the special inode for storing
  85 * free ino cache
  86 */
  87#define BTRFS_FREE_INO_OBJECTID -12ULL
  88
  89/* dummy objectid represents multiple objectids */
  90#define BTRFS_MULTIPLE_OBJECTIDS -255ULL
  91
  92/*
  93 * All files have objectids in this range.
  94 */
  95#define BTRFS_FIRST_FREE_OBJECTID 256ULL
  96#define BTRFS_LAST_FREE_OBJECTID -256ULL
  97#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
  98
  99
 100/*
 101 * the device items go into the chunk tree.  The key is in the form
 102 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
 103 */
 104#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
 105
 106#define BTRFS_BTREE_INODE_OBJECTID 1
 107
 108#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
 109
 110#define BTRFS_DEV_REPLACE_DEVID 0ULL
 111
 112/*
 113 * inode items have the data typically returned from stat and store other
 114 * info about object characteristics.  There is one for every file and dir in
 115 * the FS
 116 */
 117#define BTRFS_INODE_ITEM_KEY            1
 118#define BTRFS_INODE_REF_KEY             12
 119#define BTRFS_INODE_EXTREF_KEY          13
 120#define BTRFS_XATTR_ITEM_KEY            24
 121
 122/*
 123 * fs verity items are stored under two different key types on disk.
 124 * The descriptor items:
 125 * [ inode objectid, BTRFS_VERITY_DESC_ITEM_KEY, offset ]
 126 *
 127 * At offset 0, we store a btrfs_verity_descriptor_item which tracks the size
 128 * of the descriptor item and some extra data for encryption.
 129 * Starting at offset 1, these hold the generic fs verity descriptor.  The
 130 * latter are opaque to btrfs, we just read and write them as a blob for the
 131 * higher level verity code.  The most common descriptor size is 256 bytes.
 132 *
 133 * The merkle tree items:
 134 * [ inode objectid, BTRFS_VERITY_MERKLE_ITEM_KEY, offset ]
 135 *
 136 * These also start at offset 0, and correspond to the merkle tree bytes.  When
 137 * fsverity asks for page 0 of the merkle tree, we pull up one page starting at
 138 * offset 0 for this key type.  These are also opaque to btrfs, we're blindly
 139 * storing whatever fsverity sends down.
 140 */
 141#define BTRFS_VERITY_DESC_ITEM_KEY      36
 142#define BTRFS_VERITY_MERKLE_ITEM_KEY    37
 143
 144#define BTRFS_ORPHAN_ITEM_KEY           48
 145/* reserve 2-15 close to the inode for later flexibility */
 146
 147/*
 148 * dir items are the name -> inode pointers in a directory.  There is one
 149 * for every name in a directory.  BTRFS_DIR_LOG_ITEM_KEY is no longer used
 150 * but it's still defined here for documentation purposes and to help avoid
 151 * having its numerical value reused in the future.
 152 */
 153#define BTRFS_DIR_LOG_ITEM_KEY  60
 154#define BTRFS_DIR_LOG_INDEX_KEY 72
 155#define BTRFS_DIR_ITEM_KEY      84
 156#define BTRFS_DIR_INDEX_KEY     96
 157/*
 158 * extent data is for file data
 159 */
 160#define BTRFS_EXTENT_DATA_KEY   108
 161
 162/*
 163 * extent csums are stored in a separate tree and hold csums for
 164 * an entire extent on disk.
 165 */
 166#define BTRFS_EXTENT_CSUM_KEY   128
 167
 168/*
 169 * root items point to tree roots.  They are typically in the root
 170 * tree used by the super block to find all the other trees
 171 */
 172#define BTRFS_ROOT_ITEM_KEY     132
 173
 174/*
 175 * root backrefs tie subvols and snapshots to the directory entries that
 176 * reference them
 177 */
 178#define BTRFS_ROOT_BACKREF_KEY  144
 179
 180/*
 181 * root refs make a fast index for listing all of the snapshots and
 182 * subvolumes referenced by a given root.  They point directly to the
 183 * directory item in the root that references the subvol
 184 */
 185#define BTRFS_ROOT_REF_KEY      156
 186
 187/*
 188 * extent items are in the extent map tree.  These record which blocks
 189 * are used, and how many references there are to each block
 190 */
 191#define BTRFS_EXTENT_ITEM_KEY   168
 192
 193/*
 194 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
 195 * the length, so we save the level in key->offset instead of the length.
 196 */
 197#define BTRFS_METADATA_ITEM_KEY 169
 198
 199#define BTRFS_TREE_BLOCK_REF_KEY        176
 200
 201#define BTRFS_EXTENT_DATA_REF_KEY       178
 202
 203#define BTRFS_EXTENT_REF_V0_KEY         180
 204
 205#define BTRFS_SHARED_BLOCK_REF_KEY      182
 206
 207#define BTRFS_SHARED_DATA_REF_KEY       184
 208
 209/*
 210 * block groups give us hints into the extent allocation trees.  Which
 211 * blocks are free etc etc
 212 */
 213#define BTRFS_BLOCK_GROUP_ITEM_KEY 192
 214
 215/*
 216 * Every block group is represented in the free space tree by a free space info
 217 * item, which stores some accounting information. It is keyed on
 218 * (block_group_start, FREE_SPACE_INFO, block_group_length).
 219 */
 220#define BTRFS_FREE_SPACE_INFO_KEY 198
 221
 222/*
 223 * A free space extent tracks an extent of space that is free in a block group.
 224 * It is keyed on (start, FREE_SPACE_EXTENT, length).
 225 */
 226#define BTRFS_FREE_SPACE_EXTENT_KEY 199
 227
 228/*
 229 * When a block group becomes very fragmented, we convert it to use bitmaps
 230 * instead of extents. A free space bitmap is keyed on
 231 * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
 232 * (length / sectorsize) bits.
 233 */
 234#define BTRFS_FREE_SPACE_BITMAP_KEY 200
 235
 236#define BTRFS_DEV_EXTENT_KEY    204
 237#define BTRFS_DEV_ITEM_KEY      216
 238#define BTRFS_CHUNK_ITEM_KEY    228
 239
 240/*
 241 * Records the overall state of the qgroups.
 242 * There's only one instance of this key present,
 243 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
 244 */
 245#define BTRFS_QGROUP_STATUS_KEY         240
 246/*
 247 * Records the currently used space of the qgroup.
 248 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
 249 */
 250#define BTRFS_QGROUP_INFO_KEY           242
 251/*
 252 * Contains the user configured limits for the qgroup.
 253 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
 254 */
 255#define BTRFS_QGROUP_LIMIT_KEY          244
 256/*
 257 * Records the child-parent relationship of qgroups. For
 258 * each relation, 2 keys are present:
 259 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
 260 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
 261 */
 262#define BTRFS_QGROUP_RELATION_KEY       246
 263
 264/*
 265 * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
 266 */
 267#define BTRFS_BALANCE_ITEM_KEY  248
 268
 269/*
 270 * The key type for tree items that are stored persistently, but do not need to
 271 * exist for extended period of time. The items can exist in any tree.
 272 *
 273 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
 274 *
 275 * Existing items:
 276 *
 277 * - balance status item
 278 *   (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
 279 */
 280#define BTRFS_TEMPORARY_ITEM_KEY        248
 281
 282/*
 283 * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
 284 */
 285#define BTRFS_DEV_STATS_KEY             249
 286
 287/*
 288 * The key type for tree items that are stored persistently and usually exist
 289 * for a long period, eg. filesystem lifetime. The item kinds can be status
 290 * information, stats or preference values. The item can exist in any tree.
 291 *
 292 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
 293 *
 294 * Existing items:
 295 *
 296 * - device statistics, store IO stats in the device tree, one key for all
 297 *   stats
 298 *   (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
 299 */
 300#define BTRFS_PERSISTENT_ITEM_KEY       249
 301
 302/*
 303 * Persistently stores the device replace state in the device tree.
 304 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
 305 */
 306#define BTRFS_DEV_REPLACE_KEY   250
 307
 308/*
 309 * Stores items that allow to quickly map UUIDs to something else.
 310 * These items are part of the filesystem UUID tree.
 311 * The key is built like this:
 312 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
 313 */
 314#if BTRFS_UUID_SIZE != 16
 315#error "UUID items require BTRFS_UUID_SIZE == 16!"
 316#endif
 317#define BTRFS_UUID_KEY_SUBVOL   251     /* for UUIDs assigned to subvols */
 318#define BTRFS_UUID_KEY_RECEIVED_SUBVOL  252     /* for UUIDs assigned to
 319                                                 * received subvols */
 320
 321/*
 322 * string items are for debugging.  They just store a short string of
 323 * data in the FS
 324 */
 325#define BTRFS_STRING_ITEM_KEY   253
 326
 327/* Maximum metadata block size (nodesize) */
 328#define BTRFS_MAX_METADATA_BLOCKSIZE                    65536
 329
 330/* 32 bytes in various csum fields */
 331#define BTRFS_CSUM_SIZE 32
 332
 333/* csum types */
 334enum btrfs_csum_type {
 335        BTRFS_CSUM_TYPE_CRC32   = 0,
 336        BTRFS_CSUM_TYPE_XXHASH  = 1,
 337        BTRFS_CSUM_TYPE_SHA256  = 2,
 338        BTRFS_CSUM_TYPE_BLAKE2  = 3,
 339};
 340
 341/*
 342 * flags definitions for directory entry item type
 343 *
 344 * Used by:
 345 * struct btrfs_dir_item.type
 346 *
 347 * Values 0..7 must match common file type values in fs_types.h.
 348 */
 349#define BTRFS_FT_UNKNOWN        0
 350#define BTRFS_FT_REG_FILE       1
 351#define BTRFS_FT_DIR            2
 352#define BTRFS_FT_CHRDEV         3
 353#define BTRFS_FT_BLKDEV         4
 354#define BTRFS_FT_FIFO           5
 355#define BTRFS_FT_SOCK           6
 356#define BTRFS_FT_SYMLINK        7
 357#define BTRFS_FT_XATTR          8
 358#define BTRFS_FT_MAX            9
 359
 360/*
 361 * The key defines the order in the tree, and so it also defines (optimal)
 362 * block layout.
 363 *
 364 * objectid corresponds to the inode number.
 365 *
 366 * type tells us things about the object, and is a kind of stream selector.
 367 * so for a given inode, keys with type of 1 might refer to the inode data,
 368 * type of 2 may point to file data in the btree and type == 3 may point to
 369 * extents.
 370 *
 371 * offset is the starting byte offset for this key in the stream.
 372 *
 373 * btrfs_disk_key is in disk byte order.  struct btrfs_key is always
 374 * in cpu native order.  Otherwise they are identical and their sizes
 375 * should be the same (ie both packed)
 376 */
 377struct btrfs_disk_key {
 378        __le64 objectid;
 379        __u8 type;
 380        __le64 offset;
 381} __attribute__ ((__packed__));
 382
 383struct btrfs_key {
 384        __u64 objectid;
 385        __u8 type;
 386        __u64 offset;
 387} __attribute__ ((__packed__));
 388
 389struct btrfs_dev_item {
 390        /* the internal btrfs device id */
 391        __le64 devid;
 392
 393        /* size of the device */
 394        __le64 total_bytes;
 395
 396        /* bytes used */
 397        __le64 bytes_used;
 398
 399        /* optimal io alignment for this device */
 400        __le32 io_align;
 401
 402        /* optimal io width for this device */
 403        __le32 io_width;
 404
 405        /* minimal io size for this device */
 406        __le32 sector_size;
 407
 408        /* type and info about this device */
 409        __le64 type;
 410
 411        /* expected generation for this device */
 412        __le64 generation;
 413
 414        /*
 415         * starting byte of this partition on the device,
 416         * to allow for stripe alignment in the future
 417         */
 418        __le64 start_offset;
 419
 420        /* grouping information for allocation decisions */
 421        __le32 dev_group;
 422
 423        /* seek speed 0-100 where 100 is fastest */
 424        __u8 seek_speed;
 425
 426        /* bandwidth 0-100 where 100 is fastest */
 427        __u8 bandwidth;
 428
 429        /* btrfs generated uuid for this device */
 430        __u8 uuid[BTRFS_UUID_SIZE];
 431
 432        /* uuid of FS who owns this device */
 433        __u8 fsid[BTRFS_UUID_SIZE];
 434} __attribute__ ((__packed__));
 435
 436struct btrfs_stripe {
 437        __le64 devid;
 438        __le64 offset;
 439        __u8 dev_uuid[BTRFS_UUID_SIZE];
 440} __attribute__ ((__packed__));
 441
 442struct btrfs_chunk {
 443        /* size of this chunk in bytes */
 444        __le64 length;
 445
 446        /* objectid of the root referencing this chunk */
 447        __le64 owner;
 448
 449        __le64 stripe_len;
 450        __le64 type;
 451
 452        /* optimal io alignment for this chunk */
 453        __le32 io_align;
 454
 455        /* optimal io width for this chunk */
 456        __le32 io_width;
 457
 458        /* minimal io size for this chunk */
 459        __le32 sector_size;
 460
 461        /* 2^16 stripes is quite a lot, a second limit is the size of a single
 462         * item in the btree
 463         */
 464        __le16 num_stripes;
 465
 466        /* sub stripes only matter for raid10 */
 467        __le16 sub_stripes;
 468        struct btrfs_stripe stripe;
 469        /* additional stripes go here */
 470} __attribute__ ((__packed__));
 471
 472#define BTRFS_FREE_SPACE_EXTENT 1
 473#define BTRFS_FREE_SPACE_BITMAP 2
 474
 475struct btrfs_free_space_entry {
 476        __le64 offset;
 477        __le64 bytes;
 478        __u8 type;
 479} __attribute__ ((__packed__));
 480
 481struct btrfs_free_space_header {
 482        struct btrfs_disk_key location;
 483        __le64 generation;
 484        __le64 num_entries;
 485        __le64 num_bitmaps;
 486} __attribute__ ((__packed__));
 487
 488#define BTRFS_HEADER_FLAG_WRITTEN       (1ULL << 0)
 489#define BTRFS_HEADER_FLAG_RELOC         (1ULL << 1)
 490
 491/* Super block flags */
 492/* Errors detected */
 493#define BTRFS_SUPER_FLAG_ERROR          (1ULL << 2)
 494
 495#define BTRFS_SUPER_FLAG_SEEDING        (1ULL << 32)
 496#define BTRFS_SUPER_FLAG_METADUMP       (1ULL << 33)
 497#define BTRFS_SUPER_FLAG_METADUMP_V2    (1ULL << 34)
 498#define BTRFS_SUPER_FLAG_CHANGING_FSID  (1ULL << 35)
 499#define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
 500
 501
 502/*
 503 * items in the extent btree are used to record the objectid of the
 504 * owner of the block and the number of references
 505 */
 506
 507struct btrfs_extent_item {
 508        __le64 refs;
 509        __le64 generation;
 510        __le64 flags;
 511} __attribute__ ((__packed__));
 512
 513struct btrfs_extent_item_v0 {
 514        __le32 refs;
 515} __attribute__ ((__packed__));
 516
 517
 518#define BTRFS_EXTENT_FLAG_DATA          (1ULL << 0)
 519#define BTRFS_EXTENT_FLAG_TREE_BLOCK    (1ULL << 1)
 520
 521/* following flags only apply to tree blocks */
 522
 523/* use full backrefs for extent pointers in the block */
 524#define BTRFS_BLOCK_FLAG_FULL_BACKREF   (1ULL << 8)
 525
 526/*
 527 * this flag is only used internally by scrub and may be changed at any time
 528 * it is only declared here to avoid collisions
 529 */
 530#define BTRFS_EXTENT_FLAG_SUPER         (1ULL << 48)
 531
 532struct btrfs_tree_block_info {
 533        struct btrfs_disk_key key;
 534        __u8 level;
 535} __attribute__ ((__packed__));
 536
 537struct btrfs_extent_data_ref {
 538        __le64 root;
 539        __le64 objectid;
 540        __le64 offset;
 541        __le32 count;
 542} __attribute__ ((__packed__));
 543
 544struct btrfs_shared_data_ref {
 545        __le32 count;
 546} __attribute__ ((__packed__));
 547
 548struct btrfs_extent_inline_ref {
 549        __u8 type;
 550        __le64 offset;
 551} __attribute__ ((__packed__));
 552
 553/* dev extents record free space on individual devices.  The owner
 554 * field points back to the chunk allocation mapping tree that allocated
 555 * the extent.  The chunk tree uuid field is a way to double check the owner
 556 */
 557struct btrfs_dev_extent {
 558        __le64 chunk_tree;
 559        __le64 chunk_objectid;
 560        __le64 chunk_offset;
 561        __le64 length;
 562        __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
 563} __attribute__ ((__packed__));
 564
 565struct btrfs_inode_ref {
 566        __le64 index;
 567        __le16 name_len;
 568        /* name goes here */
 569} __attribute__ ((__packed__));
 570
 571struct btrfs_inode_extref {
 572        __le64 parent_objectid;
 573        __le64 index;
 574        __le16 name_len;
 575        __u8   name[0];
 576        /* name goes here */
 577} __attribute__ ((__packed__));
 578
 579struct btrfs_timespec {
 580        __le64 sec;
 581        __le32 nsec;
 582} __attribute__ ((__packed__));
 583
 584struct btrfs_inode_item {
 585        /* nfs style generation number */
 586        __le64 generation;
 587        /* transid that last touched this inode */
 588        __le64 transid;
 589        __le64 size;
 590        __le64 nbytes;
 591        __le64 block_group;
 592        __le32 nlink;
 593        __le32 uid;
 594        __le32 gid;
 595        __le32 mode;
 596        __le64 rdev;
 597        __le64 flags;
 598
 599        /* modification sequence number for NFS */
 600        __le64 sequence;
 601
 602        /*
 603         * a little future expansion, for more than this we can
 604         * just grow the inode item and version it
 605         */
 606        __le64 reserved[4];
 607        struct btrfs_timespec atime;
 608        struct btrfs_timespec ctime;
 609        struct btrfs_timespec mtime;
 610        struct btrfs_timespec otime;
 611} __attribute__ ((__packed__));
 612
 613struct btrfs_dir_log_item {
 614        __le64 end;
 615} __attribute__ ((__packed__));
 616
 617struct btrfs_dir_item {
 618        struct btrfs_disk_key location;
 619        __le64 transid;
 620        __le16 data_len;
 621        __le16 name_len;
 622        __u8 type;
 623} __attribute__ ((__packed__));
 624
 625#define BTRFS_ROOT_SUBVOL_RDONLY        (1ULL << 0)
 626
 627/*
 628 * Internal in-memory flag that a subvolume has been marked for deletion but
 629 * still visible as a directory
 630 */
 631#define BTRFS_ROOT_SUBVOL_DEAD          (1ULL << 48)
 632
 633struct btrfs_root_item {
 634        struct btrfs_inode_item inode;
 635        __le64 generation;
 636        __le64 root_dirid;
 637        __le64 bytenr;
 638        __le64 byte_limit;
 639        __le64 bytes_used;
 640        __le64 last_snapshot;
 641        __le64 flags;
 642        __le32 refs;
 643        struct btrfs_disk_key drop_progress;
 644        __u8 drop_level;
 645        __u8 level;
 646
 647        /*
 648         * The following fields appear after subvol_uuids+subvol_times
 649         * were introduced.
 650         */
 651
 652        /*
 653         * This generation number is used to test if the new fields are valid
 654         * and up to date while reading the root item. Every time the root item
 655         * is written out, the "generation" field is copied into this field. If
 656         * anyone ever mounted the fs with an older kernel, we will have
 657         * mismatching generation values here and thus must invalidate the
 658         * new fields. See btrfs_update_root and btrfs_find_last_root for
 659         * details.
 660         * the offset of generation_v2 is also used as the start for the memset
 661         * when invalidating the fields.
 662         */
 663        __le64 generation_v2;
 664        __u8 uuid[BTRFS_UUID_SIZE];
 665        __u8 parent_uuid[BTRFS_UUID_SIZE];
 666        __u8 received_uuid[BTRFS_UUID_SIZE];
 667        __le64 ctransid; /* updated when an inode changes */
 668        __le64 otransid; /* trans when created */
 669        __le64 stransid; /* trans when sent. non-zero for received subvol */
 670        __le64 rtransid; /* trans when received. non-zero for received subvol */
 671        struct btrfs_timespec ctime;
 672        struct btrfs_timespec otime;
 673        struct btrfs_timespec stime;
 674        struct btrfs_timespec rtime;
 675        __le64 reserved[8]; /* for future */
 676} __attribute__ ((__packed__));
 677
 678/*
 679 * Btrfs root item used to be smaller than current size.  The old format ends
 680 * at where member generation_v2 is.
 681 */
 682static inline __u32 btrfs_legacy_root_item_size(void)
 683{
 684        return offsetof(struct btrfs_root_item, generation_v2);
 685}
 686
 687/*
 688 * this is used for both forward and backward root refs
 689 */
 690struct btrfs_root_ref {
 691        __le64 dirid;
 692        __le64 sequence;
 693        __le16 name_len;
 694} __attribute__ ((__packed__));
 695
 696struct btrfs_disk_balance_args {
 697        /*
 698         * profiles to operate on, single is denoted by
 699         * BTRFS_AVAIL_ALLOC_BIT_SINGLE
 700         */
 701        __le64 profiles;
 702
 703        /*
 704         * usage filter
 705         * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
 706         * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
 707         */
 708        union {
 709                __le64 usage;
 710                struct {
 711                        __le32 usage_min;
 712                        __le32 usage_max;
 713                };
 714        };
 715
 716        /* devid filter */
 717        __le64 devid;
 718
 719        /* devid subset filter [pstart..pend) */
 720        __le64 pstart;
 721        __le64 pend;
 722
 723        /* btrfs virtual address space subset filter [vstart..vend) */
 724        __le64 vstart;
 725        __le64 vend;
 726
 727        /*
 728         * profile to convert to, single is denoted by
 729         * BTRFS_AVAIL_ALLOC_BIT_SINGLE
 730         */
 731        __le64 target;
 732
 733        /* BTRFS_BALANCE_ARGS_* */
 734        __le64 flags;
 735
 736        /*
 737         * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
 738         * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
 739         * and maximum
 740         */
 741        union {
 742                __le64 limit;
 743                struct {
 744                        __le32 limit_min;
 745                        __le32 limit_max;
 746                };
 747        };
 748
 749        /*
 750         * Process chunks that cross stripes_min..stripes_max devices,
 751         * BTRFS_BALANCE_ARGS_STRIPES_RANGE
 752         */
 753        __le32 stripes_min;
 754        __le32 stripes_max;
 755
 756        __le64 unused[6];
 757} __attribute__ ((__packed__));
 758
 759/*
 760 * store balance parameters to disk so that balance can be properly
 761 * resumed after crash or unmount
 762 */
 763struct btrfs_balance_item {
 764        /* BTRFS_BALANCE_* */
 765        __le64 flags;
 766
 767        struct btrfs_disk_balance_args data;
 768        struct btrfs_disk_balance_args meta;
 769        struct btrfs_disk_balance_args sys;
 770
 771        __le64 unused[4];
 772} __attribute__ ((__packed__));
 773
 774enum {
 775        BTRFS_FILE_EXTENT_INLINE   = 0,
 776        BTRFS_FILE_EXTENT_REG      = 1,
 777        BTRFS_FILE_EXTENT_PREALLOC = 2,
 778        BTRFS_NR_FILE_EXTENT_TYPES = 3,
 779};
 780
 781struct btrfs_file_extent_item {
 782        /*
 783         * transaction id that created this extent
 784         */
 785        __le64 generation;
 786        /*
 787         * max number of bytes to hold this extent in ram
 788         * when we split a compressed extent we can't know how big
 789         * each of the resulting pieces will be.  So, this is
 790         * an upper limit on the size of the extent in ram instead of
 791         * an exact limit.
 792         */
 793        __le64 ram_bytes;
 794
 795        /*
 796         * 32 bits for the various ways we might encode the data,
 797         * including compression and encryption.  If any of these
 798         * are set to something a given disk format doesn't understand
 799         * it is treated like an incompat flag for reading and writing,
 800         * but not for stat.
 801         */
 802        __u8 compression;
 803        __u8 encryption;
 804        __le16 other_encoding; /* spare for later use */
 805
 806        /* are we inline data or a real extent? */
 807        __u8 type;
 808
 809        /*
 810         * disk space consumed by the extent, checksum blocks are included
 811         * in these numbers
 812         *
 813         * At this offset in the structure, the inline extent data start.
 814         */
 815        __le64 disk_bytenr;
 816        __le64 disk_num_bytes;
 817        /*
 818         * the logical offset in file blocks (no csums)
 819         * this extent record is for.  This allows a file extent to point
 820         * into the middle of an existing extent on disk, sharing it
 821         * between two snapshots (useful if some bytes in the middle of the
 822         * extent have changed
 823         */
 824        __le64 offset;
 825        /*
 826         * the logical number of file blocks (no csums included).  This
 827         * always reflects the size uncompressed and without encoding.
 828         */
 829        __le64 num_bytes;
 830
 831} __attribute__ ((__packed__));
 832
 833struct btrfs_csum_item {
 834        __u8 csum;
 835} __attribute__ ((__packed__));
 836
 837struct btrfs_dev_stats_item {
 838        /*
 839         * grow this item struct at the end for future enhancements and keep
 840         * the existing values unchanged
 841         */
 842        __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
 843} __attribute__ ((__packed__));
 844
 845#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS     0
 846#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID      1
 847
 848struct btrfs_dev_replace_item {
 849        /*
 850         * grow this item struct at the end for future enhancements and keep
 851         * the existing values unchanged
 852         */
 853        __le64 src_devid;
 854        __le64 cursor_left;
 855        __le64 cursor_right;
 856        __le64 cont_reading_from_srcdev_mode;
 857
 858        __le64 replace_state;
 859        __le64 time_started;
 860        __le64 time_stopped;
 861        __le64 num_write_errors;
 862        __le64 num_uncorrectable_read_errors;
 863} __attribute__ ((__packed__));
 864
 865/* different types of block groups (and chunks) */
 866#define BTRFS_BLOCK_GROUP_DATA          (1ULL << 0)
 867#define BTRFS_BLOCK_GROUP_SYSTEM        (1ULL << 1)
 868#define BTRFS_BLOCK_GROUP_METADATA      (1ULL << 2)
 869#define BTRFS_BLOCK_GROUP_RAID0         (1ULL << 3)
 870#define BTRFS_BLOCK_GROUP_RAID1         (1ULL << 4)
 871#define BTRFS_BLOCK_GROUP_DUP           (1ULL << 5)
 872#define BTRFS_BLOCK_GROUP_RAID10        (1ULL << 6)
 873#define BTRFS_BLOCK_GROUP_RAID5         (1ULL << 7)
 874#define BTRFS_BLOCK_GROUP_RAID6         (1ULL << 8)
 875#define BTRFS_BLOCK_GROUP_RAID1C3       (1ULL << 9)
 876#define BTRFS_BLOCK_GROUP_RAID1C4       (1ULL << 10)
 877#define BTRFS_BLOCK_GROUP_RESERVED      (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
 878                                         BTRFS_SPACE_INFO_GLOBAL_RSV)
 879
 880enum btrfs_raid_types {
 881        BTRFS_RAID_RAID10,
 882        BTRFS_RAID_RAID1,
 883        BTRFS_RAID_DUP,
 884        BTRFS_RAID_RAID0,
 885        BTRFS_RAID_SINGLE,
 886        BTRFS_RAID_RAID5,
 887        BTRFS_RAID_RAID6,
 888        BTRFS_RAID_RAID1C3,
 889        BTRFS_RAID_RAID1C4,
 890        BTRFS_NR_RAID_TYPES
 891};
 892
 893#define BTRFS_BLOCK_GROUP_TYPE_MASK     (BTRFS_BLOCK_GROUP_DATA |    \
 894                                         BTRFS_BLOCK_GROUP_SYSTEM |  \
 895                                         BTRFS_BLOCK_GROUP_METADATA)
 896
 897#define BTRFS_BLOCK_GROUP_PROFILE_MASK  (BTRFS_BLOCK_GROUP_RAID0 |   \
 898                                         BTRFS_BLOCK_GROUP_RAID1 |   \
 899                                         BTRFS_BLOCK_GROUP_RAID1C3 | \
 900                                         BTRFS_BLOCK_GROUP_RAID1C4 | \
 901                                         BTRFS_BLOCK_GROUP_RAID5 |   \
 902                                         BTRFS_BLOCK_GROUP_RAID6 |   \
 903                                         BTRFS_BLOCK_GROUP_DUP |     \
 904                                         BTRFS_BLOCK_GROUP_RAID10)
 905#define BTRFS_BLOCK_GROUP_RAID56_MASK   (BTRFS_BLOCK_GROUP_RAID5 |   \
 906                                         BTRFS_BLOCK_GROUP_RAID6)
 907
 908#define BTRFS_BLOCK_GROUP_RAID1_MASK    (BTRFS_BLOCK_GROUP_RAID1 |   \
 909                                         BTRFS_BLOCK_GROUP_RAID1C3 | \
 910                                         BTRFS_BLOCK_GROUP_RAID1C4)
 911
 912/*
 913 * We need a bit for restriper to be able to tell when chunks of type
 914 * SINGLE are available.  This "extended" profile format is used in
 915 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
 916 * (on-disk).  The corresponding on-disk bit in chunk.type is reserved
 917 * to avoid remappings between two formats in future.
 918 */
 919#define BTRFS_AVAIL_ALLOC_BIT_SINGLE    (1ULL << 48)
 920
 921/*
 922 * A fake block group type that is used to communicate global block reserve
 923 * size to userspace via the SPACE_INFO ioctl.
 924 */
 925#define BTRFS_SPACE_INFO_GLOBAL_RSV     (1ULL << 49)
 926
 927#define BTRFS_EXTENDED_PROFILE_MASK     (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
 928                                         BTRFS_AVAIL_ALLOC_BIT_SINGLE)
 929
 930static inline __u64 chunk_to_extended(__u64 flags)
 931{
 932        if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
 933                flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
 934
 935        return flags;
 936}
 937static inline __u64 extended_to_chunk(__u64 flags)
 938{
 939        return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
 940}
 941
 942struct btrfs_block_group_item {
 943        __le64 used;
 944        __le64 chunk_objectid;
 945        __le64 flags;
 946} __attribute__ ((__packed__));
 947
 948struct btrfs_free_space_info {
 949        __le32 extent_count;
 950        __le32 flags;
 951} __attribute__ ((__packed__));
 952
 953#define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
 954
 955#define BTRFS_QGROUP_LEVEL_SHIFT                48
 956static inline __u16 btrfs_qgroup_level(__u64 qgroupid)
 957{
 958        return (__u16)(qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT);
 959}
 960
 961/*
 962 * is subvolume quota turned on?
 963 */
 964#define BTRFS_QGROUP_STATUS_FLAG_ON             (1ULL << 0)
 965/*
 966 * RESCAN is set during the initialization phase
 967 */
 968#define BTRFS_QGROUP_STATUS_FLAG_RESCAN         (1ULL << 1)
 969/*
 970 * Some qgroup entries are known to be out of date,
 971 * either because the configuration has changed in a way that
 972 * makes a rescan necessary, or because the fs has been mounted
 973 * with a non-qgroup-aware version.
 974 * Turning qouta off and on again makes it inconsistent, too.
 975 */
 976#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT   (1ULL << 2)
 977
 978#define BTRFS_QGROUP_STATUS_VERSION        1
 979
 980struct btrfs_qgroup_status_item {
 981        __le64 version;
 982        /*
 983         * the generation is updated during every commit. As older
 984         * versions of btrfs are not aware of qgroups, it will be
 985         * possible to detect inconsistencies by checking the
 986         * generation on mount time
 987         */
 988        __le64 generation;
 989
 990        /* flag definitions see above */
 991        __le64 flags;
 992
 993        /*
 994         * only used during scanning to record the progress
 995         * of the scan. It contains a logical address
 996         */
 997        __le64 rescan;
 998} __attribute__ ((__packed__));
 999
1000struct btrfs_qgroup_info_item {
1001        __le64 generation;
1002        __le64 rfer;
1003        __le64 rfer_cmpr;
1004        __le64 excl;
1005        __le64 excl_cmpr;
1006} __attribute__ ((__packed__));
1007
1008struct btrfs_qgroup_limit_item {
1009        /*
1010         * only updated when any of the other values change
1011         */
1012        __le64 flags;
1013        __le64 max_rfer;
1014        __le64 max_excl;
1015        __le64 rsv_rfer;
1016        __le64 rsv_excl;
1017} __attribute__ ((__packed__));
1018
1019struct btrfs_verity_descriptor_item {
1020        /* Size of the verity descriptor in bytes */
1021        __le64 size;
1022        /*
1023         * When we implement support for fscrypt, we will need to encrypt the
1024         * Merkle tree for encrypted verity files. These 128 bits are for the
1025         * eventual storage of an fscrypt initialization vector.
1026         */
1027        __le64 reserved[2];
1028        __u8 encryption;
1029} __attribute__ ((__packed__));
1030
1031#endif /* _BTRFS_CTREE_H_ */
1032