ctree.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. /*
  2. * Copyright (C) 2007 Oracle. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #ifndef __BTRFS__
  19. #define __BTRFS__
  20. #include <linux/fs.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/completion.h>
  23. #include <asm/kmap_types.h>
  24. #include "bit-radix.h"
  25. #include "extent_map.h"
  26. struct btrfs_trans_handle;
  27. struct btrfs_transaction;
  28. extern struct kmem_cache *btrfs_trans_handle_cachep;
  29. extern struct kmem_cache *btrfs_transaction_cachep;
  30. extern struct kmem_cache *btrfs_bit_radix_cachep;
  31. extern struct kmem_cache *btrfs_path_cachep;
  32. #define BTRFS_MAGIC "_B2RfS_M"
  33. #define BTRFS_ROOT_TREE_OBJECTID 1ULL
  34. #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
  35. #define BTRFS_FS_TREE_OBJECTID 3ULL
  36. #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
  37. #define BTRFS_FIRST_FREE_OBJECTID 5ULL
  38. /*
  39. * we can actually store much bigger names, but lets not confuse the rest
  40. * of linux
  41. */
  42. #define BTRFS_NAME_LEN 255
  43. /* 32 bytes in various csum fields */
  44. #define BTRFS_CSUM_SIZE 32
  45. /* four bytes for CRC32 */
  46. #define BTRFS_CRC32_SIZE 4
  47. #define BTRFS_EMPTY_DIR_SIZE 6
  48. #define BTRFS_FT_UNKNOWN 0
  49. #define BTRFS_FT_REG_FILE 1
  50. #define BTRFS_FT_DIR 2
  51. #define BTRFS_FT_CHRDEV 3
  52. #define BTRFS_FT_BLKDEV 4
  53. #define BTRFS_FT_FIFO 5
  54. #define BTRFS_FT_SOCK 6
  55. #define BTRFS_FT_SYMLINK 7
  56. #define BTRFS_FT_MAX 8
  57. /*
  58. * the key defines the order in the tree, and so it also defines (optimal)
  59. * block layout. objectid corresonds to the inode number. The flags
  60. * tells us things about the object, and is a kind of stream selector.
  61. * so for a given inode, keys with flags of 1 might refer to the inode
  62. * data, flags of 2 may point to file data in the btree and flags == 3
  63. * may point to extents.
  64. *
  65. * offset is the starting byte offset for this key in the stream.
  66. *
  67. * btrfs_disk_key is in disk byte order. struct btrfs_key is always
  68. * in cpu native order. Otherwise they are identical and their sizes
  69. * should be the same (ie both packed)
  70. */
  71. struct btrfs_disk_key {
  72. __le64 objectid;
  73. u8 type;
  74. __le64 offset;
  75. } __attribute__ ((__packed__));
  76. struct btrfs_key {
  77. u64 objectid;
  78. u8 type;
  79. u64 offset;
  80. } __attribute__ ((__packed__));
  81. #define BTRFS_FSID_SIZE 16
  82. /*
  83. * every tree block (leaf or node) starts with this header.
  84. */
  85. struct btrfs_header {
  86. u8 csum[BTRFS_CSUM_SIZE];
  87. u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
  88. __le64 blocknr; /* which block this node is supposed to live in */
  89. __le64 generation;
  90. __le64 owner;
  91. __le32 nritems;
  92. __le16 flags;
  93. u8 level;
  94. } __attribute__ ((__packed__));
  95. #define BTRFS_MAX_LEVEL 8
  96. #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
  97. sizeof(struct btrfs_header)) / \
  98. (sizeof(struct btrfs_disk_key) + sizeof(u64)))
  99. #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
  100. #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
  101. #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
  102. sizeof(struct btrfs_item) - \
  103. sizeof(struct btrfs_file_extent_item))
  104. /*
  105. * the super block basically lists the main trees of the FS
  106. * it currently lacks any block count etc etc
  107. */
  108. struct btrfs_super_block {
  109. u8 csum[BTRFS_CSUM_SIZE];
  110. /* the first 3 fields must match struct btrfs_header */
  111. u8 fsid[16]; /* FS specific uuid */
  112. __le64 blocknr; /* this block number */
  113. __le64 magic;
  114. __le64 generation;
  115. __le64 root;
  116. __le64 total_blocks;
  117. __le64 blocks_used;
  118. __le64 root_dir_objectid;
  119. __le32 sectorsize;
  120. __le32 nodesize;
  121. __le32 leafsize;
  122. } __attribute__ ((__packed__));
  123. /*
  124. * A leaf is full of items. offset and size tell us where to find
  125. * the item in the leaf (relative to the start of the data area)
  126. */
  127. struct btrfs_item {
  128. struct btrfs_disk_key key;
  129. __le32 offset;
  130. __le32 size;
  131. } __attribute__ ((__packed__));
  132. /*
  133. * leaves have an item area and a data area:
  134. * [item0, item1....itemN] [free space] [dataN...data1, data0]
  135. *
  136. * The data is separate from the items to get the keys closer together
  137. * during searches.
  138. */
  139. struct btrfs_leaf {
  140. struct btrfs_header header;
  141. struct btrfs_item items[];
  142. } __attribute__ ((__packed__));
  143. /*
  144. * all non-leaf blocks are nodes, they hold only keys and pointers to
  145. * other blocks
  146. */
  147. struct btrfs_key_ptr {
  148. struct btrfs_disk_key key;
  149. __le64 blockptr;
  150. } __attribute__ ((__packed__));
  151. struct btrfs_node {
  152. struct btrfs_header header;
  153. struct btrfs_key_ptr ptrs[];
  154. } __attribute__ ((__packed__));
  155. /*
  156. * btrfs_paths remember the path taken from the root down to the leaf.
  157. * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
  158. * to any other levels that are present.
  159. *
  160. * The slots array records the index of the item or block pointer
  161. * used while walking the tree.
  162. */
  163. struct btrfs_path {
  164. struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
  165. int slots[BTRFS_MAX_LEVEL];
  166. int reada;
  167. int lowest_level;
  168. };
  169. /*
  170. * items in the extent btree are used to record the objectid of the
  171. * owner of the block and the number of references
  172. */
  173. struct btrfs_extent_item {
  174. __le32 refs;
  175. __le64 owner;
  176. } __attribute__ ((__packed__));
  177. struct btrfs_inode_timespec {
  178. __le64 sec;
  179. __le32 nsec;
  180. } __attribute__ ((__packed__));
  181. /*
  182. * there is no padding here on purpose. If you want to extent the inode,
  183. * make a new item type
  184. */
  185. struct btrfs_inode_item {
  186. __le64 generation;
  187. __le64 size;
  188. __le64 nblocks;
  189. __le64 block_group;
  190. __le32 nlink;
  191. __le32 uid;
  192. __le32 gid;
  193. __le32 mode;
  194. __le32 rdev;
  195. __le16 flags;
  196. __le16 compat_flags;
  197. struct btrfs_inode_timespec atime;
  198. struct btrfs_inode_timespec ctime;
  199. struct btrfs_inode_timespec mtime;
  200. struct btrfs_inode_timespec otime;
  201. } __attribute__ ((__packed__));
  202. struct btrfs_dir_item {
  203. struct btrfs_disk_key location;
  204. __le16 flags;
  205. __le16 name_len;
  206. u8 type;
  207. } __attribute__ ((__packed__));
  208. struct btrfs_root_item {
  209. struct btrfs_inode_item inode;
  210. __le64 root_dirid;
  211. __le64 blocknr;
  212. __le64 block_limit;
  213. __le64 blocks_used;
  214. __le32 flags;
  215. __le32 refs;
  216. struct btrfs_disk_key drop_progress;
  217. u8 drop_level;
  218. } __attribute__ ((__packed__));
  219. #define BTRFS_FILE_EXTENT_REG 0
  220. #define BTRFS_FILE_EXTENT_INLINE 1
  221. struct btrfs_file_extent_item {
  222. __le64 generation;
  223. u8 type;
  224. /*
  225. * disk space consumed by the extent, checksum blocks are included
  226. * in these numbers
  227. */
  228. __le64 disk_blocknr;
  229. __le64 disk_num_blocks;
  230. /*
  231. * the logical offset in file blocks (no csums)
  232. * this extent record is for. This allows a file extent to point
  233. * into the middle of an existing extent on disk, sharing it
  234. * between two snapshots (useful if some bytes in the middle of the
  235. * extent have changed
  236. */
  237. __le64 offset;
  238. /*
  239. * the logical number of file blocks (no csums included)
  240. */
  241. __le64 num_blocks;
  242. } __attribute__ ((__packed__));
  243. struct btrfs_csum_item {
  244. u8 csum;
  245. } __attribute__ ((__packed__));
  246. /* tag for the radix tree of block groups in ram */
  247. #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
  248. #define BTRFS_BLOCK_GROUP_DATA 1
  249. struct btrfs_block_group_item {
  250. __le64 used;
  251. u8 flags;
  252. } __attribute__ ((__packed__));
  253. struct btrfs_block_group_cache {
  254. struct btrfs_key key;
  255. struct btrfs_block_group_item item;
  256. int data;
  257. int cached;
  258. };
  259. struct btrfs_fs_info {
  260. u8 fsid[BTRFS_FSID_SIZE];
  261. struct btrfs_root *extent_root;
  262. struct btrfs_root *tree_root;
  263. struct radix_tree_root fs_roots_radix;
  264. struct extent_map_tree free_space_cache;
  265. struct extent_map_tree block_group_cache;
  266. struct extent_map_tree pinned_extents;
  267. struct extent_map_tree pending_del;
  268. struct extent_map_tree extent_ins;
  269. u64 generation;
  270. u64 last_trans_committed;
  271. struct btrfs_transaction *running_transaction;
  272. struct btrfs_super_block super_copy;
  273. struct extent_buffer *sb_buffer;
  274. struct super_block *sb;
  275. struct inode *btree_inode;
  276. struct mutex trans_mutex;
  277. struct mutex fs_mutex;
  278. struct list_head trans_list;
  279. struct list_head dead_roots;
  280. struct delayed_work trans_work;
  281. struct kobject super_kobj;
  282. struct completion kobj_unregister;
  283. int do_barriers;
  284. int closing;
  285. };
  286. /*
  287. * in ram representation of the tree. extent_root is used for all allocations
  288. * and for the extent tree extent_root root.
  289. */
  290. struct btrfs_root {
  291. struct extent_buffer *node;
  292. struct extent_buffer *commit_root;
  293. struct btrfs_root_item root_item;
  294. struct btrfs_key root_key;
  295. struct btrfs_fs_info *fs_info;
  296. struct inode *inode;
  297. struct kobject root_kobj;
  298. struct completion kobj_unregister;
  299. struct rw_semaphore snap_sem;
  300. u64 objectid;
  301. u64 last_trans;
  302. /* data allocations are done in sectorsize units */
  303. u32 sectorsize;
  304. /* node allocations are done in nodesize units */
  305. u32 nodesize;
  306. /* leaf allocations are done in leafsize units */
  307. u32 leafsize;
  308. u32 type;
  309. u64 highest_inode;
  310. u64 last_inode_alloc;
  311. int ref_cows;
  312. struct btrfs_key defrag_progress;
  313. int defrag_running;
  314. int defrag_level;
  315. char *name;
  316. };
  317. /*
  318. * inode items have the data typically returned from stat and store other
  319. * info about object characteristics. There is one for every file and dir in
  320. * the FS
  321. */
  322. #define BTRFS_INODE_ITEM_KEY 1
  323. /* reserve 2-15 close to the inode for later flexibility */
  324. /*
  325. * dir items are the name -> inode pointers in a directory. There is one
  326. * for every name in a directory.
  327. */
  328. #define BTRFS_DIR_ITEM_KEY 16
  329. #define BTRFS_DIR_INDEX_KEY 17
  330. /*
  331. * extent data is for file data
  332. */
  333. #define BTRFS_EXTENT_DATA_KEY 18
  334. /*
  335. * csum items have the checksums for data in the extents
  336. */
  337. #define BTRFS_CSUM_ITEM_KEY 19
  338. /* reserve 20-31 for other file stuff */
  339. /*
  340. * root items point to tree roots. There are typically in the root
  341. * tree used by the super block to find all the other trees
  342. */
  343. #define BTRFS_ROOT_ITEM_KEY 32
  344. /*
  345. * extent items are in the extent map tree. These record which blocks
  346. * are used, and how many references there are to each block
  347. */
  348. #define BTRFS_EXTENT_ITEM_KEY 33
  349. /*
  350. * block groups give us hints into the extent allocation trees. Which
  351. * blocks are free etc etc
  352. */
  353. #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
  354. /*
  355. * string items are for debugging. They just store a short string of
  356. * data in the FS
  357. */
  358. #define BTRFS_STRING_ITEM_KEY 253
  359. /* some macros to generate set/get funcs for the struct fields. This
  360. * assumes there is a lefoo_to_cpu for every type, so lets make a simple
  361. * one for u8:
  362. */
  363. #define le8_to_cpu(v) (v)
  364. #define cpu_to_le8(v) (v)
  365. #define __le8 u8
  366. #define read_eb_member(eb, ptr, type, member, result) ( \
  367. read_extent_buffer(eb, (char *)(result), \
  368. ((unsigned long)(ptr)) + \
  369. offsetof(type, member), \
  370. sizeof(((type *)0)->member)))
  371. #define write_eb_member(eb, ptr, type, member, result) ( \
  372. write_extent_buffer(eb, (char *)(result), \
  373. ((unsigned long)(ptr)) + \
  374. offsetof(type, member), \
  375. sizeof(((type *)0)->member)))
  376. #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
  377. static inline u##bits btrfs_##name(struct extent_buffer *eb, \
  378. type *s) \
  379. { \
  380. int err; \
  381. char *map_token; \
  382. char *kaddr; \
  383. unsigned long map_start; \
  384. unsigned long map_len; \
  385. unsigned long offset = (unsigned long)s + \
  386. offsetof(type, member); \
  387. err = map_extent_buffer(eb, offset, \
  388. sizeof(((type *)0)->member), \
  389. &map_token, &kaddr, \
  390. &map_start, &map_len, KM_USER0); \
  391. if (!err) { \
  392. __le##bits *tmp = (__le##bits *)(kaddr + offset - \
  393. map_start); \
  394. u##bits res = le##bits##_to_cpu(*tmp); \
  395. unmap_extent_buffer(eb, map_token, KM_USER0); \
  396. return res; \
  397. } else { \
  398. __le##bits res; \
  399. read_eb_member(eb, s, type, member, &res); \
  400. return le##bits##_to_cpu(res); \
  401. } \
  402. } \
  403. static inline void btrfs_set_##name(struct extent_buffer *eb, \
  404. type *s, u##bits val) \
  405. { \
  406. int err; \
  407. char *map_token; \
  408. char *kaddr; \
  409. unsigned long map_start; \
  410. unsigned long map_len; \
  411. unsigned long offset = (unsigned long)s + \
  412. offsetof(type, member); \
  413. err = map_extent_buffer(eb, offset, \
  414. sizeof(((type *)0)->member), \
  415. &map_token, &kaddr, \
  416. &map_start, &map_len, KM_USER0); \
  417. if (!err) { \
  418. __le##bits *tmp = (__le##bits *)(kaddr + offset - \
  419. map_start); \
  420. *tmp = cpu_to_le##bits(val); \
  421. unmap_extent_buffer(eb, map_token, KM_USER0); \
  422. } else { \
  423. val = cpu_to_le##bits(val); \
  424. write_eb_member(eb, s, type, member, &val); \
  425. } \
  426. }
  427. #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
  428. static inline u##bits btrfs_##name(struct extent_buffer *eb) \
  429. { \
  430. int err; \
  431. char *map_token; \
  432. char *kaddr; \
  433. unsigned long map_start; \
  434. unsigned long map_len; \
  435. unsigned long offset = offsetof(type, member); \
  436. err = map_extent_buffer(eb, offset, \
  437. sizeof(((type *)0)->member), \
  438. &map_token, &kaddr, \
  439. &map_start, &map_len, KM_USER0); \
  440. if (!err) { \
  441. __le##bits *tmp = (__le##bits *)(kaddr + offset - \
  442. map_start); \
  443. u##bits res = le##bits##_to_cpu(*tmp); \
  444. unmap_extent_buffer(eb, map_token, KM_USER0); \
  445. return res; \
  446. } else { \
  447. __le##bits res; \
  448. read_eb_member(eb, NULL, type, member, &res); \
  449. return le##bits##_to_cpu(res); \
  450. } \
  451. } \
  452. static inline void btrfs_set_##name(struct extent_buffer *eb, \
  453. u##bits val) \
  454. { \
  455. int err; \
  456. char *map_token; \
  457. char *kaddr; \
  458. unsigned long map_start; \
  459. unsigned long map_len; \
  460. unsigned long offset = offsetof(type, member); \
  461. err = map_extent_buffer(eb, offset, \
  462. sizeof(((type *)0)->member), \
  463. &map_token, &kaddr, \
  464. &map_start, &map_len, KM_USER0); \
  465. if (!err) { \
  466. __le##bits *tmp = (__le##bits *)(kaddr + offset - \
  467. map_start); \
  468. *tmp = cpu_to_le##bits(val); \
  469. unmap_extent_buffer(eb, map_token, KM_USER0); \
  470. } else { \
  471. val = cpu_to_le##bits(val); \
  472. write_eb_member(eb, NULL, type, member, &val); \
  473. } \
  474. }
  475. #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
  476. static inline u##bits btrfs_##name(type *s) \
  477. { \
  478. return le##bits##_to_cpu(s->member); \
  479. } \
  480. static inline void btrfs_set_##name(type *s, u##bits val) \
  481. { \
  482. s->member = cpu_to_le##bits(val); \
  483. }
  484. /* struct btrfs_block_group_item */
  485. BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
  486. used, 64);
  487. BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
  488. used, 64);
  489. /* struct btrfs_inode_item */
  490. BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
  491. BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
  492. BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
  493. BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
  494. BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
  495. BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
  496. BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
  497. BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
  498. BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 32);
  499. BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
  500. BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
  501. compat_flags, 16);
  502. static inline struct btrfs_inode_timespec *
  503. btrfs_inode_atime(struct btrfs_inode_item *inode_item)
  504. {
  505. unsigned long ptr = (unsigned long)inode_item;
  506. ptr += offsetof(struct btrfs_inode_item, atime);
  507. return (struct btrfs_inode_timespec *)ptr;
  508. }
  509. static inline struct btrfs_inode_timespec *
  510. btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
  511. {
  512. unsigned long ptr = (unsigned long)inode_item;
  513. ptr += offsetof(struct btrfs_inode_item, mtime);
  514. return (struct btrfs_inode_timespec *)ptr;
  515. }
  516. static inline struct btrfs_inode_timespec *
  517. btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
  518. {
  519. unsigned long ptr = (unsigned long)inode_item;
  520. ptr += offsetof(struct btrfs_inode_item, ctime);
  521. return (struct btrfs_inode_timespec *)ptr;
  522. }
  523. static inline struct btrfs_inode_timespec *
  524. btrfs_inode_otime(struct btrfs_inode_item *inode_item)
  525. {
  526. unsigned long ptr = (unsigned long)inode_item;
  527. ptr += offsetof(struct btrfs_inode_item, otime);
  528. return (struct btrfs_inode_timespec *)ptr;
  529. }
  530. BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_inode_timespec, sec, 64);
  531. BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_inode_timespec, nsec, 32);
  532. /* struct btrfs_extent_item */
  533. BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
  534. BTRFS_SETGET_FUNCS(extent_owner, struct btrfs_extent_item, owner, 32);
  535. BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
  536. refs, 32);
  537. BTRFS_SETGET_STACK_FUNCS(stack_extent_owner, struct btrfs_extent_item,
  538. owner, 32);
  539. /* struct btrfs_node */
  540. BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
  541. static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
  542. {
  543. unsigned long ptr;
  544. ptr = offsetof(struct btrfs_node, ptrs) +
  545. sizeof(struct btrfs_key_ptr) * nr;
  546. return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
  547. }
  548. static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
  549. int nr, u64 val)
  550. {
  551. unsigned long ptr;
  552. ptr = offsetof(struct btrfs_node, ptrs) +
  553. sizeof(struct btrfs_key_ptr) * nr;
  554. btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
  555. }
  556. static unsigned long btrfs_node_key_ptr_offset(int nr)
  557. {
  558. return offsetof(struct btrfs_node, ptrs) +
  559. sizeof(struct btrfs_key_ptr) * nr;
  560. }
  561. static void btrfs_node_key(struct extent_buffer *eb,
  562. struct btrfs_disk_key *disk_key, int nr)
  563. {
  564. unsigned long ptr;
  565. ptr = btrfs_node_key_ptr_offset(nr);
  566. read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
  567. struct btrfs_key_ptr, key, disk_key);
  568. }
  569. static inline void btrfs_set_node_key(struct extent_buffer *eb,
  570. struct btrfs_disk_key *disk_key, int nr)
  571. {
  572. unsigned long ptr;
  573. ptr = btrfs_node_key_ptr_offset(nr);
  574. write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
  575. struct btrfs_key_ptr, key, disk_key);
  576. }
  577. /* struct btrfs_item */
  578. BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
  579. BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
  580. static inline unsigned long btrfs_item_nr_offset(int nr)
  581. {
  582. return offsetof(struct btrfs_leaf, items) +
  583. sizeof(struct btrfs_item) * nr;
  584. }
  585. static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
  586. int nr)
  587. {
  588. return (struct btrfs_item *)btrfs_item_nr_offset(nr);
  589. }
  590. static inline u32 btrfs_item_end(struct extent_buffer *eb,
  591. struct btrfs_item *item)
  592. {
  593. return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
  594. }
  595. static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
  596. {
  597. return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
  598. }
  599. static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
  600. {
  601. return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
  602. }
  603. static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
  604. {
  605. return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
  606. }
  607. static inline void btrfs_item_key(struct extent_buffer *eb,
  608. struct btrfs_disk_key *disk_key, int nr)
  609. {
  610. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  611. read_eb_member(eb, item, struct btrfs_item, key, disk_key);
  612. }
  613. static inline void btrfs_set_item_key(struct extent_buffer *eb,
  614. struct btrfs_disk_key *disk_key, int nr)
  615. {
  616. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  617. write_eb_member(eb, item, struct btrfs_item, key, disk_key);
  618. }
  619. /* struct btrfs_dir_item */
  620. BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, flags, 16);
  621. BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
  622. BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
  623. static inline void btrfs_dir_item_key(struct extent_buffer *eb,
  624. struct btrfs_dir_item *item,
  625. struct btrfs_disk_key *key)
  626. {
  627. read_eb_member(eb, item, struct btrfs_dir_item, location, key);
  628. }
  629. static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
  630. struct btrfs_dir_item *item,
  631. struct btrfs_disk_key *key)
  632. {
  633. write_eb_member(eb, item, struct btrfs_dir_item, location, key);
  634. }
  635. /* struct btrfs_disk_key */
  636. BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
  637. objectid, 64);
  638. BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
  639. BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
  640. static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
  641. struct btrfs_disk_key *disk)
  642. {
  643. cpu->offset = le64_to_cpu(disk->offset);
  644. cpu->type = disk->type;
  645. cpu->objectid = le64_to_cpu(disk->objectid);
  646. }
  647. static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
  648. struct btrfs_key *cpu)
  649. {
  650. disk->offset = cpu_to_le64(cpu->offset);
  651. disk->type = cpu->type;
  652. disk->objectid = cpu_to_le64(cpu->objectid);
  653. }
  654. static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
  655. struct btrfs_key *key, int nr)
  656. {
  657. struct btrfs_disk_key disk_key;
  658. btrfs_node_key(eb, &disk_key, nr);
  659. btrfs_disk_key_to_cpu(key, &disk_key);
  660. }
  661. static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
  662. struct btrfs_key *key, int nr)
  663. {
  664. struct btrfs_disk_key disk_key;
  665. btrfs_item_key(eb, &disk_key, nr);
  666. btrfs_disk_key_to_cpu(key, &disk_key);
  667. }
  668. static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
  669. struct btrfs_dir_item *item,
  670. struct btrfs_key *key)
  671. {
  672. struct btrfs_disk_key disk_key;
  673. btrfs_dir_item_key(eb, item, &disk_key);
  674. btrfs_disk_key_to_cpu(key, &disk_key);
  675. }
  676. static inline u8 btrfs_key_type(struct btrfs_key *key)
  677. {
  678. return key->type;
  679. }
  680. static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
  681. {
  682. key->type = val;
  683. }
  684. /* struct btrfs_header */
  685. BTRFS_SETGET_HEADER_FUNCS(header_blocknr, struct btrfs_header, blocknr, 64);
  686. BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
  687. generation, 64);
  688. BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
  689. BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
  690. BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 16);
  691. BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
  692. static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
  693. {
  694. unsigned long ptr = offsetof(struct btrfs_header, fsid);
  695. return (u8 *)ptr;
  696. }
  697. static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
  698. {
  699. unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
  700. return (u8 *)ptr;
  701. }
  702. static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
  703. {
  704. unsigned long ptr = offsetof(struct btrfs_header, csum);
  705. return (u8 *)ptr;
  706. }
  707. static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
  708. {
  709. return NULL;
  710. }
  711. static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
  712. {
  713. return NULL;
  714. }
  715. static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
  716. {
  717. return NULL;
  718. }
  719. static inline int btrfs_is_leaf(struct extent_buffer *eb)
  720. {
  721. return (btrfs_header_level(eb) == 0);
  722. }
  723. /* struct btrfs_root_item */
  724. BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
  725. BTRFS_SETGET_FUNCS(disk_root_blocknr, struct btrfs_root_item, blocknr, 64);
  726. BTRFS_SETGET_STACK_FUNCS(root_blocknr, struct btrfs_root_item, blocknr, 64);
  727. BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
  728. BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
  729. BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
  730. BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, blocks_used, 64);
  731. BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, block_limit, 64);
  732. /* struct btrfs_super_block */
  733. BTRFS_SETGET_STACK_FUNCS(super_blocknr, struct btrfs_super_block, blocknr, 64);
  734. BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
  735. generation, 64);
  736. BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
  737. BTRFS_SETGET_STACK_FUNCS(super_total_blocks, struct btrfs_super_block,
  738. total_blocks, 64);
  739. BTRFS_SETGET_STACK_FUNCS(super_blocks_used, struct btrfs_super_block,
  740. blocks_used, 64);
  741. BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
  742. sectorsize, 32);
  743. BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
  744. nodesize, 32);
  745. BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
  746. leafsize, 32);
  747. BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
  748. root_dir_objectid, 64);
  749. static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
  750. {
  751. return offsetof(struct btrfs_leaf, items);
  752. }
  753. /* struct btrfs_file_extent_item */
  754. BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
  755. static inline unsigned long btrfs_file_extent_inline_start(struct
  756. btrfs_file_extent_item *e)
  757. {
  758. unsigned long offset = (unsigned long)e;
  759. offset += offsetof(struct btrfs_file_extent_item, disk_blocknr);
  760. return offset;
  761. }
  762. static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
  763. {
  764. return offsetof(struct btrfs_file_extent_item, disk_blocknr) + datasize;
  765. }
  766. static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
  767. struct btrfs_item *e)
  768. {
  769. unsigned long offset;
  770. offset = offsetof(struct btrfs_file_extent_item, disk_blocknr);
  771. return btrfs_item_size(eb, e) - offset;
  772. }
  773. BTRFS_SETGET_FUNCS(file_extent_disk_blocknr, struct btrfs_file_extent_item,
  774. disk_blocknr, 64);
  775. BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
  776. generation, 64);
  777. BTRFS_SETGET_FUNCS(file_extent_disk_num_blocks, struct btrfs_file_extent_item,
  778. disk_num_blocks, 64);
  779. BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
  780. offset, 64);
  781. BTRFS_SETGET_FUNCS(file_extent_num_blocks, struct btrfs_file_extent_item,
  782. num_blocks, 64);
  783. static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
  784. {
  785. return sb->s_fs_info;
  786. }
  787. static inline int btrfs_set_root_name(struct btrfs_root *root,
  788. const char *name, int len)
  789. {
  790. /* if we already have a name just free it */
  791. if (root->name)
  792. kfree(root->name);
  793. root->name = kmalloc(len+1, GFP_KERNEL);
  794. if (!root->name)
  795. return -ENOMEM;
  796. memcpy(root->name, name, len);
  797. root->name[len] ='\0';
  798. return 0;
  799. }
  800. /* helper function to cast into the data area of the leaf. */
  801. #define btrfs_item_ptr(leaf, slot, type) \
  802. ((type *)(btrfs_leaf_data(leaf) + \
  803. btrfs_item_offset_nr(leaf, slot)))
  804. #define btrfs_item_ptr_offset(leaf, slot) \
  805. ((unsigned long)(btrfs_leaf_data(leaf) + \
  806. btrfs_item_offset_nr(leaf, slot)))
  807. /* mount option defines and helpers */
  808. #define BTRFS_MOUNT_SUBVOL 0x000001
  809. #define btrfs_clear_opt(o, opt) o &= ~BTRFS_MOUNT_##opt
  810. #define btrfs_set_opt(o, opt) o |= BTRFS_MOUNT_##opt
  811. #define btrfs_test_opt(sb, opt) (BTRFS_SB(sb)->s_mount_opt & \
  812. BTRFS_MOUNT_##opt)
  813. /* extent-tree.c */
  814. int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
  815. struct btrfs_root *root);
  816. int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy);
  817. struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
  818. btrfs_fs_info *info,
  819. u64 blocknr);
  820. struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
  821. struct btrfs_block_group_cache
  822. *hint, u64 search_start,
  823. int data, int owner);
  824. int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
  825. struct btrfs_root *root);
  826. struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
  827. struct btrfs_root *root, u64 hint,
  828. u64 empty_size);
  829. int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
  830. struct btrfs_root *root, u64 owner,
  831. u64 num_blocks, u64 empty_size, u64 search_start,
  832. u64 search_end, struct btrfs_key *ins, int data);
  833. int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  834. struct extent_buffer *buf);
  835. int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
  836. *root, u64 blocknr, u64 num_blocks, int pin);
  837. int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
  838. struct btrfs_root *root,
  839. struct extent_map_tree *unpin);
  840. int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
  841. struct btrfs_root *root,
  842. u64 blocknr, u64 num_blocks);
  843. int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
  844. struct btrfs_root *root);
  845. int btrfs_free_block_groups(struct btrfs_fs_info *info);
  846. int btrfs_read_block_groups(struct btrfs_root *root);
  847. /* ctree.c */
  848. int btrfs_cow_block(struct btrfs_trans_handle *trans,
  849. struct btrfs_root *root, struct extent_buffer *buf,
  850. struct extent_buffer *parent, int parent_slot,
  851. struct extent_buffer **cow_ret);
  852. int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
  853. *root, struct btrfs_path *path, u32 data_size);
  854. int btrfs_truncate_item(struct btrfs_trans_handle *trans,
  855. struct btrfs_root *root,
  856. struct btrfs_path *path,
  857. u32 new_size);
  858. int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
  859. *root, struct btrfs_key *key, struct btrfs_path *p, int
  860. ins_len, int cow);
  861. int btrfs_realloc_node(struct btrfs_trans_handle *trans,
  862. struct btrfs_root *root, struct extent_buffer *parent,
  863. int cache_only, u64 *last_ret);
  864. void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
  865. struct btrfs_path *btrfs_alloc_path(void);
  866. void btrfs_free_path(struct btrfs_path *p);
  867. void btrfs_init_path(struct btrfs_path *p);
  868. int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  869. struct btrfs_path *path);
  870. int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
  871. *root, struct btrfs_key *key, void *data, u32 data_size);
  872. int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
  873. *root, struct btrfs_path *path, struct btrfs_key
  874. *cpu_key, u32 data_size);
  875. int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
  876. int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
  877. int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
  878. *root);
  879. /* root-item.c */
  880. int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  881. struct btrfs_key *key);
  882. int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
  883. *root, struct btrfs_key *key, struct btrfs_root_item
  884. *item);
  885. int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
  886. *root, struct btrfs_key *key, struct btrfs_root_item
  887. *item);
  888. int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
  889. btrfs_root_item *item, struct btrfs_key *key);
  890. int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
  891. struct btrfs_root *latest_root);
  892. /* dir-item.c */
  893. int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
  894. *root, const char *name, int name_len, u64 dir,
  895. struct btrfs_key *location, u8 type);
  896. struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
  897. struct btrfs_root *root,
  898. struct btrfs_path *path, u64 dir,
  899. const char *name, int name_len,
  900. int mod);
  901. struct btrfs_dir_item *
  902. btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
  903. struct btrfs_root *root,
  904. struct btrfs_path *path, u64 dir,
  905. u64 objectid, const char *name, int name_len,
  906. int mod);
  907. struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
  908. struct btrfs_path *path,
  909. const char *name, int name_len);
  910. int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
  911. struct btrfs_root *root,
  912. struct btrfs_path *path,
  913. struct btrfs_dir_item *di);
  914. /* inode-map.c */
  915. int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
  916. struct btrfs_root *fs_root,
  917. u64 dirid, u64 *objectid);
  918. int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
  919. /* inode-item.c */
  920. int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
  921. struct btrfs_root *root,
  922. struct btrfs_path *path, u64 objectid);
  923. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  924. *root, struct btrfs_path *path,
  925. struct btrfs_key *location, int mod);
  926. /* file-item.c */
  927. int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
  928. struct btrfs_root *root,
  929. u64 objectid, u64 pos, u64 offset,
  930. u64 disk_num_blocks,
  931. u64 num_blocks);
  932. int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
  933. struct btrfs_root *root,
  934. struct btrfs_path *path, u64 objectid,
  935. u64 blocknr, int mod);
  936. int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
  937. struct btrfs_root *root,
  938. u64 objectid, u64 offset,
  939. char *data, size_t len);
  940. struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
  941. struct btrfs_root *root,
  942. struct btrfs_path *path,
  943. u64 objectid, u64 offset,
  944. int cow);
  945. int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
  946. struct btrfs_root *root, struct btrfs_path *path,
  947. u64 isize);
  948. /* inode.c */
  949. int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
  950. int btrfs_readpage(struct file *file, struct page *page);
  951. void btrfs_delete_inode(struct inode *inode);
  952. void btrfs_read_locked_inode(struct inode *inode);
  953. int btrfs_write_inode(struct inode *inode, int wait);
  954. void btrfs_dirty_inode(struct inode *inode);
  955. struct inode *btrfs_alloc_inode(struct super_block *sb);
  956. void btrfs_destroy_inode(struct inode *inode);
  957. int btrfs_init_cachep(void);
  958. void btrfs_destroy_cachep(void);
  959. long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  960. struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
  961. struct btrfs_root *root);
  962. int btrfs_commit_write(struct file *file, struct page *page,
  963. unsigned from, unsigned to);
  964. struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
  965. size_t page_offset, u64 start, u64 end,
  966. int create);
  967. int btrfs_update_inode(struct btrfs_trans_handle *trans,
  968. struct btrfs_root *root,
  969. struct inode *inode);
  970. /* file.c */
  971. int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end);
  972. extern struct file_operations btrfs_file_operations;
  973. int btrfs_drop_extents(struct btrfs_trans_handle *trans,
  974. struct btrfs_root *root, struct inode *inode,
  975. u64 start, u64 end, u64 *hint_block);
  976. /* tree-defrag.c */
  977. int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
  978. struct btrfs_root *root, int cache_only);
  979. /* sysfs.c */
  980. int btrfs_init_sysfs(void);
  981. void btrfs_exit_sysfs(void);
  982. int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
  983. int btrfs_sysfs_add_root(struct btrfs_root *root);
  984. void btrfs_sysfs_del_root(struct btrfs_root *root);
  985. void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
  986. #endif