btrfs_tree.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  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. enum btrfs_csum_type {
  247. BTRFS_CSUM_TYPE_CRC32 = 0,
  248. BTRFS_CSUM_TYPE_XXHASH = 1,
  249. BTRFS_CSUM_TYPE_SHA256 = 2,
  250. BTRFS_CSUM_TYPE_BLAKE2 = 3,
  251. };
  252. /*
  253. * flags definitions for directory entry item type
  254. *
  255. * Used by:
  256. * struct btrfs_dir_item.type
  257. *
  258. * Values 0..7 must match common file type values in fs_types.h.
  259. */
  260. #define BTRFS_FT_UNKNOWN 0
  261. #define BTRFS_FT_REG_FILE 1
  262. #define BTRFS_FT_DIR 2
  263. #define BTRFS_FT_CHRDEV 3
  264. #define BTRFS_FT_BLKDEV 4
  265. #define BTRFS_FT_FIFO 5
  266. #define BTRFS_FT_SOCK 6
  267. #define BTRFS_FT_SYMLINK 7
  268. #define BTRFS_FT_XATTR 8
  269. #define BTRFS_FT_MAX 9
  270. /*
  271. * The key defines the order in the tree, and so it also defines (optimal)
  272. * block layout.
  273. *
  274. * objectid corresponds to the inode number.
  275. *
  276. * type tells us things about the object, and is a kind of stream selector.
  277. * so for a given inode, keys with type of 1 might refer to the inode data,
  278. * type of 2 may point to file data in the btree and type == 3 may point to
  279. * extents.
  280. *
  281. * offset is the starting byte offset for this key in the stream.
  282. *
  283. * btrfs_disk_key is in disk byte order. struct btrfs_key is always
  284. * in cpu native order. Otherwise they are identical and their sizes
  285. * should be the same (ie both packed)
  286. */
  287. struct btrfs_disk_key {
  288. __le64 objectid;
  289. __u8 type;
  290. __le64 offset;
  291. } __attribute__ ((__packed__));
  292. struct btrfs_key {
  293. __u64 objectid;
  294. __u8 type;
  295. __u64 offset;
  296. } __attribute__ ((__packed__));
  297. struct btrfs_dev_item {
  298. /* the internal btrfs device id */
  299. __le64 devid;
  300. /* size of the device */
  301. __le64 total_bytes;
  302. /* bytes used */
  303. __le64 bytes_used;
  304. /* optimal io alignment for this device */
  305. __le32 io_align;
  306. /* optimal io width for this device */
  307. __le32 io_width;
  308. /* minimal io size for this device */
  309. __le32 sector_size;
  310. /* type and info about this device */
  311. __le64 type;
  312. /* expected generation for this device */
  313. __le64 generation;
  314. /*
  315. * starting byte of this partition on the device,
  316. * to allow for stripe alignment in the future
  317. */
  318. __le64 start_offset;
  319. /* grouping information for allocation decisions */
  320. __le32 dev_group;
  321. /* seek speed 0-100 where 100 is fastest */
  322. __u8 seek_speed;
  323. /* bandwidth 0-100 where 100 is fastest */
  324. __u8 bandwidth;
  325. /* btrfs generated uuid for this device */
  326. __u8 uuid[BTRFS_UUID_SIZE];
  327. /* uuid of FS who owns this device */
  328. __u8 fsid[BTRFS_UUID_SIZE];
  329. } __attribute__ ((__packed__));
  330. struct btrfs_stripe {
  331. __le64 devid;
  332. __le64 offset;
  333. __u8 dev_uuid[BTRFS_UUID_SIZE];
  334. } __attribute__ ((__packed__));
  335. struct btrfs_chunk {
  336. /* size of this chunk in bytes */
  337. __le64 length;
  338. /* objectid of the root referencing this chunk */
  339. __le64 owner;
  340. __le64 stripe_len;
  341. __le64 type;
  342. /* optimal io alignment for this chunk */
  343. __le32 io_align;
  344. /* optimal io width for this chunk */
  345. __le32 io_width;
  346. /* minimal io size for this chunk */
  347. __le32 sector_size;
  348. /* 2^16 stripes is quite a lot, a second limit is the size of a single
  349. * item in the btree
  350. */
  351. __le16 num_stripes;
  352. /* sub stripes only matter for raid10 */
  353. __le16 sub_stripes;
  354. struct btrfs_stripe stripe;
  355. /* additional stripes go here */
  356. } __attribute__ ((__packed__));
  357. #define BTRFS_FREE_SPACE_EXTENT 1
  358. #define BTRFS_FREE_SPACE_BITMAP 2
  359. struct btrfs_free_space_entry {
  360. __le64 offset;
  361. __le64 bytes;
  362. __u8 type;
  363. } __attribute__ ((__packed__));
  364. struct btrfs_free_space_header {
  365. struct btrfs_disk_key location;
  366. __le64 generation;
  367. __le64 num_entries;
  368. __le64 num_bitmaps;
  369. } __attribute__ ((__packed__));
  370. #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
  371. #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
  372. /* Super block flags */
  373. /* Errors detected */
  374. #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
  375. #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
  376. #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
  377. #define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
  378. #define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
  379. #define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
  380. /*
  381. * items in the extent btree are used to record the objectid of the
  382. * owner of the block and the number of references
  383. */
  384. struct btrfs_extent_item {
  385. __le64 refs;
  386. __le64 generation;
  387. __le64 flags;
  388. } __attribute__ ((__packed__));
  389. struct btrfs_extent_item_v0 {
  390. __le32 refs;
  391. } __attribute__ ((__packed__));
  392. #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
  393. #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
  394. /* following flags only apply to tree blocks */
  395. /* use full backrefs for extent pointers in the block */
  396. #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
  397. /*
  398. * this flag is only used internally by scrub and may be changed at any time
  399. * it is only declared here to avoid collisions
  400. */
  401. #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
  402. struct btrfs_tree_block_info {
  403. struct btrfs_disk_key key;
  404. __u8 level;
  405. } __attribute__ ((__packed__));
  406. struct btrfs_extent_data_ref {
  407. __le64 root;
  408. __le64 objectid;
  409. __le64 offset;
  410. __le32 count;
  411. } __attribute__ ((__packed__));
  412. struct btrfs_shared_data_ref {
  413. __le32 count;
  414. } __attribute__ ((__packed__));
  415. struct btrfs_extent_inline_ref {
  416. __u8 type;
  417. __le64 offset;
  418. } __attribute__ ((__packed__));
  419. /* old style backrefs item */
  420. struct btrfs_extent_ref_v0 {
  421. __le64 root;
  422. __le64 generation;
  423. __le64 objectid;
  424. __le32 count;
  425. } __attribute__ ((__packed__));
  426. /* dev extents record free space on individual devices. The owner
  427. * field points back to the chunk allocation mapping tree that allocated
  428. * the extent. The chunk tree uuid field is a way to double check the owner
  429. */
  430. struct btrfs_dev_extent {
  431. __le64 chunk_tree;
  432. __le64 chunk_objectid;
  433. __le64 chunk_offset;
  434. __le64 length;
  435. __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  436. } __attribute__ ((__packed__));
  437. struct btrfs_inode_ref {
  438. __le64 index;
  439. __le16 name_len;
  440. /* name goes here */
  441. } __attribute__ ((__packed__));
  442. struct btrfs_inode_extref {
  443. __le64 parent_objectid;
  444. __le64 index;
  445. __le16 name_len;
  446. __u8 name[0];
  447. /* name goes here */
  448. } __attribute__ ((__packed__));
  449. struct btrfs_timespec {
  450. __le64 sec;
  451. __le32 nsec;
  452. } __attribute__ ((__packed__));
  453. struct btrfs_inode_item {
  454. /* nfs style generation number */
  455. __le64 generation;
  456. /* transid that last touched this inode */
  457. __le64 transid;
  458. __le64 size;
  459. __le64 nbytes;
  460. __le64 block_group;
  461. __le32 nlink;
  462. __le32 uid;
  463. __le32 gid;
  464. __le32 mode;
  465. __le64 rdev;
  466. __le64 flags;
  467. /* modification sequence number for NFS */
  468. __le64 sequence;
  469. /*
  470. * a little future expansion, for more than this we can
  471. * just grow the inode item and version it
  472. */
  473. __le64 reserved[4];
  474. struct btrfs_timespec atime;
  475. struct btrfs_timespec ctime;
  476. struct btrfs_timespec mtime;
  477. struct btrfs_timespec otime;
  478. } __attribute__ ((__packed__));
  479. struct btrfs_dir_log_item {
  480. __le64 end;
  481. } __attribute__ ((__packed__));
  482. struct btrfs_dir_item {
  483. struct btrfs_disk_key location;
  484. __le64 transid;
  485. __le16 data_len;
  486. __le16 name_len;
  487. __u8 type;
  488. } __attribute__ ((__packed__));
  489. #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
  490. /*
  491. * Internal in-memory flag that a subvolume has been marked for deletion but
  492. * still visible as a directory
  493. */
  494. #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
  495. struct btrfs_root_item {
  496. struct btrfs_inode_item inode;
  497. __le64 generation;
  498. __le64 root_dirid;
  499. __le64 bytenr;
  500. __le64 byte_limit;
  501. __le64 bytes_used;
  502. __le64 last_snapshot;
  503. __le64 flags;
  504. __le32 refs;
  505. struct btrfs_disk_key drop_progress;
  506. __u8 drop_level;
  507. __u8 level;
  508. /*
  509. * The following fields appear after subvol_uuids+subvol_times
  510. * were introduced.
  511. */
  512. /*
  513. * This generation number is used to test if the new fields are valid
  514. * and up to date while reading the root item. Every time the root item
  515. * is written out, the "generation" field is copied into this field. If
  516. * anyone ever mounted the fs with an older kernel, we will have
  517. * mismatching generation values here and thus must invalidate the
  518. * new fields. See btrfs_update_root and btrfs_find_last_root for
  519. * details.
  520. * the offset of generation_v2 is also used as the start for the memset
  521. * when invalidating the fields.
  522. */
  523. __le64 generation_v2;
  524. __u8 uuid[BTRFS_UUID_SIZE];
  525. __u8 parent_uuid[BTRFS_UUID_SIZE];
  526. __u8 received_uuid[BTRFS_UUID_SIZE];
  527. __le64 ctransid; /* updated when an inode changes */
  528. __le64 otransid; /* trans when created */
  529. __le64 stransid; /* trans when sent. non-zero for received subvol */
  530. __le64 rtransid; /* trans when received. non-zero for received subvol */
  531. struct btrfs_timespec ctime;
  532. struct btrfs_timespec otime;
  533. struct btrfs_timespec stime;
  534. struct btrfs_timespec rtime;
  535. __le64 reserved[8]; /* for future */
  536. } __attribute__ ((__packed__));
  537. /*
  538. * this is used for both forward and backward root refs
  539. */
  540. struct btrfs_root_ref {
  541. __le64 dirid;
  542. __le64 sequence;
  543. __le16 name_len;
  544. } __attribute__ ((__packed__));
  545. struct btrfs_disk_balance_args {
  546. /*
  547. * profiles to operate on, single is denoted by
  548. * BTRFS_AVAIL_ALLOC_BIT_SINGLE
  549. */
  550. __le64 profiles;
  551. /*
  552. * usage filter
  553. * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
  554. * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
  555. */
  556. union {
  557. __le64 usage;
  558. struct {
  559. __le32 usage_min;
  560. __le32 usage_max;
  561. };
  562. };
  563. /* devid filter */
  564. __le64 devid;
  565. /* devid subset filter [pstart..pend) */
  566. __le64 pstart;
  567. __le64 pend;
  568. /* btrfs virtual address space subset filter [vstart..vend) */
  569. __le64 vstart;
  570. __le64 vend;
  571. /*
  572. * profile to convert to, single is denoted by
  573. * BTRFS_AVAIL_ALLOC_BIT_SINGLE
  574. */
  575. __le64 target;
  576. /* BTRFS_BALANCE_ARGS_* */
  577. __le64 flags;
  578. /*
  579. * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
  580. * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
  581. * and maximum
  582. */
  583. union {
  584. __le64 limit;
  585. struct {
  586. __le32 limit_min;
  587. __le32 limit_max;
  588. };
  589. };
  590. /*
  591. * Process chunks that cross stripes_min..stripes_max devices,
  592. * BTRFS_BALANCE_ARGS_STRIPES_RANGE
  593. */
  594. __le32 stripes_min;
  595. __le32 stripes_max;
  596. __le64 unused[6];
  597. } __attribute__ ((__packed__));
  598. /*
  599. * store balance parameters to disk so that balance can be properly
  600. * resumed after crash or unmount
  601. */
  602. struct btrfs_balance_item {
  603. /* BTRFS_BALANCE_* */
  604. __le64 flags;
  605. struct btrfs_disk_balance_args data;
  606. struct btrfs_disk_balance_args meta;
  607. struct btrfs_disk_balance_args sys;
  608. __le64 unused[4];
  609. } __attribute__ ((__packed__));
  610. enum {
  611. BTRFS_FILE_EXTENT_INLINE = 0,
  612. BTRFS_FILE_EXTENT_REG = 1,
  613. BTRFS_FILE_EXTENT_PREALLOC = 2,
  614. BTRFS_NR_FILE_EXTENT_TYPES = 3,
  615. };
  616. struct btrfs_file_extent_item {
  617. /*
  618. * transaction id that created this extent
  619. */
  620. __le64 generation;
  621. /*
  622. * max number of bytes to hold this extent in ram
  623. * when we split a compressed extent we can't know how big
  624. * each of the resulting pieces will be. So, this is
  625. * an upper limit on the size of the extent in ram instead of
  626. * an exact limit.
  627. */
  628. __le64 ram_bytes;
  629. /*
  630. * 32 bits for the various ways we might encode the data,
  631. * including compression and encryption. If any of these
  632. * are set to something a given disk format doesn't understand
  633. * it is treated like an incompat flag for reading and writing,
  634. * but not for stat.
  635. */
  636. __u8 compression;
  637. __u8 encryption;
  638. __le16 other_encoding; /* spare for later use */
  639. /* are we __inline__ data or a real extent? */
  640. __u8 type;
  641. /*
  642. * disk space consumed by the extent, checksum blocks are included
  643. * in these numbers
  644. *
  645. * At this offset in the structure, the __inline__ extent data start.
  646. */
  647. __le64 disk_bytenr;
  648. __le64 disk_num_bytes;
  649. /*
  650. * the logical offset in file blocks (no csums)
  651. * this extent record is for. This allows a file extent to point
  652. * into the middle of an existing extent on disk, sharing it
  653. * between two snapshots (useful if some bytes in the middle of the
  654. * extent have changed
  655. */
  656. __le64 offset;
  657. /*
  658. * the logical number of file blocks (no csums included). This
  659. * always reflects the size uncompressed and without encoding.
  660. */
  661. __le64 num_bytes;
  662. } __attribute__ ((__packed__));
  663. struct btrfs_csum_item {
  664. __u8 csum;
  665. } __attribute__ ((__packed__));
  666. struct btrfs_dev_stats_item {
  667. /*
  668. * grow this item struct at the end for future enhancements and keep
  669. * the existing values unchanged
  670. */
  671. __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
  672. } __attribute__ ((__packed__));
  673. #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
  674. #define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
  675. struct btrfs_dev_replace_item {
  676. /*
  677. * grow this item struct at the end for future enhancements and keep
  678. * the existing values unchanged
  679. */
  680. __le64 src_devid;
  681. __le64 cursor_left;
  682. __le64 cursor_right;
  683. __le64 cont_reading_from_srcdev_mode;
  684. __le64 replace_state;
  685. __le64 time_started;
  686. __le64 time_stopped;
  687. __le64 num_write_errors;
  688. __le64 num_uncorrectable_read_errors;
  689. } __attribute__ ((__packed__));
  690. /* different types of block groups (and chunks) */
  691. #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
  692. #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
  693. #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
  694. #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
  695. #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
  696. #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
  697. #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
  698. #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
  699. #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
  700. #define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
  701. #define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
  702. #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
  703. BTRFS_SPACE_INFO_GLOBAL_RSV)
  704. enum btrfs_raid_types {
  705. BTRFS_RAID_RAID10,
  706. BTRFS_RAID_RAID1,
  707. BTRFS_RAID_DUP,
  708. BTRFS_RAID_RAID0,
  709. BTRFS_RAID_SINGLE,
  710. BTRFS_RAID_RAID5,
  711. BTRFS_RAID_RAID6,
  712. BTRFS_RAID_RAID1C3,
  713. BTRFS_RAID_RAID1C4,
  714. BTRFS_NR_RAID_TYPES
  715. };
  716. #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
  717. BTRFS_BLOCK_GROUP_SYSTEM | \
  718. BTRFS_BLOCK_GROUP_METADATA)
  719. #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
  720. BTRFS_BLOCK_GROUP_RAID1 | \
  721. BTRFS_BLOCK_GROUP_RAID1C3 | \
  722. BTRFS_BLOCK_GROUP_RAID1C4 | \
  723. BTRFS_BLOCK_GROUP_RAID5 | \
  724. BTRFS_BLOCK_GROUP_RAID6 | \
  725. BTRFS_BLOCK_GROUP_DUP | \
  726. BTRFS_BLOCK_GROUP_RAID10)
  727. #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
  728. BTRFS_BLOCK_GROUP_RAID6)
  729. #define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
  730. BTRFS_BLOCK_GROUP_RAID1C3 | \
  731. BTRFS_BLOCK_GROUP_RAID1C4)
  732. /*
  733. * We need a bit for restriper to be able to tell when chunks of type
  734. * SINGLE are available. This "extended" profile format is used in
  735. * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
  736. * (on-disk). The corresponding on-disk bit in chunk.type is reserved
  737. * to avoid remappings between two formats in future.
  738. */
  739. #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
  740. /*
  741. * A fake block group type that is used to communicate global block reserve
  742. * size to userspace via the SPACE_INFO ioctl.
  743. */
  744. #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
  745. #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
  746. BTRFS_AVAIL_ALLOC_BIT_SINGLE)
  747. static __inline__ __u64 chunk_to_extended(__u64 flags)
  748. {
  749. if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
  750. flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
  751. return flags;
  752. }
  753. static __inline__ __u64 extended_to_chunk(__u64 flags)
  754. {
  755. return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
  756. }
  757. struct btrfs_block_group_item {
  758. __le64 used;
  759. __le64 chunk_objectid;
  760. __le64 flags;
  761. } __attribute__ ((__packed__));
  762. struct btrfs_free_space_info {
  763. __le32 extent_count;
  764. __le32 flags;
  765. } __attribute__ ((__packed__));
  766. #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
  767. #define BTRFS_QGROUP_LEVEL_SHIFT 48
  768. static __inline__ __u64 btrfs_qgroup_level(__u64 qgroupid)
  769. {
  770. return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
  771. }
  772. /*
  773. * is subvolume quota turned on?
  774. */
  775. #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
  776. /*
  777. * RESCAN is set during the initialization phase
  778. */
  779. #define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
  780. /*
  781. * Some qgroup entries are known to be out of date,
  782. * either because the configuration has changed in a way that
  783. * makes a rescan necessary, or because the fs has been mounted
  784. * with a non-qgroup-aware version.
  785. * Turning qouta off and on again makes it inconsistent, too.
  786. */
  787. #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
  788. #define BTRFS_QGROUP_STATUS_VERSION 1
  789. struct btrfs_qgroup_status_item {
  790. __le64 version;
  791. /*
  792. * the generation is updated during every commit. As older
  793. * versions of btrfs are not aware of qgroups, it will be
  794. * possible to detect inconsistencies by checking the
  795. * generation on mount time
  796. */
  797. __le64 generation;
  798. /* flag definitions see above */
  799. __le64 flags;
  800. /*
  801. * only used during scanning to record the progress
  802. * of the scan. It contains a logical address
  803. */
  804. __le64 rescan;
  805. } __attribute__ ((__packed__));
  806. struct btrfs_qgroup_info_item {
  807. __le64 generation;
  808. __le64 rfer;
  809. __le64 rfer_cmpr;
  810. __le64 excl;
  811. __le64 excl_cmpr;
  812. } __attribute__ ((__packed__));
  813. struct btrfs_qgroup_limit_item {
  814. /*
  815. * only updated when any of the other values change
  816. */
  817. __le64 flags;
  818. __le64 max_rfer;
  819. __le64 max_excl;
  820. __le64 rsv_rfer;
  821. __le64 rsv_excl;
  822. } __attribute__ ((__packed__));
  823. #endif /* _BTRFS_CTREE_H_ */