btrfs_tree.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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. /*
  372. * items in the extent btree are used to record the objectid of the
  373. * owner of the block and the number of references
  374. */
  375. struct btrfs_extent_item {
  376. __le64 refs;
  377. __le64 generation;
  378. __le64 flags;
  379. } __attribute__ ((__packed__));
  380. struct btrfs_extent_item_v0 {
  381. __le32 refs;
  382. } __attribute__ ((__packed__));
  383. #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
  384. #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
  385. /* following flags only apply to tree blocks */
  386. /* use full backrefs for extent pointers in the block */
  387. #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
  388. /*
  389. * this flag is only used internally by scrub and may be changed at any time
  390. * it is only declared here to avoid collisions
  391. */
  392. #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
  393. struct btrfs_tree_block_info {
  394. struct btrfs_disk_key key;
  395. __u8 level;
  396. } __attribute__ ((__packed__));
  397. struct btrfs_extent_data_ref {
  398. __le64 root;
  399. __le64 objectid;
  400. __le64 offset;
  401. __le32 count;
  402. } __attribute__ ((__packed__));
  403. struct btrfs_shared_data_ref {
  404. __le32 count;
  405. } __attribute__ ((__packed__));
  406. struct btrfs_extent_inline_ref {
  407. __u8 type;
  408. __le64 offset;
  409. } __attribute__ ((__packed__));
  410. /* old style backrefs item */
  411. struct btrfs_extent_ref_v0 {
  412. __le64 root;
  413. __le64 generation;
  414. __le64 objectid;
  415. __le32 count;
  416. } __attribute__ ((__packed__));
  417. /* dev extents record free space on individual devices. The owner
  418. * field points back to the chunk allocation mapping tree that allocated
  419. * the extent. The chunk tree uuid field is a way to double check the owner
  420. */
  421. struct btrfs_dev_extent {
  422. __le64 chunk_tree;
  423. __le64 chunk_objectid;
  424. __le64 chunk_offset;
  425. __le64 length;
  426. __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  427. } __attribute__ ((__packed__));
  428. struct btrfs_inode_ref {
  429. __le64 index;
  430. __le16 name_len;
  431. /* name goes here */
  432. } __attribute__ ((__packed__));
  433. struct btrfs_inode_extref {
  434. __le64 parent_objectid;
  435. __le64 index;
  436. __le16 name_len;
  437. __u8 name[0];
  438. /* name goes here */
  439. } __attribute__ ((__packed__));
  440. struct btrfs_timespec {
  441. __le64 sec;
  442. __le32 nsec;
  443. } __attribute__ ((__packed__));
  444. struct btrfs_inode_item {
  445. /* nfs style generation number */
  446. __le64 generation;
  447. /* transid that last touched this inode */
  448. __le64 transid;
  449. __le64 size;
  450. __le64 nbytes;
  451. __le64 block_group;
  452. __le32 nlink;
  453. __le32 uid;
  454. __le32 gid;
  455. __le32 mode;
  456. __le64 rdev;
  457. __le64 flags;
  458. /* modification sequence number for NFS */
  459. __le64 sequence;
  460. /*
  461. * a little future expansion, for more than this we can
  462. * just grow the inode item and version it
  463. */
  464. __le64 reserved[4];
  465. struct btrfs_timespec atime;
  466. struct btrfs_timespec ctime;
  467. struct btrfs_timespec mtime;
  468. struct btrfs_timespec otime;
  469. } __attribute__ ((__packed__));
  470. struct btrfs_dir_log_item {
  471. __le64 end;
  472. } __attribute__ ((__packed__));
  473. struct btrfs_dir_item {
  474. struct btrfs_disk_key location;
  475. __le64 transid;
  476. __le16 data_len;
  477. __le16 name_len;
  478. __u8 type;
  479. } __attribute__ ((__packed__));
  480. #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
  481. /*
  482. * Internal in-memory flag that a subvolume has been marked for deletion but
  483. * still visible as a directory
  484. */
  485. #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
  486. struct btrfs_root_item {
  487. struct btrfs_inode_item inode;
  488. __le64 generation;
  489. __le64 root_dirid;
  490. __le64 bytenr;
  491. __le64 byte_limit;
  492. __le64 bytes_used;
  493. __le64 last_snapshot;
  494. __le64 flags;
  495. __le32 refs;
  496. struct btrfs_disk_key drop_progress;
  497. __u8 drop_level;
  498. __u8 level;
  499. /*
  500. * The following fields appear after subvol_uuids+subvol_times
  501. * were introduced.
  502. */
  503. /*
  504. * This generation number is used to test if the new fields are valid
  505. * and up to date while reading the root item. Every time the root item
  506. * is written out, the "generation" field is copied into this field. If
  507. * anyone ever mounted the fs with an older kernel, we will have
  508. * mismatching generation values here and thus must invalidate the
  509. * new fields. See btrfs_update_root and btrfs_find_last_root for
  510. * details.
  511. * the offset of generation_v2 is also used as the start for the memset
  512. * when invalidating the fields.
  513. */
  514. __le64 generation_v2;
  515. __u8 uuid[BTRFS_UUID_SIZE];
  516. __u8 parent_uuid[BTRFS_UUID_SIZE];
  517. __u8 received_uuid[BTRFS_UUID_SIZE];
  518. __le64 ctransid; /* updated when an inode changes */
  519. __le64 otransid; /* trans when created */
  520. __le64 stransid; /* trans when sent. non-zero for received subvol */
  521. __le64 rtransid; /* trans when received. non-zero for received subvol */
  522. struct btrfs_timespec ctime;
  523. struct btrfs_timespec otime;
  524. struct btrfs_timespec stime;
  525. struct btrfs_timespec rtime;
  526. __le64 reserved[8]; /* for future */
  527. } __attribute__ ((__packed__));
  528. /*
  529. * this is used for both forward and backward root refs
  530. */
  531. struct btrfs_root_ref {
  532. __le64 dirid;
  533. __le64 sequence;
  534. __le16 name_len;
  535. } __attribute__ ((__packed__));
  536. struct btrfs_disk_balance_args {
  537. /*
  538. * profiles to operate on, single is denoted by
  539. * BTRFS_AVAIL_ALLOC_BIT_SINGLE
  540. */
  541. __le64 profiles;
  542. /*
  543. * usage filter
  544. * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
  545. * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
  546. */
  547. union {
  548. __le64 usage;
  549. struct {
  550. __le32 usage_min;
  551. __le32 usage_max;
  552. };
  553. };
  554. /* devid filter */
  555. __le64 devid;
  556. /* devid subset filter [pstart..pend) */
  557. __le64 pstart;
  558. __le64 pend;
  559. /* btrfs virtual address space subset filter [vstart..vend) */
  560. __le64 vstart;
  561. __le64 vend;
  562. /*
  563. * profile to convert to, single is denoted by
  564. * BTRFS_AVAIL_ALLOC_BIT_SINGLE
  565. */
  566. __le64 target;
  567. /* BTRFS_BALANCE_ARGS_* */
  568. __le64 flags;
  569. /*
  570. * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
  571. * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
  572. * and maximum
  573. */
  574. union {
  575. __le64 limit;
  576. struct {
  577. __le32 limit_min;
  578. __le32 limit_max;
  579. };
  580. };
  581. /*
  582. * Process chunks that cross stripes_min..stripes_max devices,
  583. * BTRFS_BALANCE_ARGS_STRIPES_RANGE
  584. */
  585. __le32 stripes_min;
  586. __le32 stripes_max;
  587. __le64 unused[6];
  588. } __attribute__ ((__packed__));
  589. /*
  590. * store balance parameters to disk so that balance can be properly
  591. * resumed after crash or unmount
  592. */
  593. struct btrfs_balance_item {
  594. /* BTRFS_BALANCE_* */
  595. __le64 flags;
  596. struct btrfs_disk_balance_args data;
  597. struct btrfs_disk_balance_args meta;
  598. struct btrfs_disk_balance_args sys;
  599. __le64 unused[4];
  600. } __attribute__ ((__packed__));
  601. #define BTRFS_FILE_EXTENT_INLINE 0
  602. #define BTRFS_FILE_EXTENT_REG 1
  603. #define BTRFS_FILE_EXTENT_PREALLOC 2
  604. #define BTRFS_FILE_EXTENT_TYPES 2
  605. struct btrfs_file_extent_item {
  606. /*
  607. * transaction id that created this extent
  608. */
  609. __le64 generation;
  610. /*
  611. * max number of bytes to hold this extent in ram
  612. * when we split a compressed extent we can't know how big
  613. * each of the resulting pieces will be. So, this is
  614. * an upper limit on the size of the extent in ram instead of
  615. * an exact limit.
  616. */
  617. __le64 ram_bytes;
  618. /*
  619. * 32 bits for the various ways we might encode the data,
  620. * including compression and encryption. If any of these
  621. * are set to something a given disk format doesn't understand
  622. * it is treated like an incompat flag for reading and writing,
  623. * but not for stat.
  624. */
  625. __u8 compression;
  626. __u8 encryption;
  627. __le16 other_encoding; /* spare for later use */
  628. /* are we inline data or a real extent? */
  629. __u8 type;
  630. /*
  631. * disk space consumed by the extent, checksum blocks are included
  632. * in these numbers
  633. *
  634. * At this offset in the structure, the inline extent data start.
  635. */
  636. __le64 disk_bytenr;
  637. __le64 disk_num_bytes;
  638. /*
  639. * the logical offset in file blocks (no csums)
  640. * this extent record is for. This allows a file extent to point
  641. * into the middle of an existing extent on disk, sharing it
  642. * between two snapshots (useful if some bytes in the middle of the
  643. * extent have changed
  644. */
  645. __le64 offset;
  646. /*
  647. * the logical number of file blocks (no csums included). This
  648. * always reflects the size uncompressed and without encoding.
  649. */
  650. __le64 num_bytes;
  651. } __attribute__ ((__packed__));
  652. struct btrfs_csum_item {
  653. __u8 csum;
  654. } __attribute__ ((__packed__));
  655. struct btrfs_dev_stats_item {
  656. /*
  657. * grow this item struct at the end for future enhancements and keep
  658. * the existing values unchanged
  659. */
  660. __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
  661. } __attribute__ ((__packed__));
  662. #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
  663. #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
  664. #define BTRFS_DEV_REPLACE_ITEM_STATE_NEVER_STARTED 0
  665. #define BTRFS_DEV_REPLACE_ITEM_STATE_STARTED 1
  666. #define BTRFS_DEV_REPLACE_ITEM_STATE_SUSPENDED 2
  667. #define BTRFS_DEV_REPLACE_ITEM_STATE_FINISHED 3
  668. #define BTRFS_DEV_REPLACE_ITEM_STATE_CANCELED 4
  669. struct btrfs_dev_replace_item {
  670. /*
  671. * grow this item struct at the end for future enhancements and keep
  672. * the existing values unchanged
  673. */
  674. __le64 src_devid;
  675. __le64 cursor_left;
  676. __le64 cursor_right;
  677. __le64 cont_reading_from_srcdev_mode;
  678. __le64 replace_state;
  679. __le64 time_started;
  680. __le64 time_stopped;
  681. __le64 num_write_errors;
  682. __le64 num_uncorrectable_read_errors;
  683. } __attribute__ ((__packed__));
  684. /* different types of block groups (and chunks) */
  685. #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
  686. #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
  687. #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
  688. #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
  689. #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
  690. #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
  691. #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
  692. #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
  693. #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
  694. #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
  695. BTRFS_SPACE_INFO_GLOBAL_RSV)
  696. enum btrfs_raid_types {
  697. BTRFS_RAID_RAID10,
  698. BTRFS_RAID_RAID1,
  699. BTRFS_RAID_DUP,
  700. BTRFS_RAID_RAID0,
  701. BTRFS_RAID_SINGLE,
  702. BTRFS_RAID_RAID5,
  703. BTRFS_RAID_RAID6,
  704. BTRFS_NR_RAID_TYPES
  705. };
  706. #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
  707. BTRFS_BLOCK_GROUP_SYSTEM | \
  708. BTRFS_BLOCK_GROUP_METADATA)
  709. #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
  710. BTRFS_BLOCK_GROUP_RAID1 | \
  711. BTRFS_BLOCK_GROUP_RAID5 | \
  712. BTRFS_BLOCK_GROUP_RAID6 | \
  713. BTRFS_BLOCK_GROUP_DUP | \
  714. BTRFS_BLOCK_GROUP_RAID10)
  715. #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
  716. BTRFS_BLOCK_GROUP_RAID6)
  717. /*
  718. * We need a bit for restriper to be able to tell when chunks of type
  719. * SINGLE are available. This "extended" profile format is used in
  720. * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
  721. * (on-disk). The corresponding on-disk bit in chunk.type is reserved
  722. * to avoid remappings between two formats in future.
  723. */
  724. #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
  725. /*
  726. * A fake block group type that is used to communicate global block reserve
  727. * size to userspace via the SPACE_INFO ioctl.
  728. */
  729. #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
  730. #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
  731. BTRFS_AVAIL_ALLOC_BIT_SINGLE)
  732. static inline __u64 chunk_to_extended(__u64 flags)
  733. {
  734. if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
  735. flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
  736. return flags;
  737. }
  738. static inline __u64 extended_to_chunk(__u64 flags)
  739. {
  740. return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
  741. }
  742. struct btrfs_block_group_item {
  743. __le64 used;
  744. __le64 chunk_objectid;
  745. __le64 flags;
  746. } __attribute__ ((__packed__));
  747. struct btrfs_free_space_info {
  748. __le32 extent_count;
  749. __le32 flags;
  750. } __attribute__ ((__packed__));
  751. #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
  752. #define BTRFS_QGROUP_LEVEL_SHIFT 48
  753. static inline __u64 btrfs_qgroup_level(__u64 qgroupid)
  754. {
  755. return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
  756. }
  757. /*
  758. * is subvolume quota turned on?
  759. */
  760. #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
  761. /*
  762. * RESCAN is set during the initialization phase
  763. */
  764. #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
  765. /*
  766. * Some qgroup entries are known to be out of date,
  767. * either because the configuration has changed in a way that
  768. * makes a rescan necessary, or because the fs has been mounted
  769. * with a non-qgroup-aware version.
  770. * Turning qouta off and on again makes it inconsistent, too.
  771. */
  772. #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
  773. #define BTRFS_QGROUP_STATUS_VERSION 1
  774. struct btrfs_qgroup_status_item {
  775. __le64 version;
  776. /*
  777. * the generation is updated during every commit. As older
  778. * versions of btrfs are not aware of qgroups, it will be
  779. * possible to detect inconsistencies by checking the
  780. * generation on mount time
  781. */
  782. __le64 generation;
  783. /* flag definitions see above */
  784. __le64 flags;
  785. /*
  786. * only used during scanning to record the progress
  787. * of the scan. It contains a logical address
  788. */
  789. __le64 rescan;
  790. } __attribute__ ((__packed__));
  791. struct btrfs_qgroup_info_item {
  792. __le64 generation;
  793. __le64 rfer;
  794. __le64 rfer_cmpr;
  795. __le64 excl;
  796. __le64 excl_cmpr;
  797. } __attribute__ ((__packed__));
  798. struct btrfs_qgroup_limit_item {
  799. /*
  800. * only updated when any of the other values change
  801. */
  802. __le64 flags;
  803. __le64 max_rfer;
  804. __le64 max_excl;
  805. __le64 rsv_rfer;
  806. __le64 rsv_excl;
  807. } __attribute__ ((__packed__));
  808. #endif /* _BTRFS_CTREE_H_ */