Marek BehĂșn | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 1 | /* |
| 2 | * From linux/include/uapi/linux/btrfs_tree.h |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #ifndef __BTRFS_BTRFS_TREE_H__ |
| 8 | #define __BTRFS_BTRFS_TREE_H__ |
| 9 | |
| 10 | #include <common.h> |
| 11 | |
| 12 | #define BTRFS_VOL_NAME_MAX 255 |
| 13 | #define BTRFS_NAME_MAX 255 |
| 14 | #define BTRFS_LABEL_SIZE 256 |
| 15 | #define BTRFS_FSID_SIZE 16 |
| 16 | #define BTRFS_UUID_SIZE 16 |
| 17 | |
| 18 | /* |
| 19 | * This header contains the structure definitions and constants used |
| 20 | * by file system objects that can be retrieved using |
| 21 | * the BTRFS_IOC_SEARCH_TREE ioctl. That means basically anything that |
| 22 | * is needed to describe a leaf node's key or item contents. |
| 23 | */ |
| 24 | |
| 25 | /* holds pointers to all of the tree roots */ |
| 26 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL |
| 27 | |
| 28 | /* stores information about which extents are in use, and reference counts */ |
| 29 | #define BTRFS_EXTENT_TREE_OBJECTID 2ULL |
| 30 | |
| 31 | /* |
| 32 | * chunk tree stores translations from logical -> physical block numbering |
| 33 | * the super block points to the chunk tree |
| 34 | */ |
| 35 | #define BTRFS_CHUNK_TREE_OBJECTID 3ULL |
| 36 | |
| 37 | /* |
| 38 | * stores information about which areas of a given device are in use. |
| 39 | * one per device. The tree of tree roots points to the device tree |
| 40 | */ |
| 41 | #define BTRFS_DEV_TREE_OBJECTID 4ULL |
| 42 | |
| 43 | /* one per subvolume, storing files and directories */ |
| 44 | #define BTRFS_FS_TREE_OBJECTID 5ULL |
| 45 | |
| 46 | /* directory objectid inside the root tree */ |
| 47 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL |
| 48 | |
| 49 | /* holds checksums of all the data extents */ |
| 50 | #define BTRFS_CSUM_TREE_OBJECTID 7ULL |
| 51 | |
| 52 | /* holds quota configuration and tracking */ |
| 53 | #define BTRFS_QUOTA_TREE_OBJECTID 8ULL |
| 54 | |
| 55 | /* for storing items that use the BTRFS_UUID_KEY* types */ |
| 56 | #define BTRFS_UUID_TREE_OBJECTID 9ULL |
| 57 | |
| 58 | /* tracks free space in block groups. */ |
| 59 | #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL |
| 60 | |
| 61 | /* device stats in the device tree */ |
| 62 | #define BTRFS_DEV_STATS_OBJECTID 0ULL |
| 63 | |
| 64 | /* for storing balance parameters in the root tree */ |
| 65 | #define BTRFS_BALANCE_OBJECTID -4ULL |
| 66 | |
| 67 | /* orhpan objectid for tracking unlinked/truncated files */ |
| 68 | #define BTRFS_ORPHAN_OBJECTID -5ULL |
| 69 | |
| 70 | /* does write ahead logging to speed up fsyncs */ |
| 71 | #define BTRFS_TREE_LOG_OBJECTID -6ULL |
| 72 | #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL |
| 73 | |
| 74 | /* for space balancing */ |
| 75 | #define BTRFS_TREE_RELOC_OBJECTID -8ULL |
| 76 | #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL |
| 77 | |
| 78 | /* |
| 79 | * extent checksums all have this objectid |
| 80 | * this allows them to share the logging tree |
| 81 | * for fsyncs |
| 82 | */ |
| 83 | #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL |
| 84 | |
| 85 | /* For storing free space cache */ |
| 86 | #define BTRFS_FREE_SPACE_OBJECTID -11ULL |
| 87 | |
| 88 | /* |
| 89 | * The inode number assigned to the special inode for storing |
| 90 | * free ino cache |
| 91 | */ |
| 92 | #define BTRFS_FREE_INO_OBJECTID -12ULL |
| 93 | |
| 94 | /* dummy objectid represents multiple objectids */ |
| 95 | #define BTRFS_MULTIPLE_OBJECTIDS -255ULL |
| 96 | |
| 97 | /* |
| 98 | * All files have objectids in this range. |
| 99 | */ |
| 100 | #define BTRFS_FIRST_FREE_OBJECTID 256ULL |
| 101 | #define BTRFS_LAST_FREE_OBJECTID -256ULL |
| 102 | #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL |
| 103 | |
| 104 | |
| 105 | /* |
| 106 | * the device items go into the chunk tree. The key is in the form |
| 107 | * [ 1 BTRFS_DEV_ITEM_KEY device_id ] |
| 108 | */ |
| 109 | #define BTRFS_DEV_ITEMS_OBJECTID 1ULL |
| 110 | |
| 111 | #define BTRFS_BTREE_INODE_OBJECTID 1 |
| 112 | |
| 113 | #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2 |
| 114 | |
| 115 | #define BTRFS_DEV_REPLACE_DEVID 0ULL |
| 116 | |
| 117 | /* |
| 118 | * inode items have the data typically returned from stat and store other |
| 119 | * info about object characteristics. There is one for every file and dir in |
| 120 | * the FS |
| 121 | */ |
| 122 | #define BTRFS_INODE_ITEM_KEY 1 |
| 123 | #define BTRFS_INODE_REF_KEY 12 |
| 124 | #define BTRFS_INODE_EXTREF_KEY 13 |
| 125 | #define BTRFS_XATTR_ITEM_KEY 24 |
| 126 | #define BTRFS_ORPHAN_ITEM_KEY 48 |
| 127 | /* reserve 2-15 close to the inode for later flexibility */ |
| 128 | |
| 129 | /* |
| 130 | * dir items are the name -> inode pointers in a directory. There is one |
| 131 | * for every name in a directory. |
| 132 | */ |
| 133 | #define BTRFS_DIR_LOG_ITEM_KEY 60 |
| 134 | #define BTRFS_DIR_LOG_INDEX_KEY 72 |
| 135 | #define BTRFS_DIR_ITEM_KEY 84 |
| 136 | #define BTRFS_DIR_INDEX_KEY 96 |
| 137 | /* |
| 138 | * extent data is for file data |
| 139 | */ |
| 140 | #define BTRFS_EXTENT_DATA_KEY 108 |
| 141 | |
| 142 | /* |
| 143 | * extent csums are stored in a separate tree and hold csums for |
| 144 | * an entire extent on disk. |
| 145 | */ |
| 146 | #define BTRFS_EXTENT_CSUM_KEY 128 |
| 147 | |
| 148 | /* |
| 149 | * root items point to tree roots. They are typically in the root |
| 150 | * tree used by the super block to find all the other trees |
| 151 | */ |
| 152 | #define BTRFS_ROOT_ITEM_KEY 132 |
| 153 | |
| 154 | /* |
| 155 | * root backrefs tie subvols and snapshots to the directory entries that |
| 156 | * reference them |
| 157 | */ |
| 158 | #define BTRFS_ROOT_BACKREF_KEY 144 |
| 159 | |
| 160 | /* |
| 161 | * root refs make a fast index for listing all of the snapshots and |
| 162 | * subvolumes referenced by a given root. They point directly to the |
| 163 | * directory item in the root that references the subvol |
| 164 | */ |
| 165 | #define BTRFS_ROOT_REF_KEY 156 |
| 166 | |
| 167 | /* |
| 168 | * extent items are in the extent map tree. These record which blocks |
| 169 | * are used, and how many references there are to each block |
| 170 | */ |
| 171 | #define BTRFS_EXTENT_ITEM_KEY 168 |
| 172 | |
| 173 | /* |
| 174 | * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know |
| 175 | * the length, so we save the level in key->offset instead of the length. |
| 176 | */ |
| 177 | #define BTRFS_METADATA_ITEM_KEY 169 |
| 178 | |
| 179 | #define BTRFS_TREE_BLOCK_REF_KEY 176 |
| 180 | |
| 181 | #define BTRFS_EXTENT_DATA_REF_KEY 178 |
| 182 | |
| 183 | #define BTRFS_EXTENT_REF_V0_KEY 180 |
| 184 | |
| 185 | #define BTRFS_SHARED_BLOCK_REF_KEY 182 |
| 186 | |
| 187 | #define BTRFS_SHARED_DATA_REF_KEY 184 |
| 188 | |
| 189 | /* |
| 190 | * block groups give us hints into the extent allocation trees. Which |
| 191 | * blocks are free etc etc |
| 192 | */ |
| 193 | #define BTRFS_BLOCK_GROUP_ITEM_KEY 192 |
| 194 | |
| 195 | /* |
| 196 | * Every block group is represented in the free space tree by a free space info |
| 197 | * item, which stores some accounting information. It is keyed on |
| 198 | * (block_group_start, FREE_SPACE_INFO, block_group_length). |
| 199 | */ |
| 200 | #define BTRFS_FREE_SPACE_INFO_KEY 198 |
| 201 | |
| 202 | /* |
| 203 | * A free space extent tracks an extent of space that is free in a block group. |
| 204 | * It is keyed on (start, FREE_SPACE_EXTENT, length). |
| 205 | */ |
| 206 | #define BTRFS_FREE_SPACE_EXTENT_KEY 199 |
| 207 | |
| 208 | /* |
| 209 | * When a block group becomes very fragmented, we convert it to use bitmaps |
| 210 | * instead of extents. A free space bitmap is keyed on |
| 211 | * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with |
| 212 | * (length / sectorsize) bits. |
| 213 | */ |
| 214 | #define BTRFS_FREE_SPACE_BITMAP_KEY 200 |
| 215 | |
| 216 | #define BTRFS_DEV_EXTENT_KEY 204 |
| 217 | #define BTRFS_DEV_ITEM_KEY 216 |
| 218 | #define BTRFS_CHUNK_ITEM_KEY 228 |
| 219 | |
| 220 | /* |
| 221 | * Records the overall state of the qgroups. |
| 222 | * There's only one instance of this key present, |
| 223 | * (0, BTRFS_QGROUP_STATUS_KEY, 0) |
| 224 | */ |
| 225 | #define BTRFS_QGROUP_STATUS_KEY 240 |
| 226 | /* |
| 227 | * Records the currently used space of the qgroup. |
| 228 | * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid). |
| 229 | */ |
| 230 | #define BTRFS_QGROUP_INFO_KEY 242 |
| 231 | /* |
| 232 | * Contains the user configured limits for the qgroup. |
| 233 | * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid). |
| 234 | */ |
| 235 | #define BTRFS_QGROUP_LIMIT_KEY 244 |
| 236 | /* |
| 237 | * Records the child-parent relationship of qgroups. For |
| 238 | * each relation, 2 keys are present: |
| 239 | * (childid, BTRFS_QGROUP_RELATION_KEY, parentid) |
| 240 | * (parentid, BTRFS_QGROUP_RELATION_KEY, childid) |
| 241 | */ |
| 242 | #define BTRFS_QGROUP_RELATION_KEY 246 |
| 243 | |
| 244 | /* |
| 245 | * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. |
| 246 | */ |
| 247 | #define BTRFS_BALANCE_ITEM_KEY 248 |
| 248 | |
| 249 | /* |
| 250 | * The key type for tree items that are stored persistently, but do not need to |
| 251 | * exist for extended period of time. The items can exist in any tree. |
| 252 | * |
| 253 | * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data] |
| 254 | * |
| 255 | * Existing items: |
| 256 | * |
| 257 | * - balance status item |
| 258 | * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0) |
| 259 | */ |
| 260 | #define BTRFS_TEMPORARY_ITEM_KEY 248 |
| 261 | |
| 262 | /* |
| 263 | * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY |
| 264 | */ |
| 265 | #define BTRFS_DEV_STATS_KEY 249 |
| 266 | |
| 267 | /* |
| 268 | * The key type for tree items that are stored persistently and usually exist |
| 269 | * for a long period, eg. filesystem lifetime. The item kinds can be status |
| 270 | * information, stats or preference values. The item can exist in any tree. |
| 271 | * |
| 272 | * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data] |
| 273 | * |
| 274 | * Existing items: |
| 275 | * |
| 276 | * - device statistics, store IO stats in the device tree, one key for all |
| 277 | * stats |
| 278 | * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0) |
| 279 | */ |
| 280 | #define BTRFS_PERSISTENT_ITEM_KEY 249 |
| 281 | |
| 282 | /* |
| 283 | * Persistantly stores the device replace state in the device tree. |
| 284 | * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0). |
| 285 | */ |
| 286 | #define BTRFS_DEV_REPLACE_KEY 250 |
| 287 | |
| 288 | /* |
| 289 | * Stores items that allow to quickly map UUIDs to something else. |
| 290 | * These items are part of the filesystem UUID tree. |
| 291 | * The key is built like this: |
| 292 | * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits). |
| 293 | */ |
| 294 | #if BTRFS_UUID_SIZE != 16 |
| 295 | #error "UUID items require BTRFS_UUID_SIZE == 16!" |
| 296 | #endif |
| 297 | #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */ |
| 298 | #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to |
| 299 | * received subvols */ |
| 300 | |
| 301 | /* |
| 302 | * string items are for debugging. They just store a short string of |
| 303 | * data in the FS |
| 304 | */ |
| 305 | #define BTRFS_STRING_ITEM_KEY 253 |
| 306 | |
| 307 | |
| 308 | |
| 309 | /* 32 bytes in various csum fields */ |
| 310 | #define BTRFS_CSUM_SIZE 32 |
| 311 | |
| 312 | /* csum types */ |
| 313 | #define BTRFS_CSUM_TYPE_CRC32 0 |
| 314 | |
| 315 | /* |
| 316 | * flags definitions for directory entry item type |
| 317 | * |
| 318 | * Used by: |
| 319 | * struct btrfs_dir_item.type |
| 320 | */ |
| 321 | #define BTRFS_FT_UNKNOWN 0 |
| 322 | #define BTRFS_FT_REG_FILE 1 |
| 323 | #define BTRFS_FT_DIR 2 |
| 324 | #define BTRFS_FT_CHRDEV 3 |
| 325 | #define BTRFS_FT_BLKDEV 4 |
| 326 | #define BTRFS_FT_FIFO 5 |
| 327 | #define BTRFS_FT_SOCK 6 |
| 328 | #define BTRFS_FT_SYMLINK 7 |
| 329 | #define BTRFS_FT_XATTR 8 |
| 330 | #define BTRFS_FT_MAX 9 |
| 331 | |
| 332 | /* |
| 333 | * The key defines the order in the tree, and so it also defines (optimal) |
| 334 | * block layout. |
| 335 | * |
| 336 | * objectid corresponds to the inode number. |
| 337 | * |
| 338 | * type tells us things about the object, and is a kind of stream selector. |
| 339 | * so for a given inode, keys with type of 1 might refer to the inode data, |
| 340 | * type of 2 may point to file data in the btree and type == 3 may point to |
| 341 | * extents. |
| 342 | * |
| 343 | * offset is the starting byte offset for this key in the stream. |
| 344 | */ |
| 345 | |
| 346 | struct btrfs_key { |
| 347 | __u64 objectid; |
| 348 | __u8 type; |
| 349 | __u64 offset; |
| 350 | } __attribute__ ((__packed__)); |
| 351 | |
| 352 | struct btrfs_dev_item { |
| 353 | /* the internal btrfs device id */ |
| 354 | __u64 devid; |
| 355 | |
| 356 | /* size of the device */ |
| 357 | __u64 total_bytes; |
| 358 | |
| 359 | /* bytes used */ |
| 360 | __u64 bytes_used; |
| 361 | |
| 362 | /* optimal io alignment for this device */ |
| 363 | __u32 io_align; |
| 364 | |
| 365 | /* optimal io width for this device */ |
| 366 | __u32 io_width; |
| 367 | |
| 368 | /* minimal io size for this device */ |
| 369 | __u32 sector_size; |
| 370 | |
| 371 | /* type and info about this device */ |
| 372 | __u64 type; |
| 373 | |
| 374 | /* expected generation for this device */ |
| 375 | __u64 generation; |
| 376 | |
| 377 | /* |
| 378 | * starting byte of this partition on the device, |
| 379 | * to allow for stripe alignment in the future |
| 380 | */ |
| 381 | __u64 start_offset; |
| 382 | |
| 383 | /* grouping information for allocation decisions */ |
| 384 | __u32 dev_group; |
| 385 | |
| 386 | /* seek speed 0-100 where 100 is fastest */ |
| 387 | __u8 seek_speed; |
| 388 | |
| 389 | /* bandwidth 0-100 where 100 is fastest */ |
| 390 | __u8 bandwidth; |
| 391 | |
| 392 | /* btrfs generated uuid for this device */ |
| 393 | __u8 uuid[BTRFS_UUID_SIZE]; |
| 394 | |
| 395 | /* uuid of FS who owns this device */ |
| 396 | __u8 fsid[BTRFS_UUID_SIZE]; |
| 397 | } __attribute__ ((__packed__)); |
| 398 | |
| 399 | struct btrfs_stripe { |
| 400 | __u64 devid; |
| 401 | __u64 offset; |
| 402 | __u8 dev_uuid[BTRFS_UUID_SIZE]; |
| 403 | } __attribute__ ((__packed__)); |
| 404 | |
| 405 | struct btrfs_chunk { |
| 406 | /* size of this chunk in bytes */ |
| 407 | __u64 length; |
| 408 | |
| 409 | /* objectid of the root referencing this chunk */ |
| 410 | __u64 owner; |
| 411 | |
| 412 | __u64 stripe_len; |
| 413 | __u64 type; |
| 414 | |
| 415 | /* optimal io alignment for this chunk */ |
| 416 | __u32 io_align; |
| 417 | |
| 418 | /* optimal io width for this chunk */ |
| 419 | __u32 io_width; |
| 420 | |
| 421 | /* minimal io size for this chunk */ |
| 422 | __u32 sector_size; |
| 423 | |
| 424 | /* 2^16 stripes is quite a lot, a second limit is the size of a single |
| 425 | * item in the btree |
| 426 | */ |
| 427 | __u16 num_stripes; |
| 428 | |
| 429 | /* sub stripes only matter for raid10 */ |
| 430 | __u16 sub_stripes; |
| 431 | struct btrfs_stripe stripe; |
| 432 | /* additional stripes go here */ |
| 433 | } __attribute__ ((__packed__)); |
| 434 | |
| 435 | #define BTRFS_FREE_SPACE_EXTENT 1 |
| 436 | #define BTRFS_FREE_SPACE_BITMAP 2 |
| 437 | |
| 438 | struct btrfs_free_space_entry { |
| 439 | __u64 offset; |
| 440 | __u64 bytes; |
| 441 | __u8 type; |
| 442 | } __attribute__ ((__packed__)); |
| 443 | |
| 444 | struct btrfs_free_space_header { |
| 445 | struct btrfs_key location; |
| 446 | __u64 generation; |
| 447 | __u64 num_entries; |
| 448 | __u64 num_bitmaps; |
| 449 | } __attribute__ ((__packed__)); |
| 450 | |
| 451 | #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0) |
| 452 | #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1) |
| 453 | |
| 454 | /* Super block flags */ |
| 455 | /* Errors detected */ |
| 456 | #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2) |
| 457 | |
| 458 | #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32) |
| 459 | #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33) |
| 460 | |
| 461 | |
| 462 | /* |
| 463 | * items in the extent btree are used to record the objectid of the |
| 464 | * owner of the block and the number of references |
| 465 | */ |
| 466 | |
| 467 | struct btrfs_extent_item { |
| 468 | __u64 refs; |
| 469 | __u64 generation; |
| 470 | __u64 flags; |
| 471 | } __attribute__ ((__packed__)); |
| 472 | |
| 473 | |
| 474 | #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0) |
| 475 | #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1) |
| 476 | |
| 477 | /* following flags only apply to tree blocks */ |
| 478 | |
| 479 | /* use full backrefs for extent pointers in the block */ |
| 480 | #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8) |
| 481 | |
| 482 | /* |
| 483 | * this flag is only used internally by scrub and may be changed at any time |
| 484 | * it is only declared here to avoid collisions |
| 485 | */ |
| 486 | #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48) |
| 487 | |
| 488 | struct btrfs_tree_block_info { |
| 489 | struct btrfs_key key; |
| 490 | __u8 level; |
| 491 | } __attribute__ ((__packed__)); |
| 492 | |
| 493 | struct btrfs_extent_data_ref { |
| 494 | __u64 root; |
| 495 | __u64 objectid; |
| 496 | __u64 offset; |
| 497 | __u32 count; |
| 498 | } __attribute__ ((__packed__)); |
| 499 | |
| 500 | struct btrfs_shared_data_ref { |
| 501 | __u32 count; |
| 502 | } __attribute__ ((__packed__)); |
| 503 | |
| 504 | struct btrfs_extent_inline_ref { |
| 505 | __u8 type; |
| 506 | __u64 offset; |
| 507 | } __attribute__ ((__packed__)); |
| 508 | |
| 509 | /* dev extents record free space on individual devices. The owner |
| 510 | * field points back to the chunk allocation mapping tree that allocated |
| 511 | * the extent. The chunk tree uuid field is a way to double check the owner |
| 512 | */ |
| 513 | struct btrfs_dev_extent { |
| 514 | __u64 chunk_tree; |
| 515 | __u64 chunk_objectid; |
| 516 | __u64 chunk_offset; |
| 517 | __u64 length; |
| 518 | __u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; |
| 519 | } __attribute__ ((__packed__)); |
| 520 | |
| 521 | struct btrfs_inode_ref { |
| 522 | __u64 index; |
| 523 | __u16 name_len; |
| 524 | /* name goes here */ |
| 525 | } __attribute__ ((__packed__)); |
| 526 | |
| 527 | struct btrfs_inode_extref { |
| 528 | __u64 parent_objectid; |
| 529 | __u64 index; |
| 530 | __u16 name_len; |
| 531 | __u8 name[0]; |
| 532 | /* name goes here */ |
| 533 | } __attribute__ ((__packed__)); |
| 534 | |
| 535 | struct btrfs_timespec { |
| 536 | __u64 sec; |
| 537 | __u32 nsec; |
| 538 | } __attribute__ ((__packed__)); |
| 539 | |
| 540 | struct btrfs_inode_item { |
| 541 | /* nfs style generation number */ |
| 542 | __u64 generation; |
| 543 | /* transid that last touched this inode */ |
| 544 | __u64 transid; |
| 545 | __u64 size; |
| 546 | __u64 nbytes; |
| 547 | __u64 block_group; |
| 548 | __u32 nlink; |
| 549 | __u32 uid; |
| 550 | __u32 gid; |
| 551 | __u32 mode; |
| 552 | __u64 rdev; |
| 553 | __u64 flags; |
| 554 | |
| 555 | /* modification sequence number for NFS */ |
| 556 | __u64 sequence; |
| 557 | |
| 558 | /* |
| 559 | * a little future expansion, for more than this we can |
| 560 | * just grow the inode item and version it |
| 561 | */ |
| 562 | __u64 reserved[4]; |
| 563 | struct btrfs_timespec atime; |
| 564 | struct btrfs_timespec ctime; |
| 565 | struct btrfs_timespec mtime; |
| 566 | struct btrfs_timespec otime; |
| 567 | } __attribute__ ((__packed__)); |
| 568 | |
| 569 | struct btrfs_dir_log_item { |
| 570 | __u64 end; |
| 571 | } __attribute__ ((__packed__)); |
| 572 | |
| 573 | struct btrfs_dir_item { |
| 574 | struct btrfs_key location; |
| 575 | __u64 transid; |
| 576 | __u16 data_len; |
| 577 | __u16 name_len; |
| 578 | __u8 type; |
| 579 | } __attribute__ ((__packed__)); |
| 580 | |
| 581 | #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0) |
| 582 | |
| 583 | /* |
| 584 | * Internal in-memory flag that a subvolume has been marked for deletion but |
| 585 | * still visible as a directory |
| 586 | */ |
| 587 | #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48) |
| 588 | |
| 589 | struct btrfs_root_item { |
| 590 | struct btrfs_inode_item inode; |
| 591 | __u64 generation; |
| 592 | __u64 root_dirid; |
| 593 | __u64 bytenr; |
| 594 | __u64 byte_limit; |
| 595 | __u64 bytes_used; |
| 596 | __u64 last_snapshot; |
| 597 | __u64 flags; |
| 598 | __u32 refs; |
| 599 | struct btrfs_key drop_progress; |
| 600 | __u8 drop_level; |
| 601 | __u8 level; |
| 602 | |
| 603 | /* |
| 604 | * The following fields appear after subvol_uuids+subvol_times |
| 605 | * were introduced. |
| 606 | */ |
| 607 | |
| 608 | /* |
| 609 | * This generation number is used to test if the new fields are valid |
| 610 | * and up to date while reading the root item. Every time the root item |
| 611 | * is written out, the "generation" field is copied into this field. If |
| 612 | * anyone ever mounted the fs with an older kernel, we will have |
| 613 | * mismatching generation values here and thus must invalidate the |
| 614 | * new fields. See btrfs_update_root and btrfs_find_last_root for |
| 615 | * details. |
| 616 | * the offset of generation_v2 is also used as the start for the memset |
| 617 | * when invalidating the fields. |
| 618 | */ |
| 619 | __u64 generation_v2; |
| 620 | __u8 uuid[BTRFS_UUID_SIZE]; |
| 621 | __u8 parent_uuid[BTRFS_UUID_SIZE]; |
| 622 | __u8 received_uuid[BTRFS_UUID_SIZE]; |
| 623 | __u64 ctransid; /* updated when an inode changes */ |
| 624 | __u64 otransid; /* trans when created */ |
| 625 | __u64 stransid; /* trans when sent. non-zero for received subvol */ |
| 626 | __u64 rtransid; /* trans when received. non-zero for received subvol */ |
| 627 | struct btrfs_timespec ctime; |
| 628 | struct btrfs_timespec otime; |
| 629 | struct btrfs_timespec stime; |
| 630 | struct btrfs_timespec rtime; |
| 631 | __u64 reserved[8]; /* for future */ |
| 632 | } __attribute__ ((__packed__)); |
| 633 | |
| 634 | /* |
| 635 | * this is used for both forward and backward root refs |
| 636 | */ |
| 637 | struct btrfs_root_ref { |
| 638 | __u64 dirid; |
| 639 | __u64 sequence; |
| 640 | __u16 name_len; |
| 641 | } __attribute__ ((__packed__)); |
| 642 | |
| 643 | #define BTRFS_FILE_EXTENT_INLINE 0 |
| 644 | #define BTRFS_FILE_EXTENT_REG 1 |
| 645 | #define BTRFS_FILE_EXTENT_PREALLOC 2 |
| 646 | |
| 647 | enum btrfs_compression_type { |
| 648 | BTRFS_COMPRESS_NONE = 0, |
| 649 | BTRFS_COMPRESS_ZLIB = 1, |
| 650 | BTRFS_COMPRESS_LZO = 2, |
| 651 | BTRFS_COMPRESS_TYPES = 2, |
| 652 | BTRFS_COMPRESS_LAST = 3, |
| 653 | }; |
| 654 | |
| 655 | struct btrfs_file_extent_item { |
| 656 | /* |
| 657 | * transaction id that created this extent |
| 658 | */ |
| 659 | __u64 generation; |
| 660 | /* |
| 661 | * max number of bytes to hold this extent in ram |
| 662 | * when we split a compressed extent we can't know how big |
| 663 | * each of the resulting pieces will be. So, this is |
| 664 | * an upper limit on the size of the extent in ram instead of |
| 665 | * an exact limit. |
| 666 | */ |
| 667 | __u64 ram_bytes; |
| 668 | |
| 669 | /* |
| 670 | * 32 bits for the various ways we might encode the data, |
| 671 | * including compression and encryption. If any of these |
| 672 | * are set to something a given disk format doesn't understand |
| 673 | * it is treated like an incompat flag for reading and writing, |
| 674 | * but not for stat. |
| 675 | */ |
| 676 | __u8 compression; |
| 677 | __u8 encryption; |
| 678 | __u16 other_encoding; /* spare for later use */ |
| 679 | |
| 680 | /* are we inline data or a real extent? */ |
| 681 | __u8 type; |
| 682 | |
| 683 | /* |
| 684 | * disk space consumed by the extent, checksum blocks are included |
| 685 | * in these numbers |
| 686 | * |
| 687 | * At this offset in the structure, the inline extent data start. |
| 688 | */ |
| 689 | __u64 disk_bytenr; |
| 690 | __u64 disk_num_bytes; |
| 691 | /* |
| 692 | * the logical offset in file blocks (no csums) |
| 693 | * this extent record is for. This allows a file extent to point |
| 694 | * into the middle of an existing extent on disk, sharing it |
| 695 | * between two snapshots (useful if some bytes in the middle of the |
| 696 | * extent have changed |
| 697 | */ |
| 698 | __u64 offset; |
| 699 | /* |
| 700 | * the logical number of file blocks (no csums included). This |
| 701 | * always reflects the size uncompressed and without encoding. |
| 702 | */ |
| 703 | __u64 num_bytes; |
| 704 | |
| 705 | } __attribute__ ((__packed__)); |
| 706 | |
| 707 | struct btrfs_csum_item { |
| 708 | __u8 csum; |
| 709 | } __attribute__ ((__packed__)); |
| 710 | |
| 711 | /* different types of block groups (and chunks) */ |
| 712 | #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0) |
| 713 | #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1) |
| 714 | #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2) |
| 715 | #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3) |
| 716 | #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4) |
| 717 | #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5) |
| 718 | #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6) |
| 719 | #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7) |
| 720 | #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8) |
| 721 | #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \ |
| 722 | BTRFS_SPACE_INFO_GLOBAL_RSV) |
| 723 | |
| 724 | enum btrfs_raid_types { |
| 725 | BTRFS_RAID_RAID10, |
| 726 | BTRFS_RAID_RAID1, |
| 727 | BTRFS_RAID_DUP, |
| 728 | BTRFS_RAID_RAID0, |
| 729 | BTRFS_RAID_SINGLE, |
| 730 | BTRFS_RAID_RAID5, |
| 731 | BTRFS_RAID_RAID6, |
| 732 | BTRFS_NR_RAID_TYPES |
| 733 | }; |
| 734 | |
| 735 | #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \ |
| 736 | BTRFS_BLOCK_GROUP_SYSTEM | \ |
| 737 | BTRFS_BLOCK_GROUP_METADATA) |
| 738 | |
| 739 | #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \ |
| 740 | BTRFS_BLOCK_GROUP_RAID1 | \ |
| 741 | BTRFS_BLOCK_GROUP_RAID5 | \ |
| 742 | BTRFS_BLOCK_GROUP_RAID6 | \ |
| 743 | BTRFS_BLOCK_GROUP_DUP | \ |
| 744 | BTRFS_BLOCK_GROUP_RAID10) |
| 745 | #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \ |
| 746 | BTRFS_BLOCK_GROUP_RAID6) |
| 747 | |
| 748 | /* |
| 749 | * We need a bit for restriper to be able to tell when chunks of type |
| 750 | * SINGLE are available. This "extended" profile format is used in |
| 751 | * fs_info->avail_*_alloc_bits (in-memory) and balance item fields |
| 752 | * (on-disk). The corresponding on-disk bit in chunk.type is reserved |
| 753 | * to avoid remappings between two formats in future. |
| 754 | */ |
| 755 | #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48) |
| 756 | |
| 757 | /* |
| 758 | * A fake block group type that is used to communicate global block reserve |
| 759 | * size to userspace via the SPACE_INFO ioctl. |
| 760 | */ |
| 761 | #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49) |
| 762 | |
| 763 | #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \ |
| 764 | BTRFS_AVAIL_ALLOC_BIT_SINGLE) |
| 765 | |
| 766 | #endif /* __BTRFS_BTRFS_TREE_H__ */ |