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