btrfs_tree.h 24 KB

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