ctree.h 22 KB

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