btrfs_tree.h 25 KB

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