ctree.h 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  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. u64 first_free;
  257. u64 last_alloc;
  258. u64 pinned;
  259. u64 last_prealloc;
  260. int data;
  261. int cached;
  262. };
  263. struct btrfs_fs_info {
  264. u8 fsid[BTRFS_FSID_SIZE];
  265. struct btrfs_root *extent_root;
  266. struct btrfs_root *tree_root;
  267. struct radix_tree_root fs_roots_radix;
  268. struct radix_tree_root pending_del_radix;
  269. struct radix_tree_root pinned_radix;
  270. struct radix_tree_root extent_ins_radix;
  271. struct extent_map_tree free_space_cache;
  272. struct extent_map_tree block_group_cache;
  273. u64 generation;
  274. u64 last_trans_committed;
  275. struct btrfs_transaction *running_transaction;
  276. struct btrfs_super_block super_copy;
  277. struct extent_buffer *sb_buffer;
  278. struct super_block *sb;
  279. struct inode *btree_inode;
  280. struct mutex trans_mutex;
  281. struct mutex fs_mutex;
  282. struct list_head trans_list;
  283. struct list_head dead_roots;
  284. struct delayed_work trans_work;
  285. struct kobject super_kobj;
  286. struct completion kobj_unregister;
  287. int do_barriers;
  288. int closing;
  289. };
  290. /*
  291. * in ram representation of the tree. extent_root is used for all allocations
  292. * and for the extent tree extent_root root.
  293. */
  294. struct btrfs_root {
  295. struct extent_buffer *node;
  296. struct extent_buffer *commit_root;
  297. struct btrfs_root_item root_item;
  298. struct btrfs_key root_key;
  299. struct btrfs_fs_info *fs_info;
  300. struct inode *inode;
  301. struct kobject root_kobj;
  302. struct completion kobj_unregister;
  303. struct rw_semaphore snap_sem;
  304. u64 objectid;
  305. u64 last_trans;
  306. /* data allocations are done in sectorsize units */
  307. u32 sectorsize;
  308. /* node allocations are done in nodesize units */
  309. u32 nodesize;
  310. /* leaf allocations are done in leafsize units */
  311. u32 leafsize;
  312. u32 type;
  313. u64 highest_inode;
  314. u64 last_inode_alloc;
  315. int ref_cows;
  316. struct btrfs_key defrag_progress;
  317. int defrag_running;
  318. int defrag_level;
  319. char *name;
  320. };
  321. /*
  322. * inode items have the data typically returned from stat and store other
  323. * info about object characteristics. There is one for every file and dir in
  324. * the FS
  325. */
  326. #define BTRFS_INODE_ITEM_KEY 1
  327. /* reserve 2-15 close to the inode for later flexibility */
  328. /*
  329. * dir items are the name -> inode pointers in a directory. There is one
  330. * for every name in a directory.
  331. */
  332. #define BTRFS_DIR_ITEM_KEY 16
  333. #define BTRFS_DIR_INDEX_KEY 17
  334. /*
  335. * extent data is for file data
  336. */
  337. #define BTRFS_EXTENT_DATA_KEY 18
  338. /*
  339. * csum items have the checksums for data in the extents
  340. */
  341. #define BTRFS_CSUM_ITEM_KEY 19
  342. /* reserve 20-31 for other file stuff */
  343. /*
  344. * root items point to tree roots. There are typically in the root
  345. * tree used by the super block to find all the other trees
  346. */
  347. #define BTRFS_ROOT_ITEM_KEY 32
  348. /*
  349. * extent items are in the extent map tree. These record which blocks
  350. * are used, and how many references there are to each block
  351. */
  352. #define BTRFS_EXTENT_ITEM_KEY 33
  353. /*
  354. * block groups give us hints into the extent allocation trees. Which
  355. * blocks are free etc etc
  356. */
  357. #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
  358. /*
  359. * string items are for debugging. They just store a short string of
  360. * data in the FS
  361. */
  362. #define BTRFS_STRING_ITEM_KEY 253
  363. /* some macros to generate set/get funcs for the struct fields. This
  364. * assumes there is a lefoo_to_cpu for every type, so lets make a simple
  365. * one for u8:
  366. */
  367. #define le8_to_cpu(v) (v)
  368. #define cpu_to_le8(v) (v)
  369. #define __le8 u8
  370. #define read_eb_member(eb, ptr, type, member, result) ( \
  371. read_extent_buffer(eb, (char *)(result), \
  372. ((unsigned long)(ptr)) + \
  373. offsetof(type, member), \
  374. sizeof(((type *)0)->member)))
  375. #define write_eb_member(eb, ptr, type, member, result) ( \
  376. write_extent_buffer(eb, (char *)(result), \
  377. ((unsigned long)(ptr)) + \
  378. offsetof(type, member), \
  379. sizeof(((type *)0)->member)))
  380. #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
  381. static inline u##bits btrfs_##name(struct extent_buffer *eb, \
  382. type *s) \
  383. { \
  384. int err; \
  385. char *map_token; \
  386. char *kaddr; \
  387. unsigned long map_start; \
  388. unsigned long map_len; \
  389. unsigned long offset = (unsigned long)s + \
  390. offsetof(type, member); \
  391. err = map_extent_buffer(eb, offset, \
  392. sizeof(((type *)0)->member), \
  393. &map_token, &kaddr, \
  394. &map_start, &map_len, KM_USER0); \
  395. if (!err) { \
  396. __le##bits *tmp = (__le##bits *)(kaddr + offset - \
  397. map_start); \
  398. u##bits res = le##bits##_to_cpu(*tmp); \
  399. unmap_extent_buffer(eb, map_token, KM_USER0); \
  400. return res; \
  401. } else { \
  402. __le##bits res; \
  403. read_eb_member(eb, s, type, member, &res); \
  404. return le##bits##_to_cpu(res); \
  405. } \
  406. } \
  407. static inline void btrfs_set_##name(struct extent_buffer *eb, \
  408. type *s, u##bits val) \
  409. { \
  410. int err; \
  411. char *map_token; \
  412. char *kaddr; \
  413. unsigned long map_start; \
  414. unsigned long map_len; \
  415. unsigned long offset = (unsigned long)s + \
  416. offsetof(type, member); \
  417. err = map_extent_buffer(eb, offset, \
  418. sizeof(((type *)0)->member), \
  419. &map_token, &kaddr, \
  420. &map_start, &map_len, KM_USER0); \
  421. if (!err) { \
  422. __le##bits *tmp = (__le##bits *)(kaddr + offset - \
  423. map_start); \
  424. *tmp = cpu_to_le##bits(val); \
  425. unmap_extent_buffer(eb, map_token, KM_USER0); \
  426. } else { \
  427. val = cpu_to_le##bits(val); \
  428. write_eb_member(eb, s, type, member, &val); \
  429. } \
  430. }
  431. #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
  432. static inline u##bits btrfs_##name(struct extent_buffer *eb) \
  433. { \
  434. int err; \
  435. char *map_token; \
  436. char *kaddr; \
  437. unsigned long map_start; \
  438. unsigned long map_len; \
  439. unsigned long offset = offsetof(type, member); \
  440. err = map_extent_buffer(eb, offset, \
  441. sizeof(((type *)0)->member), \
  442. &map_token, &kaddr, \
  443. &map_start, &map_len, KM_USER0); \
  444. if (!err) { \
  445. __le##bits *tmp = (__le##bits *)(kaddr + offset - \
  446. map_start); \
  447. u##bits res = le##bits##_to_cpu(*tmp); \
  448. unmap_extent_buffer(eb, map_token, KM_USER0); \
  449. return res; \
  450. } else { \
  451. __le##bits res; \
  452. read_eb_member(eb, NULL, type, member, &res); \
  453. return le##bits##_to_cpu(res); \
  454. } \
  455. } \
  456. static inline void btrfs_set_##name(struct extent_buffer *eb, \
  457. u##bits val) \
  458. { \
  459. int err; \
  460. char *map_token; \
  461. char *kaddr; \
  462. unsigned long map_start; \
  463. unsigned long map_len; \
  464. unsigned long offset = offsetof(type, member); \
  465. err = map_extent_buffer(eb, offset, \
  466. sizeof(((type *)0)->member), \
  467. &map_token, &kaddr, \
  468. &map_start, &map_len, KM_USER0); \
  469. if (!err) { \
  470. __le##bits *tmp = (__le##bits *)(kaddr + offset - \
  471. map_start); \
  472. *tmp = cpu_to_le##bits(val); \
  473. unmap_extent_buffer(eb, map_token, KM_USER0); \
  474. } else { \
  475. val = cpu_to_le##bits(val); \
  476. write_eb_member(eb, NULL, type, member, &val); \
  477. } \
  478. }
  479. #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
  480. static inline u##bits btrfs_##name(type *s) \
  481. { \
  482. return le##bits##_to_cpu(s->member); \
  483. } \
  484. static inline void btrfs_set_##name(type *s, u##bits val) \
  485. { \
  486. s->member = cpu_to_le##bits(val); \
  487. }
  488. /* struct btrfs_block_group_item */
  489. BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
  490. used, 64);
  491. BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
  492. used, 64);
  493. /* struct btrfs_inode_item */
  494. BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
  495. BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
  496. BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
  497. BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
  498. BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
  499. BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
  500. BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
  501. BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
  502. BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 32);
  503. BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
  504. BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
  505. compat_flags, 16);
  506. static inline struct btrfs_inode_timespec *
  507. btrfs_inode_atime(struct btrfs_inode_item *inode_item)
  508. {
  509. unsigned long ptr = (unsigned long)inode_item;
  510. ptr += offsetof(struct btrfs_inode_item, atime);
  511. return (struct btrfs_inode_timespec *)ptr;
  512. }
  513. static inline struct btrfs_inode_timespec *
  514. btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
  515. {
  516. unsigned long ptr = (unsigned long)inode_item;
  517. ptr += offsetof(struct btrfs_inode_item, mtime);
  518. return (struct btrfs_inode_timespec *)ptr;
  519. }
  520. static inline struct btrfs_inode_timespec *
  521. btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
  522. {
  523. unsigned long ptr = (unsigned long)inode_item;
  524. ptr += offsetof(struct btrfs_inode_item, ctime);
  525. return (struct btrfs_inode_timespec *)ptr;
  526. }
  527. static inline struct btrfs_inode_timespec *
  528. btrfs_inode_otime(struct btrfs_inode_item *inode_item)
  529. {
  530. unsigned long ptr = (unsigned long)inode_item;
  531. ptr += offsetof(struct btrfs_inode_item, otime);
  532. return (struct btrfs_inode_timespec *)ptr;
  533. }
  534. BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_inode_timespec, sec, 64);
  535. BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_inode_timespec, nsec, 32);
  536. /* struct btrfs_extent_item */
  537. BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
  538. BTRFS_SETGET_FUNCS(extent_owner, struct btrfs_extent_item, owner, 32);
  539. BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
  540. refs, 32);
  541. BTRFS_SETGET_STACK_FUNCS(stack_extent_owner, struct btrfs_extent_item,
  542. owner, 32);
  543. /* struct btrfs_node */
  544. BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
  545. static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
  546. {
  547. unsigned long ptr;
  548. ptr = offsetof(struct btrfs_node, ptrs) +
  549. sizeof(struct btrfs_key_ptr) * nr;
  550. return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
  551. }
  552. static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
  553. int nr, u64 val)
  554. {
  555. unsigned long ptr;
  556. ptr = offsetof(struct btrfs_node, ptrs) +
  557. sizeof(struct btrfs_key_ptr) * nr;
  558. btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
  559. }
  560. static unsigned long btrfs_node_key_ptr_offset(int nr)
  561. {
  562. return offsetof(struct btrfs_node, ptrs) +
  563. sizeof(struct btrfs_key_ptr) * nr;
  564. }
  565. static void btrfs_node_key(struct extent_buffer *eb,
  566. struct btrfs_disk_key *disk_key, int nr)
  567. {
  568. unsigned long ptr;
  569. ptr = btrfs_node_key_ptr_offset(nr);
  570. read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
  571. struct btrfs_key_ptr, key, disk_key);
  572. }
  573. static inline void btrfs_set_node_key(struct extent_buffer *eb,
  574. struct btrfs_disk_key *disk_key, int nr)
  575. {
  576. unsigned long ptr;
  577. ptr = btrfs_node_key_ptr_offset(nr);
  578. write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
  579. struct btrfs_key_ptr, key, disk_key);
  580. }
  581. /* struct btrfs_item */
  582. BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
  583. BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
  584. static inline unsigned long btrfs_item_nr_offset(int nr)
  585. {
  586. return offsetof(struct btrfs_leaf, items) +
  587. sizeof(struct btrfs_item) * nr;
  588. }
  589. static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
  590. int nr)
  591. {
  592. return (struct btrfs_item *)btrfs_item_nr_offset(nr);
  593. }
  594. static inline u32 btrfs_item_end(struct extent_buffer *eb,
  595. struct btrfs_item *item)
  596. {
  597. return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
  598. }
  599. static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
  600. {
  601. return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
  602. }
  603. static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
  604. {
  605. return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
  606. }
  607. static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
  608. {
  609. return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
  610. }
  611. static inline void btrfs_item_key(struct extent_buffer *eb,
  612. struct btrfs_disk_key *disk_key, int nr)
  613. {
  614. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  615. read_eb_member(eb, item, struct btrfs_item, key, disk_key);
  616. }
  617. static inline void btrfs_set_item_key(struct extent_buffer *eb,
  618. struct btrfs_disk_key *disk_key, int nr)
  619. {
  620. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  621. write_eb_member(eb, item, struct btrfs_item, key, disk_key);
  622. }
  623. /* struct btrfs_dir_item */
  624. BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, flags, 16);
  625. BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
  626. BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
  627. static inline void btrfs_dir_item_key(struct extent_buffer *eb,
  628. struct btrfs_dir_item *item,
  629. struct btrfs_disk_key *key)
  630. {
  631. read_eb_member(eb, item, struct btrfs_dir_item, location, key);
  632. }
  633. static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
  634. struct btrfs_dir_item *item,
  635. struct btrfs_disk_key *key)
  636. {
  637. write_eb_member(eb, item, struct btrfs_dir_item, location, key);
  638. }
  639. /* struct btrfs_disk_key */
  640. BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
  641. objectid, 64);
  642. BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
  643. BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
  644. static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
  645. struct btrfs_disk_key *disk)
  646. {
  647. cpu->offset = le64_to_cpu(disk->offset);
  648. cpu->type = disk->type;
  649. cpu->objectid = le64_to_cpu(disk->objectid);
  650. }
  651. static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
  652. struct btrfs_key *cpu)
  653. {
  654. disk->offset = cpu_to_le64(cpu->offset);
  655. disk->type = cpu->type;
  656. disk->objectid = cpu_to_le64(cpu->objectid);
  657. }
  658. static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
  659. struct btrfs_key *key, int nr)
  660. {
  661. struct btrfs_disk_key disk_key;
  662. btrfs_node_key(eb, &disk_key, nr);
  663. btrfs_disk_key_to_cpu(key, &disk_key);
  664. }
  665. static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
  666. struct btrfs_key *key, int nr)
  667. {
  668. struct btrfs_disk_key disk_key;
  669. btrfs_item_key(eb, &disk_key, nr);
  670. btrfs_disk_key_to_cpu(key, &disk_key);
  671. }
  672. static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
  673. struct btrfs_dir_item *item,
  674. struct btrfs_key *key)
  675. {
  676. struct btrfs_disk_key disk_key;
  677. btrfs_dir_item_key(eb, item, &disk_key);
  678. btrfs_disk_key_to_cpu(key, &disk_key);
  679. }
  680. static inline u8 btrfs_key_type(struct btrfs_key *key)
  681. {
  682. return key->type;
  683. }
  684. static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
  685. {
  686. key->type = val;
  687. }
  688. /* struct btrfs_header */
  689. BTRFS_SETGET_HEADER_FUNCS(header_blocknr, struct btrfs_header, blocknr, 64);
  690. BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
  691. generation, 64);
  692. BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
  693. BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
  694. BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 16);
  695. BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
  696. static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
  697. {
  698. unsigned long ptr = offsetof(struct btrfs_header, fsid);
  699. return (u8 *)ptr;
  700. }
  701. static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
  702. {
  703. unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
  704. return (u8 *)ptr;
  705. }
  706. static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
  707. {
  708. unsigned long ptr = offsetof(struct btrfs_header, csum);
  709. return (u8 *)ptr;
  710. }
  711. static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
  712. {
  713. return NULL;
  714. }
  715. static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
  716. {
  717. return NULL;
  718. }
  719. static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
  720. {
  721. return NULL;
  722. }
  723. static inline int btrfs_is_leaf(struct extent_buffer *eb)
  724. {
  725. return (btrfs_header_level(eb) == 0);
  726. }
  727. /* struct btrfs_root_item */
  728. BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
  729. BTRFS_SETGET_FUNCS(disk_root_blocknr, struct btrfs_root_item, blocknr, 64);
  730. BTRFS_SETGET_STACK_FUNCS(root_blocknr, struct btrfs_root_item, blocknr, 64);
  731. BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
  732. BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
  733. BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
  734. BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, blocks_used, 64);
  735. BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, block_limit, 64);
  736. /* struct btrfs_super_block */
  737. BTRFS_SETGET_STACK_FUNCS(super_blocknr, struct btrfs_super_block, blocknr, 64);
  738. BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
  739. generation, 64);
  740. BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
  741. BTRFS_SETGET_STACK_FUNCS(super_total_blocks, struct btrfs_super_block,
  742. total_blocks, 64);
  743. BTRFS_SETGET_STACK_FUNCS(super_blocks_used, struct btrfs_super_block,
  744. blocks_used, 64);
  745. BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
  746. sectorsize, 32);
  747. BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
  748. nodesize, 32);
  749. BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
  750. leafsize, 32);
  751. BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
  752. root_dir_objectid, 64);
  753. static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
  754. {
  755. return offsetof(struct btrfs_leaf, items);
  756. }
  757. /* struct btrfs_file_extent_item */
  758. BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
  759. static inline unsigned long btrfs_file_extent_inline_start(struct
  760. btrfs_file_extent_item *e)
  761. {
  762. unsigned long offset = (unsigned long)e;
  763. offset += offsetof(struct btrfs_file_extent_item, disk_blocknr);
  764. return offset;
  765. }
  766. static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
  767. {
  768. return offsetof(struct btrfs_file_extent_item, disk_blocknr) + datasize;
  769. }
  770. static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
  771. struct btrfs_item *e)
  772. {
  773. unsigned long offset;
  774. offset = offsetof(struct btrfs_file_extent_item, disk_blocknr);
  775. return btrfs_item_size(eb, e) - offset;
  776. }
  777. BTRFS_SETGET_FUNCS(file_extent_disk_blocknr, struct btrfs_file_extent_item,
  778. disk_blocknr, 64);
  779. BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
  780. generation, 64);
  781. BTRFS_SETGET_FUNCS(file_extent_disk_num_blocks, struct btrfs_file_extent_item,
  782. disk_num_blocks, 64);
  783. BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
  784. offset, 64);
  785. BTRFS_SETGET_FUNCS(file_extent_num_blocks, struct btrfs_file_extent_item,
  786. num_blocks, 64);
  787. static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
  788. {
  789. return sb->s_fs_info;
  790. }
  791. static inline int btrfs_set_root_name(struct btrfs_root *root,
  792. const char *name, int len)
  793. {
  794. /* if we already have a name just free it */
  795. if (root->name)
  796. kfree(root->name);
  797. root->name = kmalloc(len+1, GFP_KERNEL);
  798. if (!root->name)
  799. return -ENOMEM;
  800. memcpy(root->name, name, len);
  801. root->name[len] ='\0';
  802. return 0;
  803. }
  804. /* helper function to cast into the data area of the leaf. */
  805. #define btrfs_item_ptr(leaf, slot, type) \
  806. ((type *)(btrfs_leaf_data(leaf) + \
  807. btrfs_item_offset_nr(leaf, slot)))
  808. #define btrfs_item_ptr_offset(leaf, slot) \
  809. ((unsigned long)(btrfs_leaf_data(leaf) + \
  810. btrfs_item_offset_nr(leaf, slot)))
  811. /* mount option defines and helpers */
  812. #define BTRFS_MOUNT_SUBVOL 0x000001
  813. #define btrfs_clear_opt(o, opt) o &= ~BTRFS_MOUNT_##opt
  814. #define btrfs_set_opt(o, opt) o |= BTRFS_MOUNT_##opt
  815. #define btrfs_test_opt(sb, opt) (BTRFS_SB(sb)->s_mount_opt & \
  816. BTRFS_MOUNT_##opt)
  817. /* extent-tree.c */
  818. int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
  819. struct btrfs_root *root);
  820. int btrfs_copy_pinned(struct btrfs_root *root, struct radix_tree_root *copy);
  821. struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
  822. btrfs_fs_info *info,
  823. u64 blocknr);
  824. struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
  825. struct btrfs_block_group_cache
  826. *hint, u64 search_start,
  827. int data, int owner);
  828. int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
  829. struct btrfs_root *root);
  830. struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
  831. struct btrfs_root *root, u64 hint,
  832. u64 empty_size);
  833. int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
  834. struct btrfs_root *root, u64 owner,
  835. u64 num_blocks, u64 empty_size, u64 search_start,
  836. u64 search_end, struct btrfs_key *ins, int data);
  837. int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  838. struct extent_buffer *buf);
  839. int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
  840. *root, u64 blocknr, u64 num_blocks, int pin);
  841. int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
  842. struct btrfs_root *root,
  843. struct radix_tree_root *unpin_radix);
  844. int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
  845. struct btrfs_root *root,
  846. u64 blocknr, u64 num_blocks);
  847. int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
  848. struct btrfs_root *root);
  849. int btrfs_free_block_groups(struct btrfs_fs_info *info);
  850. int btrfs_read_block_groups(struct btrfs_root *root);
  851. /* ctree.c */
  852. int btrfs_cow_block(struct btrfs_trans_handle *trans,
  853. struct btrfs_root *root, struct extent_buffer *buf,
  854. struct extent_buffer *parent, int parent_slot,
  855. struct extent_buffer **cow_ret);
  856. int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
  857. *root, struct btrfs_path *path, u32 data_size);
  858. int btrfs_truncate_item(struct btrfs_trans_handle *trans,
  859. struct btrfs_root *root,
  860. struct btrfs_path *path,
  861. u32 new_size);
  862. int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
  863. *root, struct btrfs_key *key, struct btrfs_path *p, int
  864. ins_len, int cow);
  865. int btrfs_realloc_node(struct btrfs_trans_handle *trans,
  866. struct btrfs_root *root, struct extent_buffer *parent,
  867. int cache_only, u64 *last_ret);
  868. void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
  869. struct btrfs_path *btrfs_alloc_path(void);
  870. void btrfs_free_path(struct btrfs_path *p);
  871. void btrfs_init_path(struct btrfs_path *p);
  872. int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  873. struct btrfs_path *path);
  874. int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
  875. *root, struct btrfs_key *key, void *data, u32 data_size);
  876. int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
  877. *root, struct btrfs_path *path, struct btrfs_key
  878. *cpu_key, u32 data_size);
  879. int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
  880. int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
  881. int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
  882. *root);
  883. /* root-item.c */
  884. int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  885. struct btrfs_key *key);
  886. int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
  887. *root, struct btrfs_key *key, struct btrfs_root_item
  888. *item);
  889. int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
  890. *root, struct btrfs_key *key, struct btrfs_root_item
  891. *item);
  892. int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
  893. btrfs_root_item *item, struct btrfs_key *key);
  894. int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
  895. struct btrfs_root *latest_root);
  896. /* dir-item.c */
  897. int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
  898. *root, const char *name, int name_len, u64 dir,
  899. struct btrfs_key *location, u8 type);
  900. struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
  901. struct btrfs_root *root,
  902. struct btrfs_path *path, u64 dir,
  903. const char *name, int name_len,
  904. int mod);
  905. struct btrfs_dir_item *
  906. btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
  907. struct btrfs_root *root,
  908. struct btrfs_path *path, u64 dir,
  909. u64 objectid, const char *name, int name_len,
  910. int mod);
  911. struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
  912. struct btrfs_path *path,
  913. const char *name, int name_len);
  914. int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
  915. struct btrfs_root *root,
  916. struct btrfs_path *path,
  917. struct btrfs_dir_item *di);
  918. /* inode-map.c */
  919. int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
  920. struct btrfs_root *fs_root,
  921. u64 dirid, u64 *objectid);
  922. int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
  923. /* inode-item.c */
  924. int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
  925. struct btrfs_root *root,
  926. struct btrfs_path *path, u64 objectid);
  927. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  928. *root, struct btrfs_path *path,
  929. struct btrfs_key *location, int mod);
  930. /* file-item.c */
  931. int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
  932. struct btrfs_root *root,
  933. u64 objectid, u64 pos, u64 offset,
  934. u64 disk_num_blocks,
  935. u64 num_blocks);
  936. int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
  937. struct btrfs_root *root,
  938. struct btrfs_path *path, u64 objectid,
  939. u64 blocknr, int mod);
  940. int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
  941. struct btrfs_root *root,
  942. u64 objectid, u64 offset,
  943. char *data, size_t len);
  944. struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
  945. struct btrfs_root *root,
  946. struct btrfs_path *path,
  947. u64 objectid, u64 offset,
  948. int cow);
  949. int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
  950. struct btrfs_root *root, struct btrfs_path *path,
  951. u64 isize);
  952. /* inode.c */
  953. int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
  954. int btrfs_readpage(struct file *file, struct page *page);
  955. void btrfs_delete_inode(struct inode *inode);
  956. void btrfs_read_locked_inode(struct inode *inode);
  957. int btrfs_write_inode(struct inode *inode, int wait);
  958. void btrfs_dirty_inode(struct inode *inode);
  959. struct inode *btrfs_alloc_inode(struct super_block *sb);
  960. void btrfs_destroy_inode(struct inode *inode);
  961. int btrfs_init_cachep(void);
  962. void btrfs_destroy_cachep(void);
  963. long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  964. struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
  965. struct btrfs_root *root);
  966. int btrfs_commit_write(struct file *file, struct page *page,
  967. unsigned from, unsigned to);
  968. struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
  969. size_t page_offset, u64 start, u64 end,
  970. int create);
  971. int btrfs_update_inode(struct btrfs_trans_handle *trans,
  972. struct btrfs_root *root,
  973. struct inode *inode);
  974. /* file.c */
  975. int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end);
  976. extern struct file_operations btrfs_file_operations;
  977. int btrfs_drop_extents(struct btrfs_trans_handle *trans,
  978. struct btrfs_root *root, struct inode *inode,
  979. u64 start, u64 end, u64 *hint_block);
  980. /* tree-defrag.c */
  981. int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
  982. struct btrfs_root *root, int cache_only);
  983. /* sysfs.c */
  984. int btrfs_init_sysfs(void);
  985. void btrfs_exit_sysfs(void);
  986. int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
  987. int btrfs_sysfs_add_root(struct btrfs_root *root);
  988. void btrfs_sysfs_del_root(struct btrfs_root *root);
  989. void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
  990. #endif