ctree.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. #ifndef __BTRFS__
  2. #define __BTRFS__
  3. #include "list.h"
  4. #include "kerncompat.h"
  5. struct btrfs_trans_handle;
  6. #define BTRFS_MAGIC "_BtRfS_M"
  7. #define BTRFS_ROOT_TREE_OBJECTID 1
  8. #define BTRFS_EXTENT_TREE_OBJECTID 2
  9. #define BTRFS_INODE_MAP_OBJECTID 3
  10. #define BTRFS_FS_TREE_OBJECTID 4
  11. /*
  12. * the key defines the order in the tree, and so it also defines (optimal)
  13. * block layout. objectid corresonds to the inode number. The flags
  14. * tells us things about the object, and is a kind of stream selector.
  15. * so for a given inode, keys with flags of 1 might refer to the inode
  16. * data, flags of 2 may point to file data in the btree and flags == 3
  17. * may point to extents.
  18. *
  19. * offset is the starting byte offset for this key in the stream.
  20. *
  21. * btrfs_disk_key is in disk byte order. struct btrfs_key is always
  22. * in cpu native order. Otherwise they are identical and their sizes
  23. * should be the same (ie both packed)
  24. */
  25. struct btrfs_disk_key {
  26. __le64 objectid;
  27. __le32 flags;
  28. __le64 offset;
  29. } __attribute__ ((__packed__));
  30. struct btrfs_key {
  31. u64 objectid;
  32. u32 flags;
  33. u64 offset;
  34. } __attribute__ ((__packed__));
  35. /*
  36. * every tree block (leaf or node) starts with this header.
  37. */
  38. struct btrfs_header {
  39. u8 fsid[16]; /* FS specific uuid */
  40. __le64 blocknr; /* which block this node is supposed to live in */
  41. __le64 parentid; /* objectid of the tree root */
  42. __le32 csum;
  43. __le32 ham;
  44. __le16 nritems;
  45. __le16 flags;
  46. /* generation flags to be added */
  47. } __attribute__ ((__packed__));
  48. #define BTRFS_MAX_LEVEL 8
  49. #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
  50. sizeof(struct btrfs_header)) / \
  51. (sizeof(struct btrfs_disk_key) + sizeof(u64)))
  52. #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
  53. #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
  54. struct btrfs_buffer;
  55. /*
  56. * the super block basically lists the main trees of the FS
  57. * it currently lacks any block count etc etc
  58. */
  59. struct btrfs_super_block {
  60. u8 fsid[16]; /* FS specific uuid */
  61. __le64 blocknr; /* this block number */
  62. __le32 csum;
  63. __le64 magic;
  64. __le32 blocksize;
  65. __le64 generation;
  66. __le64 root;
  67. __le64 total_blocks;
  68. __le64 blocks_used;
  69. } __attribute__ ((__packed__));
  70. /*
  71. * A leaf is full of items. offset and size tell us where to find
  72. * the item in the leaf (relative to the start of the data area)
  73. */
  74. struct btrfs_item {
  75. struct btrfs_disk_key key;
  76. __le32 offset;
  77. __le16 size;
  78. } __attribute__ ((__packed__));
  79. /*
  80. * leaves have an item area and a data area:
  81. * [item0, item1....itemN] [free space] [dataN...data1, data0]
  82. *
  83. * The data is separate from the items to get the keys closer together
  84. * during searches.
  85. */
  86. struct btrfs_leaf {
  87. struct btrfs_header header;
  88. struct btrfs_item items[];
  89. } __attribute__ ((__packed__));
  90. /*
  91. * all non-leaf blocks are nodes, they hold only keys and pointers to
  92. * other blocks
  93. */
  94. struct btrfs_key_ptr {
  95. struct btrfs_disk_key key;
  96. __le64 blockptr;
  97. } __attribute__ ((__packed__));
  98. struct btrfs_node {
  99. struct btrfs_header header;
  100. struct btrfs_key_ptr ptrs[];
  101. } __attribute__ ((__packed__));
  102. /*
  103. * btrfs_paths remember the path taken from the root down to the leaf.
  104. * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
  105. * to any other levels that are present.
  106. *
  107. * The slots array records the index of the item or block pointer
  108. * used while walking the tree.
  109. */
  110. struct btrfs_path {
  111. struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
  112. int slots[BTRFS_MAX_LEVEL];
  113. };
  114. /*
  115. * items in the extent btree are used to record the objectid of the
  116. * owner of the block and the number of references
  117. */
  118. struct btrfs_extent_item {
  119. __le32 refs;
  120. __le64 owner;
  121. } __attribute__ ((__packed__));
  122. struct btrfs_inode_timespec {
  123. __le32 sec;
  124. __le32 nsec;
  125. } __attribute__ ((__packed__));
  126. /*
  127. * there is no padding here on purpose. If you want to extent the inode,
  128. * make a new item type
  129. */
  130. struct btrfs_inode_item {
  131. __le64 generation;
  132. __le64 size;
  133. __le64 nblocks;
  134. __le32 nlink;
  135. __le32 uid;
  136. __le32 gid;
  137. __le32 mode;
  138. __le32 rdev;
  139. __le16 flags;
  140. __le16 compat_flags;
  141. struct btrfs_inode_timespec atime;
  142. struct btrfs_inode_timespec ctime;
  143. struct btrfs_inode_timespec mtime;
  144. struct btrfs_inode_timespec otime;
  145. } __attribute__ ((__packed__));
  146. /* inline data is just a blob of bytes */
  147. struct btrfs_inline_data_item {
  148. u8 data;
  149. } __attribute__ ((__packed__));
  150. struct btrfs_dir_item {
  151. __le64 objectid;
  152. __le16 flags;
  153. __le16 name_len;
  154. u8 type;
  155. } __attribute__ ((__packed__));
  156. struct btrfs_root_item {
  157. __le64 blocknr;
  158. __le32 flags;
  159. __le64 block_limit;
  160. __le64 blocks_used;
  161. __le32 refs;
  162. } __attribute__ ((__packed__));
  163. struct btrfs_file_extent_item {
  164. /*
  165. * disk space consumed by the extent, checksum blocks are included
  166. * in these numbers
  167. */
  168. __le64 disk_blocknr;
  169. __le64 disk_num_blocks;
  170. /*
  171. * the logical offset in file bytes (no csums)
  172. * this extent record is for. This allows a file extent to point
  173. * into the middle of an existing extent on disk, sharing it
  174. * between two snapshots (useful if some bytes in the middle of the
  175. * extent have changed
  176. */
  177. __le64 offset;
  178. /*
  179. * the logical number of file blocks (no csums included)
  180. */
  181. __le64 num_blocks;
  182. } __attribute__ ((__packed__));
  183. struct btrfs_inode_map_item {
  184. struct btrfs_disk_key key;
  185. } __attribute__ ((__packed__));
  186. struct btrfs_fs_info {
  187. struct btrfs_root *fs_root;
  188. struct btrfs_root *extent_root;
  189. struct btrfs_root *tree_root;
  190. struct btrfs_root *inode_root;
  191. struct btrfs_key current_insert;
  192. struct btrfs_key last_insert;
  193. struct radix_tree_root cache_radix;
  194. struct radix_tree_root pinned_radix;
  195. struct list_head trans;
  196. struct list_head cache;
  197. u64 last_inode_alloc;
  198. u64 last_inode_alloc_dirid;
  199. u64 generation;
  200. int cache_size;
  201. int fp;
  202. struct btrfs_trans_handle *running_transaction;
  203. struct btrfs_super_block *disk_super;
  204. };
  205. /*
  206. * in ram representation of the tree. extent_root is used for all allocations
  207. * and for the extent tree extent_root root. current_insert is used
  208. * only for the extent tree.
  209. */
  210. struct btrfs_root {
  211. struct btrfs_buffer *node;
  212. struct btrfs_buffer *commit_root;
  213. struct btrfs_root_item root_item;
  214. struct btrfs_key root_key;
  215. struct btrfs_fs_info *fs_info;
  216. u32 blocksize;
  217. int ref_cows;
  218. u32 type;
  219. };
  220. /* the lower bits in the key flags defines the item type */
  221. #define BTRFS_KEY_TYPE_MAX 256
  222. #define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1)
  223. /*
  224. * inode items have the data typically returned from stat and store other
  225. * info about object characteristics. There is one for every file and dir in
  226. * the FS
  227. */
  228. #define BTRFS_INODE_ITEM_KEY 1
  229. /*
  230. * dir items are the name -> inode pointers in a directory. There is one
  231. * for every name in a directory.
  232. */
  233. #define BTRFS_DIR_ITEM_KEY 2
  234. /*
  235. * inline data is file data that fits in the btree.
  236. */
  237. #define BTRFS_INLINE_DATA_KEY 3
  238. /*
  239. * extent data is for data that can't fit in the btree. It points to
  240. * a (hopefully) huge chunk of disk
  241. */
  242. #define BTRFS_EXTENT_DATA_KEY 4
  243. /*
  244. * root items point to tree roots. There are typically in the root
  245. * tree used by the super block to find all the other trees
  246. */
  247. #define BTRFS_ROOT_ITEM_KEY 5
  248. /*
  249. * extent items are in the extent map tree. These record which blocks
  250. * are used, and how many references there are to each block
  251. */
  252. #define BTRFS_EXTENT_ITEM_KEY 6
  253. /*
  254. * the inode map records which inode numbers are in use and where
  255. * they actually live on disk
  256. */
  257. #define BTRFS_INODE_MAP_ITEM_KEY 7
  258. /*
  259. * string items are for debugging. They just store a short string of
  260. * data in the FS
  261. */
  262. #define BTRFS_STRING_ITEM_KEY 8
  263. static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
  264. {
  265. return le64_to_cpu(i->generation);
  266. }
  267. static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
  268. u64 val)
  269. {
  270. i->generation = cpu_to_le64(val);
  271. }
  272. static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
  273. {
  274. return le64_to_cpu(i->size);
  275. }
  276. static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
  277. {
  278. i->size = cpu_to_le64(val);
  279. }
  280. static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
  281. {
  282. return le64_to_cpu(i->nblocks);
  283. }
  284. static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
  285. {
  286. i->nblocks = cpu_to_le64(val);
  287. }
  288. static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
  289. {
  290. return le32_to_cpu(i->nlink);
  291. }
  292. static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
  293. {
  294. i->nlink = cpu_to_le32(val);
  295. }
  296. static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
  297. {
  298. return le32_to_cpu(i->uid);
  299. }
  300. static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
  301. {
  302. i->uid = cpu_to_le32(val);
  303. }
  304. static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
  305. {
  306. return le32_to_cpu(i->gid);
  307. }
  308. static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
  309. {
  310. i->gid = cpu_to_le32(val);
  311. }
  312. static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
  313. {
  314. return le32_to_cpu(i->mode);
  315. }
  316. static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
  317. {
  318. i->mode = cpu_to_le32(val);
  319. }
  320. static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
  321. {
  322. return le32_to_cpu(i->rdev);
  323. }
  324. static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
  325. {
  326. i->rdev = cpu_to_le32(val);
  327. }
  328. static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
  329. {
  330. return le16_to_cpu(i->flags);
  331. }
  332. static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
  333. {
  334. i->flags = cpu_to_le16(val);
  335. }
  336. static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
  337. {
  338. return le16_to_cpu(i->compat_flags);
  339. }
  340. static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
  341. u16 val)
  342. {
  343. i->compat_flags = cpu_to_le16(val);
  344. }
  345. static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
  346. {
  347. return le64_to_cpu(ei->owner);
  348. }
  349. static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
  350. {
  351. ei->owner = cpu_to_le64(val);
  352. }
  353. static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
  354. {
  355. return le32_to_cpu(ei->refs);
  356. }
  357. static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
  358. {
  359. ei->refs = cpu_to_le32(val);
  360. }
  361. static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
  362. {
  363. return le64_to_cpu(n->ptrs[nr].blockptr);
  364. }
  365. static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
  366. u64 val)
  367. {
  368. n->ptrs[nr].blockptr = cpu_to_le64(val);
  369. }
  370. static inline u32 btrfs_item_offset(struct btrfs_item *item)
  371. {
  372. return le32_to_cpu(item->offset);
  373. }
  374. static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
  375. {
  376. item->offset = cpu_to_le32(val);
  377. }
  378. static inline u32 btrfs_item_end(struct btrfs_item *item)
  379. {
  380. return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
  381. }
  382. static inline u16 btrfs_item_size(struct btrfs_item *item)
  383. {
  384. return le16_to_cpu(item->size);
  385. }
  386. static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
  387. {
  388. item->size = cpu_to_le16(val);
  389. }
  390. static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d)
  391. {
  392. return le64_to_cpu(d->objectid);
  393. }
  394. static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val)
  395. {
  396. d->objectid = cpu_to_le64(val);
  397. }
  398. static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
  399. {
  400. return le16_to_cpu(d->flags);
  401. }
  402. static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
  403. {
  404. d->flags = cpu_to_le16(val);
  405. }
  406. static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
  407. {
  408. return d->type;
  409. }
  410. static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
  411. {
  412. d->type = val;
  413. }
  414. static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
  415. {
  416. return le16_to_cpu(d->name_len);
  417. }
  418. static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
  419. {
  420. d->name_len = cpu_to_le16(val);
  421. }
  422. static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
  423. struct btrfs_disk_key *disk)
  424. {
  425. cpu->offset = le64_to_cpu(disk->offset);
  426. cpu->flags = le32_to_cpu(disk->flags);
  427. cpu->objectid = le64_to_cpu(disk->objectid);
  428. }
  429. static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
  430. struct btrfs_key *cpu)
  431. {
  432. disk->offset = cpu_to_le64(cpu->offset);
  433. disk->flags = cpu_to_le32(cpu->flags);
  434. disk->objectid = cpu_to_le64(cpu->objectid);
  435. }
  436. static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
  437. {
  438. return le64_to_cpu(disk->objectid);
  439. }
  440. static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
  441. u64 val)
  442. {
  443. disk->objectid = cpu_to_le64(val);
  444. }
  445. static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
  446. {
  447. return le64_to_cpu(disk->offset);
  448. }
  449. static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
  450. u64 val)
  451. {
  452. disk->offset = cpu_to_le64(val);
  453. }
  454. static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
  455. {
  456. return le32_to_cpu(disk->flags);
  457. }
  458. static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
  459. u32 val)
  460. {
  461. disk->flags = cpu_to_le32(val);
  462. }
  463. static inline u32 btrfs_key_type(struct btrfs_key *key)
  464. {
  465. return key->flags & BTRFS_KEY_TYPE_MASK;
  466. }
  467. static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
  468. {
  469. return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK;
  470. }
  471. static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type)
  472. {
  473. BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
  474. key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
  475. }
  476. static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type)
  477. {
  478. u32 flags = btrfs_disk_key_flags(key);
  479. BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
  480. flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
  481. btrfs_set_disk_key_flags(key, flags);
  482. }
  483. static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
  484. {
  485. return le64_to_cpu(h->blocknr);
  486. }
  487. static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
  488. {
  489. h->blocknr = cpu_to_le64(blocknr);
  490. }
  491. static inline u64 btrfs_header_parentid(struct btrfs_header *h)
  492. {
  493. return le64_to_cpu(h->parentid);
  494. }
  495. static inline void btrfs_set_header_parentid(struct btrfs_header *h,
  496. u64 parentid)
  497. {
  498. h->parentid = cpu_to_le64(parentid);
  499. }
  500. static inline u16 btrfs_header_nritems(struct btrfs_header *h)
  501. {
  502. return le16_to_cpu(h->nritems);
  503. }
  504. static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
  505. {
  506. h->nritems = cpu_to_le16(val);
  507. }
  508. static inline u16 btrfs_header_flags(struct btrfs_header *h)
  509. {
  510. return le16_to_cpu(h->flags);
  511. }
  512. static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
  513. {
  514. h->flags = cpu_to_le16(val);
  515. }
  516. static inline int btrfs_header_level(struct btrfs_header *h)
  517. {
  518. return btrfs_header_flags(h) & (BTRFS_MAX_LEVEL - 1);
  519. }
  520. static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
  521. {
  522. u16 flags;
  523. BUG_ON(level > BTRFS_MAX_LEVEL);
  524. flags = btrfs_header_flags(h) & ~(BTRFS_MAX_LEVEL - 1);
  525. btrfs_set_header_flags(h, flags | level);
  526. }
  527. static inline int btrfs_is_leaf(struct btrfs_node *n)
  528. {
  529. return (btrfs_header_level(&n->header) == 0);
  530. }
  531. static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
  532. {
  533. return le64_to_cpu(item->blocknr);
  534. }
  535. static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
  536. {
  537. item->blocknr = cpu_to_le64(val);
  538. }
  539. static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
  540. {
  541. return le32_to_cpu(item->refs);
  542. }
  543. static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
  544. {
  545. item->refs = cpu_to_le32(val);
  546. }
  547. static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
  548. {
  549. return le64_to_cpu(s->blocknr);
  550. }
  551. static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
  552. {
  553. s->blocknr = cpu_to_le64(val);
  554. }
  555. static inline u64 btrfs_super_root(struct btrfs_super_block *s)
  556. {
  557. return le64_to_cpu(s->root);
  558. }
  559. static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
  560. {
  561. s->root = cpu_to_le64(val);
  562. }
  563. static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
  564. {
  565. return le64_to_cpu(s->total_blocks);
  566. }
  567. static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
  568. u64 val)
  569. {
  570. s->total_blocks = cpu_to_le64(val);
  571. }
  572. static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
  573. {
  574. return le64_to_cpu(s->blocks_used);
  575. }
  576. static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
  577. u64 val)
  578. {
  579. s->blocks_used = cpu_to_le64(val);
  580. }
  581. static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
  582. {
  583. return le32_to_cpu(s->blocksize);
  584. }
  585. static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
  586. u32 val)
  587. {
  588. s->blocksize = cpu_to_le32(val);
  589. }
  590. static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
  591. {
  592. return (u8 *)l->items;
  593. }
  594. static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
  595. *e)
  596. {
  597. return le64_to_cpu(e->disk_blocknr);
  598. }
  599. static inline void btrfs_set_file_extent_disk_blocknr(struct
  600. btrfs_file_extent_item
  601. *e, u64 val)
  602. {
  603. e->disk_blocknr = cpu_to_le64(val);
  604. }
  605. static inline u64 btrfs_file_extent_disk_num_blocks(struct
  606. btrfs_file_extent_item *e)
  607. {
  608. return le64_to_cpu(e->disk_num_blocks);
  609. }
  610. static inline void btrfs_set_file_extent_disk_num_blocks(struct
  611. btrfs_file_extent_item
  612. *e, u64 val)
  613. {
  614. e->disk_num_blocks = cpu_to_le64(val);
  615. }
  616. static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
  617. {
  618. return le64_to_cpu(e->offset);
  619. }
  620. static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
  621. *e, u64 val)
  622. {
  623. e->offset = cpu_to_le64(val);
  624. }
  625. static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
  626. *e)
  627. {
  628. return le64_to_cpu(e->num_blocks);
  629. }
  630. static inline void btrfs_set_file_extent_num_blocks(struct
  631. btrfs_file_extent_item *e,
  632. u64 val)
  633. {
  634. e->num_blocks = cpu_to_le64(val);
  635. }
  636. /* helper function to cast into the data area of the leaf. */
  637. #define btrfs_item_ptr(leaf, slot, type) \
  638. ((type *)(btrfs_leaf_data(leaf) + \
  639. btrfs_item_offset((leaf)->items + (slot))))
  640. struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
  641. struct btrfs_root *root);
  642. int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  643. struct btrfs_buffer *buf);
  644. int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
  645. *root, u64 blocknr, u64 num_blocks, int pin);
  646. int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
  647. *root, struct btrfs_key *key, struct btrfs_path *p, int
  648. ins_len, int cow);
  649. void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
  650. void btrfs_init_path(struct btrfs_path *p);
  651. int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  652. struct btrfs_path *path);
  653. int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
  654. *root, struct btrfs_key *key, void *data, u32 data_size);
  655. int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
  656. *root, struct btrfs_path *path, struct btrfs_key
  657. *cpu_key, u32 data_size);
  658. int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
  659. int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
  660. int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
  661. *root, struct btrfs_buffer *snap);
  662. int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
  663. btrfs_root *root);
  664. int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  665. struct btrfs_key *key);
  666. int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
  667. *root, struct btrfs_key *key, struct btrfs_root_item
  668. *item);
  669. int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
  670. *root, struct btrfs_key *key, struct btrfs_root_item
  671. *item);
  672. int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
  673. btrfs_root_item *item, struct btrfs_key *key);
  674. int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
  675. *root, char *name, int name_len, u64 dir, u64
  676. objectid, u8 type);
  677. int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
  678. *root, struct btrfs_path *path, u64 dir, char *name,
  679. int name_len, int mod);
  680. int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
  681. char *name, int name_len);
  682. int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
  683. struct btrfs_root *fs_root,
  684. u64 dirid, u64 *objectid);
  685. int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
  686. struct btrfs_root *root,
  687. u64 objectid, struct btrfs_key *location);
  688. int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
  689. struct btrfs_root *root, struct btrfs_path *path,
  690. u64 objectid, int mod);
  691. int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  692. *root, u64 objectid, struct btrfs_inode_item
  693. *inode_item);
  694. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  695. *root, struct btrfs_path *path, u64 objectid, int mod);
  696. #endif