btrfs_tree.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * Copied from kernel/include/uapi/linux/btrfs_btree.h.
  4. *
  5. * Only modified the header.
  6. */
  7. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  8. #ifndef __BTRFS_TREE_H__
  9. #define __BTRFS_TREE_H__
  10. #include <linux/types.h>
  11. #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
  12. /*
  13. * The max metadata block size (node size).
  14. *
  15. * This limit is somewhat artificial. The memmove and tree block locking cost
  16. * go up with larger node size.
  17. */
  18. #define BTRFS_MAX_METADATA_BLOCKSIZE 65536
  19. /*
  20. * We can actually store much bigger names, but lets not confuse the rest
  21. * of linux.
  22. *
  23. * btrfs_dir_item::name_len follows this limitation.
  24. */
  25. #define BTRFS_NAME_LEN 255
  26. /*
  27. * Objectids start from here.
  28. *
  29. * Check btrfs_disk_key for the meaning of objectids.
  30. */
  31. /*
  32. * Root tree holds pointers to all of the tree roots.
  33. * Without special mention, the root tree contains the root bytenr of all other
  34. * trees, except the chunk tree and the log tree.
  35. *
  36. * The super block contains the root bytenr of this tree.
  37. */
  38. #define BTRFS_ROOT_TREE_OBJECTID 1ULL
  39. /*
  40. * Extent tree stores information about which extents are in use, and backrefs
  41. * for each extent.
  42. */
  43. #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
  44. /*
  45. * Chunk tree stores btrfs logical address -> physical address mapping.
  46. *
  47. * The super block contains part of chunk tree for bootstrap, and contains
  48. * the root bytenr of this tree.
  49. */
  50. #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
  51. /*
  52. * Device tree stores info about which areas of a given device are in use,
  53. * and physical address -> btrfs logical address mapping.
  54. */
  55. #define BTRFS_DEV_TREE_OBJECTID 4ULL
  56. /* The fs tree is the first subvolume tree, storing files and directories. */
  57. #define BTRFS_FS_TREE_OBJECTID 5ULL
  58. /* Shows the directory objectid inside the root tree. */
  59. #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
  60. /* Csum tree holds checksums of all the data extents. */
  61. #define BTRFS_CSUM_TREE_OBJECTID 7ULL
  62. /* Quota tree holds quota configuration and tracking. */
  63. #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
  64. /* UUID tree stores items that use the BTRFS_UUID_KEY* types. */
  65. #define BTRFS_UUID_TREE_OBJECTID 9ULL
  66. /* Free space cache tree (v2 space cache) tracks free space in block groups. */
  67. #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
  68. /* Indicates device stats in the device tree. */
  69. #define BTRFS_DEV_STATS_OBJECTID 0ULL
  70. /* For storing balance parameters in the root tree. */
  71. #define BTRFS_BALANCE_OBJECTID -4ULL
  72. /* Orhpan objectid for tracking unlinked/truncated files. */
  73. #define BTRFS_ORPHAN_OBJECTID -5ULL
  74. /* Does write ahead logging to speed up fsyncs. */
  75. #define BTRFS_TREE_LOG_OBJECTID -6ULL
  76. #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
  77. /* For space balancing. */
  78. #define BTRFS_TREE_RELOC_OBJECTID -8ULL
  79. #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
  80. /* Extent checksums, shared between the csum tree and log trees. */
  81. #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
  82. /* For storing free space cache (v1 space cache). */
  83. #define BTRFS_FREE_SPACE_OBJECTID -11ULL
  84. /* The inode number assigned to the special inode for storing free ino cache. */
  85. #define BTRFS_FREE_INO_OBJECTID -12ULL
  86. /* Dummy objectid represents multiple objectids. */
  87. #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
  88. /* All files have objectids in this range. */
  89. #define BTRFS_FIRST_FREE_OBJECTID 256ULL
  90. #define BTRFS_LAST_FREE_OBJECTID -256ULL
  91. #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
  92. /*
  93. * The device items go into the chunk tree.
  94. *
  95. * The key is in the form
  96. * (BTRFS_DEV_ITEMS_OBJECTID, BTRFS_DEV_ITEM_KEY, <device_id>)
  97. */
  98. #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
  99. #define BTRFS_BTREE_INODE_OBJECTID 1
  100. #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
  101. #define BTRFS_DEV_REPLACE_DEVID 0ULL
  102. /*
  103. * Types start from here.
  104. *
  105. * Check btrfs_disk_key for details about types.
  106. */
  107. /*
  108. * Inode items have the data typically returned from stat and store other
  109. * info about object characteristics.
  110. *
  111. * There is one for every file and dir in the FS.
  112. */
  113. #define BTRFS_INODE_ITEM_KEY 1
  114. /* reserve 2-11 close to the inode for later flexibility */
  115. #define BTRFS_INODE_REF_KEY 12
  116. #define BTRFS_INODE_EXTREF_KEY 13
  117. #define BTRFS_XATTR_ITEM_KEY 24
  118. #define BTRFS_ORPHAN_ITEM_KEY 48
  119. /*
  120. * Dir items are the name -> inode pointers in a directory.
  121. *
  122. * There is one for every name in a directory.
  123. */
  124. #define BTRFS_DIR_LOG_ITEM_KEY 60
  125. #define BTRFS_DIR_LOG_INDEX_KEY 72
  126. #define BTRFS_DIR_ITEM_KEY 84
  127. #define BTRFS_DIR_INDEX_KEY 96
  128. /* Stores info (position, size ...) about a data extent of a file */
  129. #define BTRFS_EXTENT_DATA_KEY 108
  130. /*
  131. * Extent csums are stored in a separate tree and hold csums for
  132. * an entire extent on disk.
  133. */
  134. #define BTRFS_EXTENT_CSUM_KEY 128
  135. /*
  136. * Root items point to tree roots.
  137. *
  138. * They are typically in the root tree used by the super block to find all the
  139. * other trees.
  140. */
  141. #define BTRFS_ROOT_ITEM_KEY 132
  142. /*
  143. * Root backrefs tie subvols and snapshots to the directory entries that
  144. * reference them.
  145. */
  146. #define BTRFS_ROOT_BACKREF_KEY 144
  147. /*
  148. * Root refs make a fast index for listing all of the snapshots and
  149. * subvolumes referenced by a given root. They point directly to the
  150. * directory item in the root that references the subvol.
  151. */
  152. #define BTRFS_ROOT_REF_KEY 156
  153. /*
  154. * Extent items are in the extent tree.
  155. *
  156. * These record which blocks are used, and how many references there are.
  157. */
  158. #define BTRFS_EXTENT_ITEM_KEY 168
  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. #define BTRFS_TREE_BLOCK_REF_KEY 176
  165. #define BTRFS_EXTENT_DATA_REF_KEY 178
  166. #define BTRFS_EXTENT_REF_V0_KEY 180
  167. #define BTRFS_SHARED_BLOCK_REF_KEY 182
  168. #define BTRFS_SHARED_DATA_REF_KEY 184
  169. /*
  170. * Block groups give us hints into the extent allocation trees.
  171. *
  172. * Stores how many free space there is in a block group.
  173. */
  174. #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
  175. /*
  176. * Every block group is represented in the free space tree by a free space info
  177. * item, which stores some accounting information. It is keyed on
  178. * (block_group_start, FREE_SPACE_INFO, block_group_length).
  179. */
  180. #define BTRFS_FREE_SPACE_INFO_KEY 198
  181. /*
  182. * A free space extent tracks an extent of space that is free in a block group.
  183. * It is keyed on (start, FREE_SPACE_EXTENT, length).
  184. */
  185. #define BTRFS_FREE_SPACE_EXTENT_KEY 199
  186. /*
  187. * When a block group becomes very fragmented, we convert it to use bitmaps
  188. * instead of extents.
  189. *
  190. * A free space bitmap is keyed on (start, FREE_SPACE_BITMAP, length).
  191. * The corresponding item is a bitmap with (length / sectorsize) bits.
  192. */
  193. #define BTRFS_FREE_SPACE_BITMAP_KEY 200
  194. #define BTRFS_DEV_EXTENT_KEY 204
  195. #define BTRFS_DEV_ITEM_KEY 216
  196. #define BTRFS_CHUNK_ITEM_KEY 228
  197. /*
  198. * Records the overall state of the qgroups.
  199. *
  200. * There's only one instance of this key present,
  201. * (0, BTRFS_QGROUP_STATUS_KEY, 0)
  202. */
  203. #define BTRFS_QGROUP_STATUS_KEY 240
  204. /*
  205. * Records the currently used space of the qgroup.
  206. *
  207. * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
  208. */
  209. #define BTRFS_QGROUP_INFO_KEY 242
  210. /*
  211. * Contains the user configured limits for the qgroup.
  212. *
  213. * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
  214. */
  215. #define BTRFS_QGROUP_LIMIT_KEY 244
  216. /*
  217. * Records the child-parent relationship of qgroups. For
  218. * each relation, 2 keys are present:
  219. * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
  220. * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
  221. */
  222. #define BTRFS_QGROUP_RELATION_KEY 246
  223. /* Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. */
  224. #define BTRFS_BALANCE_ITEM_KEY 248
  225. /*
  226. * The key type for tree items that are stored persistently, but do not need to
  227. * exist for extended period of time. The items can exist in any tree.
  228. *
  229. * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
  230. *
  231. * Existing items:
  232. *
  233. * - balance status item
  234. * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
  235. */
  236. #define BTRFS_TEMPORARY_ITEM_KEY 248
  237. /* Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY */
  238. #define BTRFS_DEV_STATS_KEY 249
  239. /*
  240. * The key type for tree items that are stored persistently and usually exist
  241. * for a long period, eg. filesystem lifetime. The item kinds can be status
  242. * information, stats or preference values. The item can exist in any tree.
  243. *
  244. * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
  245. *
  246. * Existing items:
  247. *
  248. * - device statistics, store IO stats in the device tree, one key for all
  249. * stats
  250. * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
  251. */
  252. #define BTRFS_PERSISTENT_ITEM_KEY 249
  253. /*
  254. * Persistently stores the device replace state in the device tree.
  255. *
  256. * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
  257. */
  258. #define BTRFS_DEV_REPLACE_KEY 250
  259. /*
  260. * Stores items that allow to quickly map UUIDs to something else.
  261. *
  262. * These items are part of the filesystem UUID tree.
  263. * The key is built like this:
  264. * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
  265. */
  266. #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
  267. #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
  268. * received subvols */
  269. /*
  270. * String items are for debugging.
  271. *
  272. * They just store a short string of data in the FS.
  273. */
  274. #define BTRFS_STRING_ITEM_KEY 253
  275. /* 32 bytes in various csum fields */
  276. #define BTRFS_CSUM_SIZE 32
  277. /* Csum types */
  278. enum btrfs_csum_type {
  279. BTRFS_CSUM_TYPE_CRC32 = 0,
  280. BTRFS_CSUM_TYPE_XXHASH = 1,
  281. BTRFS_CSUM_TYPE_SHA256 = 2,
  282. BTRFS_CSUM_TYPE_BLAKE2 = 3,
  283. };
  284. /*
  285. * Flags definitions for directory entry item type.
  286. *
  287. * Used by:
  288. * struct btrfs_dir_item.type
  289. *
  290. * Values 0..7 must match common file type values in fs_types.h.
  291. */
  292. #define BTRFS_FT_UNKNOWN 0
  293. #define BTRFS_FT_REG_FILE 1
  294. #define BTRFS_FT_DIR 2
  295. #define BTRFS_FT_CHRDEV 3
  296. #define BTRFS_FT_BLKDEV 4
  297. #define BTRFS_FT_FIFO 5
  298. #define BTRFS_FT_SOCK 6
  299. #define BTRFS_FT_SYMLINK 7
  300. #define BTRFS_FT_XATTR 8
  301. #define BTRFS_FT_MAX 9
  302. #define BTRFS_FSID_SIZE 16
  303. #define BTRFS_UUID_SIZE 16
  304. /*
  305. * The key defines the order in the tree, and so it also defines (optimal)
  306. * block layout.
  307. *
  308. * Objectid and offset are interpreted based on type.
  309. * While normally for objectid, it either represents a root number, or an
  310. * inode number.
  311. *
  312. * Type tells us things about the object, and is a kind of stream selector.
  313. * Check the following URL for full references about btrfs_disk_key/btrfs_key:
  314. * https://btrfs.wiki.kernel.org/index.php/Btree_Items
  315. *
  316. * btrfs_disk_key is in disk byte order. struct btrfs_key is always
  317. * in cpu native order. Otherwise they are identical and their sizes
  318. * should be the same (ie both packed)
  319. */
  320. struct btrfs_disk_key {
  321. __le64 objectid;
  322. __u8 type;
  323. __le64 offset;
  324. } __attribute__ ((__packed__));
  325. struct btrfs_key {
  326. __u64 objectid;
  327. __u8 type;
  328. __u64 offset;
  329. } __attribute__ ((__packed__));
  330. struct btrfs_dev_item {
  331. /* The internal btrfs device id */
  332. __le64 devid;
  333. /* Size of the device */
  334. __le64 total_bytes;
  335. /* Bytes used */
  336. __le64 bytes_used;
  337. /* Optimal io alignment for this device */
  338. __le32 io_align;
  339. /* Optimal io width for this device */
  340. __le32 io_width;
  341. /* Minimal io size for this device */
  342. __le32 sector_size;
  343. /* Type and info about this device */
  344. __le64 type;
  345. /* Expected generation for this device */
  346. __le64 generation;
  347. /*
  348. * Starting byte of this partition on the device,
  349. * to allow for stripe alignment in the future.
  350. */
  351. __le64 start_offset;
  352. /* Grouping information for allocation decisions */
  353. __le32 dev_group;
  354. /* Optimal seek speed 0-100 where 100 is fastest */
  355. __u8 seek_speed;
  356. /* Optimal bandwidth 0-100 where 100 is fastest */
  357. __u8 bandwidth;
  358. /* Btrfs generated uuid for this device */
  359. __u8 uuid[BTRFS_UUID_SIZE];
  360. /* UUID of FS who owns this device */
  361. __u8 fsid[BTRFS_UUID_SIZE];
  362. } __attribute__ ((__packed__));
  363. struct btrfs_stripe {
  364. __le64 devid;
  365. __le64 offset;
  366. __u8 dev_uuid[BTRFS_UUID_SIZE];
  367. } __attribute__ ((__packed__));
  368. struct btrfs_chunk {
  369. /* Size of this chunk in bytes */
  370. __le64 length;
  371. /* Objectid of the root referencing this chunk */
  372. __le64 owner;
  373. __le64 stripe_len;
  374. __le64 type;
  375. /* Optimal io alignment for this chunk */
  376. __le32 io_align;
  377. /* Optimal io width for this chunk */
  378. __le32 io_width;
  379. /* Minimal io size for this chunk */
  380. __le32 sector_size;
  381. /*
  382. * 2^16 stripes is quite a lot, a second limit is the size of a single
  383. * item in the btree.
  384. */
  385. __le16 num_stripes;
  386. /* Sub stripes only matter for raid10 */
  387. __le16 sub_stripes;
  388. struct btrfs_stripe stripe;
  389. /* additional stripes go here */
  390. } __attribute__ ((__packed__));
  391. #define BTRFS_FREE_SPACE_EXTENT 1
  392. #define BTRFS_FREE_SPACE_BITMAP 2
  393. struct btrfs_free_space_entry {
  394. __le64 offset;
  395. __le64 bytes;
  396. __u8 type;
  397. } __attribute__ ((__packed__));
  398. struct btrfs_free_space_header {
  399. struct btrfs_disk_key location;
  400. __le64 generation;
  401. __le64 num_entries;
  402. __le64 num_bitmaps;
  403. } __attribute__ ((__packed__));
  404. #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
  405. #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
  406. /* Super block flags */
  407. /* Errors detected */
  408. #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
  409. #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
  410. #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
  411. #define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
  412. #define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
  413. #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
  414. /*
  415. * Items in the extent tree are used to record the objectid of the
  416. * owner of the block and the number of references.
  417. */
  418. struct btrfs_extent_item {
  419. __le64 refs;
  420. __le64 generation;
  421. __le64 flags;
  422. } __attribute__ ((__packed__));
  423. struct btrfs_extent_item_v0 {
  424. __le32 refs;
  425. } __attribute__ ((__packed__));
  426. #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
  427. #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
  428. /* Use full backrefs for extent pointers in the block */
  429. #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
  430. /*
  431. * This flag is only used internally by scrub and may be changed at any time
  432. * it is only declared here to avoid collisions.
  433. */
  434. #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
  435. struct btrfs_tree_block_info {
  436. struct btrfs_disk_key key;
  437. __u8 level;
  438. } __attribute__ ((__packed__));
  439. struct btrfs_extent_data_ref {
  440. __le64 root;
  441. __le64 objectid;
  442. __le64 offset;
  443. __le32 count;
  444. } __attribute__ ((__packed__));
  445. struct btrfs_shared_data_ref {
  446. __le32 count;
  447. } __attribute__ ((__packed__));
  448. struct btrfs_extent_inline_ref {
  449. __u8 type;
  450. __le64 offset;
  451. } __attribute__ ((__packed__));
  452. /* Old style backrefs item */
  453. struct btrfs_extent_ref_v0 {
  454. __le64 root;
  455. __le64 generation;
  456. __le64 objectid;
  457. __le32 count;
  458. } __attribute__ ((__packed__));
  459. /* Dev extents record used space on individual devices.
  460. *
  461. * The owner field points back to the chunk allocation mapping tree that
  462. * allocated the extent.
  463. * The chunk tree uuid field is a way to double check the owner.
  464. */
  465. struct btrfs_dev_extent {
  466. __le64 chunk_tree;
  467. __le64 chunk_objectid;
  468. __le64 chunk_offset;
  469. __le64 length;
  470. __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  471. } __attribute__ ((__packed__));
  472. struct btrfs_inode_ref {
  473. __le64 index;
  474. __le16 name_len;
  475. /* Name goes here */
  476. } __attribute__ ((__packed__));
  477. struct btrfs_inode_extref {
  478. __le64 parent_objectid;
  479. __le64 index;
  480. __le16 name_len;
  481. __u8 name[0];
  482. /* Name goes here */
  483. } __attribute__ ((__packed__));
  484. struct btrfs_timespec {
  485. __le64 sec;
  486. __le32 nsec;
  487. } __attribute__ ((__packed__));
  488. /* Inode flags */
  489. #define BTRFS_INODE_NODATASUM (1 << 0)
  490. #define BTRFS_INODE_NODATACOW (1 << 1)
  491. #define BTRFS_INODE_READONLY (1 << 2)
  492. #define BTRFS_INODE_NOCOMPRESS (1 << 3)
  493. #define BTRFS_INODE_PREALLOC (1 << 4)
  494. #define BTRFS_INODE_SYNC (1 << 5)
  495. #define BTRFS_INODE_IMMUTABLE (1 << 6)
  496. #define BTRFS_INODE_APPEND (1 << 7)
  497. #define BTRFS_INODE_NODUMP (1 << 8)
  498. #define BTRFS_INODE_NOATIME (1 << 9)
  499. #define BTRFS_INODE_DIRSYNC (1 << 10)
  500. #define BTRFS_INODE_COMPRESS (1 << 11)
  501. #define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31)
  502. #define BTRFS_INODE_FLAG_MASK \
  503. (BTRFS_INODE_NODATASUM | \
  504. BTRFS_INODE_NODATACOW | \
  505. BTRFS_INODE_READONLY | \
  506. BTRFS_INODE_NOCOMPRESS | \
  507. BTRFS_INODE_PREALLOC | \
  508. BTRFS_INODE_SYNC | \
  509. BTRFS_INODE_IMMUTABLE | \
  510. BTRFS_INODE_APPEND | \
  511. BTRFS_INODE_NODUMP | \
  512. BTRFS_INODE_NOATIME | \
  513. BTRFS_INODE_DIRSYNC | \
  514. BTRFS_INODE_COMPRESS | \
  515. BTRFS_INODE_ROOT_ITEM_INIT)
  516. struct btrfs_inode_item {
  517. /* Nfs style generation number */
  518. __le64 generation;
  519. /* Transid that last touched this inode */
  520. __le64 transid;
  521. __le64 size;
  522. __le64 nbytes;
  523. __le64 block_group;
  524. __le32 nlink;
  525. __le32 uid;
  526. __le32 gid;
  527. __le32 mode;
  528. __le64 rdev;
  529. __le64 flags;
  530. /* Modification sequence number for NFS */
  531. __le64 sequence;
  532. /*
  533. * A little future expansion, for more than this we can just grow the
  534. * inode item and version it
  535. */
  536. __le64 reserved[4];
  537. struct btrfs_timespec atime;
  538. struct btrfs_timespec ctime;
  539. struct btrfs_timespec mtime;
  540. struct btrfs_timespec otime;
  541. } __attribute__ ((__packed__));
  542. struct btrfs_dir_log_item {
  543. __le64 end;
  544. } __attribute__ ((__packed__));
  545. struct btrfs_dir_item {
  546. struct btrfs_disk_key location;
  547. __le64 transid;
  548. __le16 data_len;
  549. __le16 name_len;
  550. __u8 type;
  551. } __attribute__ ((__packed__));
  552. #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
  553. /*
  554. * Internal in-memory flag that a subvolume has been marked for deletion but
  555. * still visible as a directory
  556. */
  557. #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
  558. struct btrfs_root_item {
  559. struct btrfs_inode_item inode;
  560. __le64 generation;
  561. __le64 root_dirid;
  562. __le64 bytenr;
  563. __le64 byte_limit;
  564. __le64 bytes_used;
  565. __le64 last_snapshot;
  566. __le64 flags;
  567. __le32 refs;
  568. struct btrfs_disk_key drop_progress;
  569. __u8 drop_level;
  570. __u8 level;
  571. /*
  572. * The following fields appear after subvol_uuids+subvol_times
  573. * were introduced.
  574. */
  575. /*
  576. * This generation number is used to test if the new fields are valid
  577. * and up to date while reading the root item. Every time the root item
  578. * is written out, the "generation" field is copied into this field. If
  579. * anyone ever mounted the fs with an older kernel, we will have
  580. * mismatching generation values here and thus must invalidate the
  581. * new fields. See btrfs_update_root and btrfs_find_last_root for
  582. * details.
  583. * The offset of generation_v2 is also used as the start for the memset
  584. * when invalidating the fields.
  585. */
  586. __le64 generation_v2;
  587. __u8 uuid[BTRFS_UUID_SIZE];
  588. __u8 parent_uuid[BTRFS_UUID_SIZE];
  589. __u8 received_uuid[BTRFS_UUID_SIZE];
  590. __le64 ctransid; /* Updated when an inode changes */
  591. __le64 otransid; /* Trans when created */
  592. __le64 stransid; /* Trans when sent. Non-zero for received subvol. */
  593. __le64 rtransid; /* Trans when received. Non-zero for received subvol.*/
  594. struct btrfs_timespec ctime;
  595. struct btrfs_timespec otime;
  596. struct btrfs_timespec stime;
  597. struct btrfs_timespec rtime;
  598. __le64 reserved[8]; /* For future */
  599. } __attribute__ ((__packed__));
  600. /* This is used for both forward and backward root refs */
  601. struct btrfs_root_ref {
  602. __le64 dirid;
  603. __le64 sequence;
  604. __le16 name_len;
  605. } __attribute__ ((__packed__));
  606. struct btrfs_disk_balance_args {
  607. /*
  608. * Profiles to operate on.
  609. *
  610. * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
  611. */
  612. __le64 profiles;
  613. /*
  614. * Usage filter
  615. * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
  616. * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
  617. */
  618. union {
  619. __le64 usage;
  620. struct {
  621. __le32 usage_min;
  622. __le32 usage_max;
  623. };
  624. };
  625. /* Devid filter */
  626. __le64 devid;
  627. /* Devid subset filter [pstart..pend) */
  628. __le64 pstart;
  629. __le64 pend;
  630. /* Btrfs virtual address space subset filter [vstart..vend) */
  631. __le64 vstart;
  632. __le64 vend;
  633. /*
  634. * Profile to convert to.
  635. *
  636. * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
  637. */
  638. __le64 target;
  639. /* BTRFS_BALANCE_ARGS_* */
  640. __le64 flags;
  641. /*
  642. * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'.
  643. * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
  644. * and maximum.
  645. */
  646. union {
  647. __le64 limit;
  648. struct {
  649. __le32 limit_min;
  650. __le32 limit_max;
  651. };
  652. };
  653. /*
  654. * Process chunks that cross stripes_min..stripes_max devices,
  655. * BTRFS_BALANCE_ARGS_STRIPES_RANGE.
  656. */
  657. __le32 stripes_min;
  658. __le32 stripes_max;
  659. __le64 unused[6];
  660. } __attribute__ ((__packed__));
  661. /*
  662. * Stores balance parameters to disk so that balance can be properly
  663. * resumed after crash or unmount.
  664. */
  665. struct btrfs_balance_item {
  666. /* BTRFS_BALANCE_* */
  667. __le64 flags;
  668. struct btrfs_disk_balance_args data;
  669. struct btrfs_disk_balance_args meta;
  670. struct btrfs_disk_balance_args sys;
  671. __le64 unused[4];
  672. } __attribute__ ((__packed__));
  673. enum {
  674. BTRFS_FILE_EXTENT_INLINE = 0,
  675. BTRFS_FILE_EXTENT_REG = 1,
  676. BTRFS_FILE_EXTENT_PREALLOC = 2,
  677. BTRFS_NR_FILE_EXTENT_TYPES = 3,
  678. };
  679. enum btrfs_compression_type {
  680. BTRFS_COMPRESS_NONE = 0,
  681. BTRFS_COMPRESS_ZLIB = 1,
  682. BTRFS_COMPRESS_LZO = 2,
  683. BTRFS_COMPRESS_ZSTD = 3,
  684. BTRFS_NR_COMPRESS_TYPES = 4,
  685. };
  686. struct btrfs_file_extent_item {
  687. /* Transaction id that created this extent */
  688. __le64 generation;
  689. /*
  690. * Max number of bytes to hold this extent in ram.
  691. *
  692. * When we split a compressed extent we can't know how big each of the
  693. * resulting pieces will be. So, this is an upper limit on the size of
  694. * the extent in ram instead of an exact limit.
  695. */
  696. __le64 ram_bytes;
  697. /*
  698. * 32 bits for the various ways we might encode the data,
  699. * including compression and encryption. If any of these
  700. * are set to something a given disk format doesn't understand
  701. * it is treated like an incompat flag for reading and writing,
  702. * but not for stat.
  703. */
  704. __u8 compression;
  705. __u8 encryption;
  706. __le16 other_encoding; /* Spare for later use */
  707. /* Are we inline data or a real extent? */
  708. __u8 type;
  709. /*
  710. * Disk space consumed by the extent, checksum blocks are not included
  711. * in these numbers
  712. *
  713. * At this offset in the structure, the inline extent data start.
  714. */
  715. __le64 disk_bytenr;
  716. __le64 disk_num_bytes;
  717. /*
  718. * The logical offset inside the file extent.
  719. *
  720. * This allows a file extent to point into the middle of an existing
  721. * extent on disk, sharing it between two snapshots (useful if some
  722. * bytes in the middle of the extent have changed).
  723. */
  724. __le64 offset;
  725. /*
  726. * The logical number of bytes this file extent is referencing (no
  727. * csums included).
  728. *
  729. * This always reflects the size uncompressed and without encoding.
  730. */
  731. __le64 num_bytes;
  732. } __attribute__ ((__packed__));
  733. struct btrfs_csum_item {
  734. __u8 csum;
  735. } __attribute__ ((__packed__));
  736. enum btrfs_dev_stat_values {
  737. /* Disk I/O failure stats */
  738. BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
  739. BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
  740. BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
  741. /* Stats for indirect indications for I/O failures */
  742. BTRFS_DEV_STAT_CORRUPTION_ERRS, /* Checksum error, bytenr error or
  743. * contents is illegal: this is an
  744. * indication that the block was damaged
  745. * during read or write, or written to
  746. * wrong location or read from wrong
  747. * location */
  748. BTRFS_DEV_STAT_GENERATION_ERRS, /* An indication that blocks have not
  749. * been written */
  750. BTRFS_DEV_STAT_VALUES_MAX
  751. };
  752. struct btrfs_dev_stats_item {
  753. /*
  754. * Grow this item struct at the end for future enhancements and keep
  755. * the existing values unchanged.
  756. */
  757. __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
  758. } __attribute__ ((__packed__));
  759. #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
  760. #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
  761. struct btrfs_dev_replace_item {
  762. /*
  763. * Grow this item struct at the end for future enhancements and keep
  764. * the existing values unchanged.
  765. */
  766. __le64 src_devid;
  767. __le64 cursor_left;
  768. __le64 cursor_right;
  769. __le64 cont_reading_from_srcdev_mode;
  770. __le64 replace_state;
  771. __le64 time_started;
  772. __le64 time_stopped;
  773. __le64 num_write_errors;
  774. __le64 num_uncorrectable_read_errors;
  775. } __attribute__ ((__packed__));
  776. /* Different types of block groups (and chunks) */
  777. #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
  778. #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
  779. #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
  780. #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
  781. #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
  782. #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
  783. #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
  784. #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
  785. #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
  786. #define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
  787. #define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
  788. #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
  789. BTRFS_SPACE_INFO_GLOBAL_RSV)
  790. enum btrfs_raid_types {
  791. BTRFS_RAID_RAID10,
  792. BTRFS_RAID_RAID1,
  793. BTRFS_RAID_DUP,
  794. BTRFS_RAID_RAID0,
  795. BTRFS_RAID_SINGLE,
  796. BTRFS_RAID_RAID5,
  797. BTRFS_RAID_RAID6,
  798. BTRFS_RAID_RAID1C3,
  799. BTRFS_RAID_RAID1C4,
  800. BTRFS_NR_RAID_TYPES
  801. };
  802. #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
  803. BTRFS_BLOCK_GROUP_SYSTEM | \
  804. BTRFS_BLOCK_GROUP_METADATA)
  805. #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
  806. BTRFS_BLOCK_GROUP_RAID1 | \
  807. BTRFS_BLOCK_GROUP_RAID1C3 | \
  808. BTRFS_BLOCK_GROUP_RAID1C4 | \
  809. BTRFS_BLOCK_GROUP_RAID5 | \
  810. BTRFS_BLOCK_GROUP_RAID6 | \
  811. BTRFS_BLOCK_GROUP_DUP | \
  812. BTRFS_BLOCK_GROUP_RAID10)
  813. #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
  814. BTRFS_BLOCK_GROUP_RAID6)
  815. #define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
  816. BTRFS_BLOCK_GROUP_RAID1C3 | \
  817. BTRFS_BLOCK_GROUP_RAID1C4)
  818. /*
  819. * We need a bit for restriper to be able to tell when chunks of type
  820. * SINGLE are available. This "extended" profile format is used in
  821. * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
  822. * (on-disk). The corresponding on-disk bit in chunk.type is reserved
  823. * to avoid remappings between two formats in future.
  824. */
  825. #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
  826. /*
  827. * A fake block group type that is used to communicate global block reserve
  828. * size to userspace via the SPACE_INFO ioctl.
  829. */
  830. #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
  831. #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
  832. BTRFS_AVAIL_ALLOC_BIT_SINGLE)
  833. static inline __u64 chunk_to_extended(__u64 flags)
  834. {
  835. if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
  836. flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
  837. return flags;
  838. }
  839. static inline __u64 extended_to_chunk(__u64 flags)
  840. {
  841. return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
  842. }
  843. struct btrfs_block_group_item {
  844. __le64 used;
  845. __le64 chunk_objectid;
  846. __le64 flags;
  847. } __attribute__ ((__packed__));
  848. struct btrfs_free_space_info {
  849. __le32 extent_count;
  850. __le32 flags;
  851. } __attribute__ ((__packed__));
  852. #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
  853. #define BTRFS_QGROUP_LEVEL_SHIFT 48
  854. static inline __u64 btrfs_qgroup_level(__u64 qgroupid)
  855. {
  856. return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
  857. }
  858. /* Is subvolume quota turned on? */
  859. #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
  860. /* Is qgroup rescan running? */
  861. #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
  862. /*
  863. * Some qgroup entries are known to be out of date, either because the
  864. * configuration has changed in a way that makes a rescan necessary, or
  865. * because the fs has been mounted with a non-qgroup-aware version.
  866. */
  867. #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
  868. #define BTRFS_QGROUP_STATUS_VERSION 1
  869. struct btrfs_qgroup_status_item {
  870. __le64 version;
  871. /*
  872. * The generation is updated during every commit. As older
  873. * versions of btrfs are not aware of qgroups, it will be
  874. * possible to detect inconsistencies by checking the
  875. * generation on mount time.
  876. */
  877. __le64 generation;
  878. /* Flag definitions see above */
  879. __le64 flags;
  880. /*
  881. * Only used during scanning to record the progress of the scan.
  882. * It contains a logical address.
  883. */
  884. __le64 rescan;
  885. } __attribute__ ((__packed__));
  886. struct btrfs_qgroup_info_item {
  887. __le64 generation;
  888. __le64 rfer;
  889. __le64 rfer_cmpr;
  890. __le64 excl;
  891. __le64 excl_cmpr;
  892. } __attribute__ ((__packed__));
  893. /*
  894. * Flags definition for qgroup limits
  895. *
  896. * Used by:
  897. * struct btrfs_qgroup_limit.flags
  898. * struct btrfs_qgroup_limit_item.flags
  899. */
  900. #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
  901. #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
  902. #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
  903. #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
  904. #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
  905. #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
  906. struct btrfs_qgroup_limit_item {
  907. /* Only updated when any of the other values change. */
  908. __le64 flags;
  909. __le64 max_rfer;
  910. __le64 max_excl;
  911. __le64 rsv_rfer;
  912. __le64 rsv_excl;
  913. } __attribute__ ((__packed__));
  914. /*
  915. * Just in case we somehow lose the roots and are not able to mount,
  916. * we store an array of the roots from previous transactions in the super.
  917. */
  918. #define BTRFS_NUM_BACKUP_ROOTS 4
  919. struct btrfs_root_backup {
  920. __le64 tree_root;
  921. __le64 tree_root_gen;
  922. __le64 chunk_root;
  923. __le64 chunk_root_gen;
  924. __le64 extent_root;
  925. __le64 extent_root_gen;
  926. __le64 fs_root;
  927. __le64 fs_root_gen;
  928. __le64 dev_root;
  929. __le64 dev_root_gen;
  930. __le64 csum_root;
  931. __le64 csum_root_gen;
  932. __le64 total_bytes;
  933. __le64 bytes_used;
  934. __le64 num_devices;
  935. /* future */
  936. __le64 unused_64[4];
  937. u8 tree_root_level;
  938. u8 chunk_root_level;
  939. u8 extent_root_level;
  940. u8 fs_root_level;
  941. u8 dev_root_level;
  942. u8 csum_root_level;
  943. /* future and to align */
  944. u8 unused_8[10];
  945. } __attribute__ ((__packed__));
  946. /*
  947. * This is a very generous portion of the super block, giving us room to
  948. * translate 14 chunks with 3 stripes each.
  949. */
  950. #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
  951. #define BTRFS_LABEL_SIZE 256
  952. /* The super block basically lists the main trees of the FS. */
  953. struct btrfs_super_block {
  954. /* The first 4 fields must match struct btrfs_header */
  955. u8 csum[BTRFS_CSUM_SIZE];
  956. /* FS specific UUID, visible to user */
  957. u8 fsid[BTRFS_FSID_SIZE];
  958. __le64 bytenr; /* this block number */
  959. __le64 flags;
  960. /* Allowed to be different from the btrfs_header from here own down. */
  961. __le64 magic;
  962. __le64 generation;
  963. __le64 root;
  964. __le64 chunk_root;
  965. __le64 log_root;
  966. /* This will help find the new super based on the log root. */
  967. __le64 log_root_transid;
  968. __le64 total_bytes;
  969. __le64 bytes_used;
  970. __le64 root_dir_objectid;
  971. __le64 num_devices;
  972. __le32 sectorsize;
  973. __le32 nodesize;
  974. __le32 __unused_leafsize;
  975. __le32 stripesize;
  976. __le32 sys_chunk_array_size;
  977. __le64 chunk_root_generation;
  978. __le64 compat_flags;
  979. __le64 compat_ro_flags;
  980. __le64 incompat_flags;
  981. __le16 csum_type;
  982. u8 root_level;
  983. u8 chunk_root_level;
  984. u8 log_root_level;
  985. struct btrfs_dev_item dev_item;
  986. char label[BTRFS_LABEL_SIZE];
  987. __le64 cache_generation;
  988. __le64 uuid_tree_generation;
  989. /* The UUID written into btree blocks */
  990. u8 metadata_uuid[BTRFS_FSID_SIZE];
  991. /* Future expansion */
  992. __le64 reserved[28];
  993. u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
  994. struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
  995. } __attribute__ ((__packed__));
  996. /*
  997. * Feature flags
  998. *
  999. * Used by:
  1000. * struct btrfs_super_block::(compat|compat_ro|incompat)_flags
  1001. * struct btrfs_ioctl_feature_flags
  1002. */
  1003. #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0)
  1004. /*
  1005. * Older kernels (< 4.9) on big-endian systems produced broken free space tree
  1006. * bitmaps, and btrfs-progs also used to corrupt the free space tree (versions
  1007. * < 4.7.3). If this bit is clear, then the free space tree cannot be trusted.
  1008. * btrfs-progs can also intentionally clear this bit to ask the kernel to
  1009. * rebuild the free space tree, however this might not work on older kernels
  1010. * that do not know about this bit. If not sure, clear the cache manually on
  1011. * first mount when booting older kernel versions.
  1012. */
  1013. #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID (1ULL << 1)
  1014. #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
  1015. #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
  1016. #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
  1017. #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
  1018. #define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD (1ULL << 4)
  1019. /*
  1020. * Older kernels tried to do bigger metadata blocks, but the
  1021. * code was pretty buggy. Lets not let them try anymore.
  1022. */
  1023. #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
  1024. #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
  1025. #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
  1026. #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
  1027. #define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)
  1028. #define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10)
  1029. #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11)
  1030. /*
  1031. * Compat flags that we support.
  1032. *
  1033. * If any incompat flags are set other than the ones specified below then we
  1034. * will fail to mount.
  1035. */
  1036. #define BTRFS_FEATURE_COMPAT_SUPP 0ULL
  1037. #define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL
  1038. #define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL
  1039. #define BTRFS_FEATURE_COMPAT_RO_SUPP \
  1040. (BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE | \
  1041. BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID)
  1042. #define BTRFS_FEATURE_COMPAT_RO_SAFE_SET 0ULL
  1043. #define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL
  1044. #define BTRFS_FEATURE_INCOMPAT_SUPP \
  1045. (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
  1046. BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
  1047. BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
  1048. BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \
  1049. BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
  1050. BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD | \
  1051. BTRFS_FEATURE_INCOMPAT_RAID56 | \
  1052. BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
  1053. BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \
  1054. BTRFS_FEATURE_INCOMPAT_NO_HOLES | \
  1055. BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \
  1056. BTRFS_FEATURE_INCOMPAT_RAID1C34)
  1057. #define BTRFS_FEATURE_INCOMPAT_SAFE_SET \
  1058. (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
  1059. #define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR 0ULL
  1060. #define BTRFS_BACKREF_REV_MAX 256
  1061. #define BTRFS_BACKREF_REV_SHIFT 56
  1062. #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
  1063. BTRFS_BACKREF_REV_SHIFT)
  1064. #define BTRFS_OLD_BACKREF_REV 0
  1065. #define BTRFS_MIXED_BACKREF_REV 1
  1066. #define BTRFS_MAX_LEVEL 8
  1067. /* Every tree block (leaf or node) starts with this header. */
  1068. struct btrfs_header {
  1069. /* These first four must match the super block */
  1070. u8 csum[BTRFS_CSUM_SIZE];
  1071. u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
  1072. __le64 bytenr; /* Which block this node is supposed to live in */
  1073. __le64 flags;
  1074. /* Allowed to be different from the super from here on down. */
  1075. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  1076. __le64 generation;
  1077. __le64 owner;
  1078. __le32 nritems;
  1079. u8 level;
  1080. } __attribute__ ((__packed__));
  1081. /*
  1082. * A leaf is full of items. Offset and size tell us where to find
  1083. * the item in the leaf (relative to the start of the data area).
  1084. */
  1085. struct btrfs_item {
  1086. struct btrfs_disk_key key;
  1087. __le32 offset;
  1088. __le32 size;
  1089. } __attribute__ ((__packed__));
  1090. /*
  1091. * leaves have an item area and a data area:
  1092. * [item0, item1....itemN] [free space] [dataN...data1, data0]
  1093. *
  1094. * The data is separate from the items to get the keys closer together
  1095. * during searches.
  1096. */
  1097. struct btrfs_leaf {
  1098. struct btrfs_header header;
  1099. struct btrfs_item items[];
  1100. } __attribute__ ((__packed__));
  1101. /*
  1102. * All non-leaf blocks are nodes, they hold only keys and pointers to children
  1103. * blocks.
  1104. */
  1105. struct btrfs_key_ptr {
  1106. struct btrfs_disk_key key;
  1107. __le64 blockptr;
  1108. __le64 generation;
  1109. } __attribute__ ((__packed__));
  1110. struct btrfs_node {
  1111. struct btrfs_header header;
  1112. struct btrfs_key_ptr ptrs[];
  1113. } __attribute__ ((__packed__));
  1114. #endif /* __BTRFS_TREE_H__ */