btrfs_tree.h 20 KB

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