btrfs_tree.h 25 KB

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