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