btrfs_tree.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * From linux/include/uapi/linux/btrfs_tree.h
  4. */
  5. #ifndef __BTRFS_BTRFS_TREE_H__
  6. #define __BTRFS_BTRFS_TREE_H__
  7. #include <common.h>
  8. #define BTRFS_VOL_NAME_MAX 255
  9. #define BTRFS_NAME_MAX 255
  10. #define BTRFS_LABEL_SIZE 256
  11. #define BTRFS_FSID_SIZE 16
  12. #define BTRFS_UUID_SIZE 16
  13. /*
  14. * This header contains the structure definitions and constants used
  15. * by file system objects that can be retrieved using
  16. * the BTRFS_IOC_SEARCH_TREE ioctl. That means basically anything that
  17. * is needed to describe a leaf node's key or item contents.
  18. */
  19. /* holds pointers to all of the tree roots */
  20. #define BTRFS_ROOT_TREE_OBJECTID 1ULL
  21. /* stores information about which extents are in use, and reference counts */
  22. #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
  23. /*
  24. * chunk tree stores translations from logical -> physical block numbering
  25. * the super block points to the chunk tree
  26. */
  27. #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
  28. /*
  29. * stores information about which areas of a given device are in use.
  30. * one per device. The tree of tree roots points to the device tree
  31. */
  32. #define BTRFS_DEV_TREE_OBJECTID 4ULL
  33. /* one per subvolume, storing files and directories */
  34. #define BTRFS_FS_TREE_OBJECTID 5ULL
  35. /* directory objectid inside the root tree */
  36. #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
  37. /* holds checksums of all the data extents */
  38. #define BTRFS_CSUM_TREE_OBJECTID 7ULL
  39. /* holds quota configuration and tracking */
  40. #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
  41. /* for storing items that use the BTRFS_UUID_KEY* types */
  42. #define BTRFS_UUID_TREE_OBJECTID 9ULL
  43. /* tracks free space in block groups. */
  44. #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
  45. /* device stats in the device tree */
  46. #define BTRFS_DEV_STATS_OBJECTID 0ULL
  47. /* for storing balance parameters in the root tree */
  48. #define BTRFS_BALANCE_OBJECTID -4ULL
  49. /* orhpan objectid for tracking unlinked/truncated files */
  50. #define BTRFS_ORPHAN_OBJECTID -5ULL
  51. /* does write ahead logging to speed up fsyncs */
  52. #define BTRFS_TREE_LOG_OBJECTID -6ULL
  53. #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
  54. /* for space balancing */
  55. #define BTRFS_TREE_RELOC_OBJECTID -8ULL
  56. #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
  57. /*
  58. * extent checksums all have this objectid
  59. * this allows them to share the logging tree
  60. * for fsyncs
  61. */
  62. #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
  63. /* For storing free space cache */
  64. #define BTRFS_FREE_SPACE_OBJECTID -11ULL
  65. /*
  66. * The inode number assigned to the special inode for storing
  67. * free ino cache
  68. */
  69. #define BTRFS_FREE_INO_OBJECTID -12ULL
  70. /* dummy objectid represents multiple objectids */
  71. #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
  72. /*
  73. * All files have objectids in this range.
  74. */
  75. #define BTRFS_FIRST_FREE_OBJECTID 256ULL
  76. #define BTRFS_LAST_FREE_OBJECTID -256ULL
  77. #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
  78. /*
  79. * the device items go into the chunk tree. The key is in the form
  80. * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
  81. */
  82. #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
  83. #define BTRFS_BTREE_INODE_OBJECTID 1
  84. #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
  85. #define BTRFS_DEV_REPLACE_DEVID 0ULL
  86. /*
  87. * inode items have the data typically returned from stat and store other
  88. * info about object characteristics. There is one for every file and dir in
  89. * the FS
  90. */
  91. #define BTRFS_INODE_ITEM_KEY 1
  92. #define BTRFS_INODE_REF_KEY 12
  93. #define BTRFS_INODE_EXTREF_KEY 13
  94. #define BTRFS_XATTR_ITEM_KEY 24
  95. #define BTRFS_ORPHAN_ITEM_KEY 48
  96. /* reserve 2-15 close to the inode for later flexibility */
  97. /*
  98. * dir items are the name -> inode pointers in a directory. There is one
  99. * for every name in a directory.
  100. */
  101. #define BTRFS_DIR_LOG_ITEM_KEY 60
  102. #define BTRFS_DIR_LOG_INDEX_KEY 72
  103. #define BTRFS_DIR_ITEM_KEY 84
  104. #define BTRFS_DIR_INDEX_KEY 96
  105. /*
  106. * extent data is for file data
  107. */
  108. #define BTRFS_EXTENT_DATA_KEY 108
  109. /*
  110. * extent csums are stored in a separate tree and hold csums for
  111. * an entire extent on disk.
  112. */
  113. #define BTRFS_EXTENT_CSUM_KEY 128
  114. /*
  115. * root items point to tree roots. They are typically in the root
  116. * tree used by the super block to find all the other trees
  117. */
  118. #define BTRFS_ROOT_ITEM_KEY 132
  119. /*
  120. * root backrefs tie subvols and snapshots to the directory entries that
  121. * reference them
  122. */
  123. #define BTRFS_ROOT_BACKREF_KEY 144
  124. /*
  125. * root refs make a fast index for listing all of the snapshots and
  126. * subvolumes referenced by a given root. They point directly to the
  127. * directory item in the root that references the subvol
  128. */
  129. #define BTRFS_ROOT_REF_KEY 156
  130. /*
  131. * extent items are in the extent map tree. These record which blocks
  132. * are used, and how many references there are to each block
  133. */
  134. #define BTRFS_EXTENT_ITEM_KEY 168
  135. /*
  136. * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
  137. * the length, so we save the level in key->offset instead of the length.
  138. */
  139. #define BTRFS_METADATA_ITEM_KEY 169
  140. #define BTRFS_TREE_BLOCK_REF_KEY 176
  141. #define BTRFS_EXTENT_DATA_REF_KEY 178
  142. #define BTRFS_EXTENT_REF_V0_KEY 180
  143. #define BTRFS_SHARED_BLOCK_REF_KEY 182
  144. #define BTRFS_SHARED_DATA_REF_KEY 184
  145. /*
  146. * block groups give us hints into the extent allocation trees. Which
  147. * blocks are free etc etc
  148. */
  149. #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
  150. /*
  151. * Every block group is represented in the free space tree by a free space info
  152. * item, which stores some accounting information. It is keyed on
  153. * (block_group_start, FREE_SPACE_INFO, block_group_length).
  154. */
  155. #define BTRFS_FREE_SPACE_INFO_KEY 198
  156. /*
  157. * A free space extent tracks an extent of space that is free in a block group.
  158. * It is keyed on (start, FREE_SPACE_EXTENT, length).
  159. */
  160. #define BTRFS_FREE_SPACE_EXTENT_KEY 199
  161. /*
  162. * When a block group becomes very fragmented, we convert it to use bitmaps
  163. * instead of extents. A free space bitmap is keyed on
  164. * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with
  165. * (length / sectorsize) bits.
  166. */
  167. #define BTRFS_FREE_SPACE_BITMAP_KEY 200
  168. #define BTRFS_DEV_EXTENT_KEY 204
  169. #define BTRFS_DEV_ITEM_KEY 216
  170. #define BTRFS_CHUNK_ITEM_KEY 228
  171. /*
  172. * Records the overall state of the qgroups.
  173. * There's only one instance of this key present,
  174. * (0, BTRFS_QGROUP_STATUS_KEY, 0)
  175. */
  176. #define BTRFS_QGROUP_STATUS_KEY 240
  177. /*
  178. * Records the currently used space of the qgroup.
  179. * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
  180. */
  181. #define BTRFS_QGROUP_INFO_KEY 242
  182. /*
  183. * Contains the user configured limits for the qgroup.
  184. * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
  185. */
  186. #define BTRFS_QGROUP_LIMIT_KEY 244
  187. /*
  188. * Records the child-parent relationship of qgroups. For
  189. * each relation, 2 keys are present:
  190. * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
  191. * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
  192. */
  193. #define BTRFS_QGROUP_RELATION_KEY 246
  194. /*
  195. * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.
  196. */
  197. #define BTRFS_BALANCE_ITEM_KEY 248
  198. /*
  199. * The key type for tree items that are stored persistently, but do not need to
  200. * exist for extended period of time. The items can exist in any tree.
  201. *
  202. * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
  203. *
  204. * Existing items:
  205. *
  206. * - balance status item
  207. * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
  208. */
  209. #define BTRFS_TEMPORARY_ITEM_KEY 248
  210. /*
  211. * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY
  212. */
  213. #define BTRFS_DEV_STATS_KEY 249
  214. /*
  215. * The key type for tree items that are stored persistently and usually exist
  216. * for a long period, eg. filesystem lifetime. The item kinds can be status
  217. * information, stats or preference values. The item can exist in any tree.
  218. *
  219. * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
  220. *
  221. * Existing items:
  222. *
  223. * - device statistics, store IO stats in the device tree, one key for all
  224. * stats
  225. * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
  226. */
  227. #define BTRFS_PERSISTENT_ITEM_KEY 249
  228. /*
  229. * Persistantly stores the device replace state in the device tree.
  230. * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
  231. */
  232. #define BTRFS_DEV_REPLACE_KEY 250
  233. /*
  234. * Stores items that allow to quickly map UUIDs to something else.
  235. * These items are part of the filesystem UUID tree.
  236. * The key is built like this:
  237. * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
  238. */
  239. #if BTRFS_UUID_SIZE != 16
  240. #error "UUID items require BTRFS_UUID_SIZE == 16!"
  241. #endif
  242. #define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
  243. #define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
  244. * received subvols */
  245. /*
  246. * string items are for debugging. They just store a short string of
  247. * data in the FS
  248. */
  249. #define BTRFS_STRING_ITEM_KEY 253
  250. /* 32 bytes in various csum fields */
  251. #define BTRFS_CSUM_SIZE 32
  252. /* csum types */
  253. #define BTRFS_CSUM_TYPE_CRC32 0
  254. /*
  255. * flags definitions for directory entry item type
  256. *
  257. * Used by:
  258. * struct btrfs_dir_item.type
  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. struct btrfs_key {
  284. __u64 objectid;
  285. __u8 type;
  286. __u64 offset;
  287. } __attribute__ ((__packed__));
  288. struct btrfs_dev_item {
  289. /* the internal btrfs device id */
  290. __u64 devid;
  291. /* size of the device */
  292. __u64 total_bytes;
  293. /* bytes used */
  294. __u64 bytes_used;
  295. /* optimal io alignment for this device */
  296. __u32 io_align;
  297. /* optimal io width for this device */
  298. __u32 io_width;
  299. /* minimal io size for this device */
  300. __u32 sector_size;
  301. /* type and info about this device */
  302. __u64 type;
  303. /* expected generation for this device */
  304. __u64 generation;
  305. /*
  306. * starting byte of this partition on the device,
  307. * to allow for stripe alignment in the future
  308. */
  309. __u64 start_offset;
  310. /* grouping information for allocation decisions */
  311. __u32 dev_group;
  312. /* seek speed 0-100 where 100 is fastest */
  313. __u8 seek_speed;
  314. /* bandwidth 0-100 where 100 is fastest */
  315. __u8 bandwidth;
  316. /* btrfs generated uuid for this device */
  317. __u8 uuid[BTRFS_UUID_SIZE];
  318. /* uuid of FS who owns this device */
  319. __u8 fsid[BTRFS_UUID_SIZE];
  320. } __attribute__ ((__packed__));
  321. struct btrfs_stripe {
  322. __u64 devid;
  323. __u64 offset;
  324. __u8 dev_uuid[BTRFS_UUID_SIZE];
  325. } __attribute__ ((__packed__));
  326. struct btrfs_chunk {
  327. /* size of this chunk in bytes */
  328. __u64 length;
  329. /* objectid of the root referencing this chunk */
  330. __u64 owner;
  331. __u64 stripe_len;
  332. __u64 type;
  333. /* optimal io alignment for this chunk */
  334. __u32 io_align;
  335. /* optimal io width for this chunk */
  336. __u32 io_width;
  337. /* minimal io size for this chunk */
  338. __u32 sector_size;
  339. /* 2^16 stripes is quite a lot, a second limit is the size of a single
  340. * item in the btree
  341. */
  342. __u16 num_stripes;
  343. /* sub stripes only matter for raid10 */
  344. __u16 sub_stripes;
  345. struct btrfs_stripe stripe;
  346. /* additional stripes go here */
  347. } __attribute__ ((__packed__));
  348. #define BTRFS_FREE_SPACE_EXTENT 1
  349. #define BTRFS_FREE_SPACE_BITMAP 2
  350. struct btrfs_free_space_entry {
  351. __u64 offset;
  352. __u64 bytes;
  353. __u8 type;
  354. } __attribute__ ((__packed__));
  355. struct btrfs_free_space_header {
  356. struct btrfs_key location;
  357. __u64 generation;
  358. __u64 num_entries;
  359. __u64 num_bitmaps;
  360. } __attribute__ ((__packed__));
  361. #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
  362. #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
  363. /* Super block flags */
  364. /* Errors detected */
  365. #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
  366. #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
  367. #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
  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. __u64 refs;
  374. __u64 generation;
  375. __u64 flags;
  376. } __attribute__ ((__packed__));
  377. #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
  378. #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
  379. /* following flags only apply to tree blocks */
  380. /* use full backrefs for extent pointers in the block */
  381. #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
  382. /*
  383. * this flag is only used internally by scrub and may be changed at any time
  384. * it is only declared here to avoid collisions
  385. */
  386. #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
  387. struct btrfs_tree_block_info {
  388. struct btrfs_key key;
  389. __u8 level;
  390. } __attribute__ ((__packed__));
  391. struct btrfs_extent_data_ref {
  392. __u64 root;
  393. __u64 objectid;
  394. __u64 offset;
  395. __u32 count;
  396. } __attribute__ ((__packed__));
  397. struct btrfs_shared_data_ref {
  398. __u32 count;
  399. } __attribute__ ((__packed__));
  400. struct btrfs_extent_inline_ref {
  401. __u8 type;
  402. __u64 offset;
  403. } __attribute__ ((__packed__));
  404. /* dev extents record free space on individual devices. The owner
  405. * field points back to the chunk allocation mapping tree that allocated
  406. * the extent. The chunk tree uuid field is a way to double check the owner
  407. */
  408. struct btrfs_dev_extent {
  409. __u64 chunk_tree;
  410. __u64 chunk_objectid;
  411. __u64 chunk_offset;
  412. __u64 length;
  413. __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  414. } __attribute__ ((__packed__));
  415. struct btrfs_inode_ref {
  416. __u64 index;
  417. __u16 name_len;
  418. /* name goes here */
  419. } __attribute__ ((__packed__));
  420. struct btrfs_inode_extref {
  421. __u64 parent_objectid;
  422. __u64 index;
  423. __u16 name_len;
  424. __u8 name[0];
  425. /* name goes here */
  426. } __attribute__ ((__packed__));
  427. struct btrfs_timespec {
  428. __u64 sec;
  429. __u32 nsec;
  430. } __attribute__ ((__packed__));
  431. struct btrfs_inode_item {
  432. /* nfs style generation number */
  433. __u64 generation;
  434. /* transid that last touched this inode */
  435. __u64 transid;
  436. __u64 size;
  437. __u64 nbytes;
  438. __u64 block_group;
  439. __u32 nlink;
  440. __u32 uid;
  441. __u32 gid;
  442. __u32 mode;
  443. __u64 rdev;
  444. __u64 flags;
  445. /* modification sequence number for NFS */
  446. __u64 sequence;
  447. /*
  448. * a little future expansion, for more than this we can
  449. * just grow the inode item and version it
  450. */
  451. __u64 reserved[4];
  452. struct btrfs_timespec atime;
  453. struct btrfs_timespec ctime;
  454. struct btrfs_timespec mtime;
  455. struct btrfs_timespec otime;
  456. } __attribute__ ((__packed__));
  457. struct btrfs_dir_log_item {
  458. __u64 end;
  459. } __attribute__ ((__packed__));
  460. struct btrfs_dir_item {
  461. struct btrfs_key location;
  462. __u64 transid;
  463. __u16 data_len;
  464. __u16 name_len;
  465. __u8 type;
  466. } __attribute__ ((__packed__));
  467. #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
  468. /*
  469. * Internal in-memory flag that a subvolume has been marked for deletion but
  470. * still visible as a directory
  471. */
  472. #define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
  473. struct btrfs_root_item {
  474. struct btrfs_inode_item inode;
  475. __u64 generation;
  476. __u64 root_dirid;
  477. __u64 bytenr;
  478. __u64 byte_limit;
  479. __u64 bytes_used;
  480. __u64 last_snapshot;
  481. __u64 flags;
  482. __u32 refs;
  483. struct btrfs_key drop_progress;
  484. __u8 drop_level;
  485. __u8 level;
  486. /*
  487. * The following fields appear after subvol_uuids+subvol_times
  488. * were introduced.
  489. */
  490. /*
  491. * This generation number is used to test if the new fields are valid
  492. * and up to date while reading the root item. Every time the root item
  493. * is written out, the "generation" field is copied into this field. If
  494. * anyone ever mounted the fs with an older kernel, we will have
  495. * mismatching generation values here and thus must invalidate the
  496. * new fields. See btrfs_update_root and btrfs_find_last_root for
  497. * details.
  498. * the offset of generation_v2 is also used as the start for the memset
  499. * when invalidating the fields.
  500. */
  501. __u64 generation_v2;
  502. __u8 uuid[BTRFS_UUID_SIZE];
  503. __u8 parent_uuid[BTRFS_UUID_SIZE];
  504. __u8 received_uuid[BTRFS_UUID_SIZE];
  505. __u64 ctransid; /* updated when an inode changes */
  506. __u64 otransid; /* trans when created */
  507. __u64 stransid; /* trans when sent. non-zero for received subvol */
  508. __u64 rtransid; /* trans when received. non-zero for received subvol */
  509. struct btrfs_timespec ctime;
  510. struct btrfs_timespec otime;
  511. struct btrfs_timespec stime;
  512. struct btrfs_timespec rtime;
  513. __u64 reserved[8]; /* for future */
  514. } __attribute__ ((__packed__));
  515. /*
  516. * this is used for both forward and backward root refs
  517. */
  518. struct btrfs_root_ref {
  519. __u64 dirid;
  520. __u64 sequence;
  521. __u16 name_len;
  522. } __attribute__ ((__packed__));
  523. #define BTRFS_FILE_EXTENT_INLINE 0
  524. #define BTRFS_FILE_EXTENT_REG 1
  525. #define BTRFS_FILE_EXTENT_PREALLOC 2
  526. enum btrfs_compression_type {
  527. BTRFS_COMPRESS_NONE = 0,
  528. BTRFS_COMPRESS_ZLIB = 1,
  529. BTRFS_COMPRESS_LZO = 2,
  530. BTRFS_COMPRESS_ZSTD = 3,
  531. BTRFS_COMPRESS_TYPES = 3,
  532. BTRFS_COMPRESS_LAST = 4,
  533. };
  534. struct btrfs_file_extent_item {
  535. /*
  536. * transaction id that created this extent
  537. */
  538. __u64 generation;
  539. /*
  540. * max number of bytes to hold this extent in ram
  541. * when we split a compressed extent we can't know how big
  542. * each of the resulting pieces will be. So, this is
  543. * an upper limit on the size of the extent in ram instead of
  544. * an exact limit.
  545. */
  546. __u64 ram_bytes;
  547. /*
  548. * 32 bits for the various ways we might encode the data,
  549. * including compression and encryption. If any of these
  550. * are set to something a given disk format doesn't understand
  551. * it is treated like an incompat flag for reading and writing,
  552. * but not for stat.
  553. */
  554. __u8 compression;
  555. __u8 encryption;
  556. __u16 other_encoding; /* spare for later use */
  557. /* are we inline data or a real extent? */
  558. __u8 type;
  559. /*
  560. * disk space consumed by the extent, checksum blocks are included
  561. * in these numbers
  562. *
  563. * At this offset in the structure, the inline extent data start.
  564. */
  565. __u64 disk_bytenr;
  566. __u64 disk_num_bytes;
  567. /*
  568. * the logical offset in file blocks (no csums)
  569. * this extent record is for. This allows a file extent to point
  570. * into the middle of an existing extent on disk, sharing it
  571. * between two snapshots (useful if some bytes in the middle of the
  572. * extent have changed
  573. */
  574. __u64 offset;
  575. /*
  576. * the logical number of file blocks (no csums included). This
  577. * always reflects the size uncompressed and without encoding.
  578. */
  579. __u64 num_bytes;
  580. } __attribute__ ((__packed__));
  581. struct btrfs_csum_item {
  582. __u8 csum;
  583. } __attribute__ ((__packed__));
  584. /* different types of block groups (and chunks) */
  585. #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
  586. #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
  587. #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
  588. #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
  589. #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
  590. #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
  591. #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
  592. #define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
  593. #define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
  594. #define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
  595. BTRFS_SPACE_INFO_GLOBAL_RSV)
  596. enum btrfs_raid_types {
  597. BTRFS_RAID_RAID10,
  598. BTRFS_RAID_RAID1,
  599. BTRFS_RAID_DUP,
  600. BTRFS_RAID_RAID0,
  601. BTRFS_RAID_SINGLE,
  602. BTRFS_RAID_RAID5,
  603. BTRFS_RAID_RAID6,
  604. BTRFS_NR_RAID_TYPES
  605. };
  606. #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
  607. BTRFS_BLOCK_GROUP_SYSTEM | \
  608. BTRFS_BLOCK_GROUP_METADATA)
  609. #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
  610. BTRFS_BLOCK_GROUP_RAID1 | \
  611. BTRFS_BLOCK_GROUP_RAID5 | \
  612. BTRFS_BLOCK_GROUP_RAID6 | \
  613. BTRFS_BLOCK_GROUP_DUP | \
  614. BTRFS_BLOCK_GROUP_RAID10)
  615. #define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
  616. BTRFS_BLOCK_GROUP_RAID6)
  617. /*
  618. * We need a bit for restriper to be able to tell when chunks of type
  619. * SINGLE are available. This "extended" profile format is used in
  620. * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
  621. * (on-disk). The corresponding on-disk bit in chunk.type is reserved
  622. * to avoid remappings between two formats in future.
  623. */
  624. #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
  625. /*
  626. * A fake block group type that is used to communicate global block reserve
  627. * size to userspace via the SPACE_INFO ioctl.
  628. */
  629. #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
  630. #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
  631. BTRFS_AVAIL_ALLOC_BIT_SINGLE)
  632. #endif /* __BTRFS_BTRFS_TREE_H__ */