btrfs_tree.h 27 KB

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