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