btrfs_tree.h 24 KB

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