ctree.h 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  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_CTREE__
  19. #define __BTRFS_CTREE__
  20. #include <linux/version.h>
  21. #include <linux/mm.h>
  22. #include <linux/highmem.h>
  23. #include <linux/fs.h>
  24. #include <linux/completion.h>
  25. #include <linux/backing-dev.h>
  26. #include <asm/kmap_types.h>
  27. #include "bit-radix.h"
  28. #include "extent_io.h"
  29. #include "extent_map.h"
  30. #include "async-thread.h"
  31. struct btrfs_trans_handle;
  32. struct btrfs_transaction;
  33. extern struct kmem_cache *btrfs_trans_handle_cachep;
  34. extern struct kmem_cache *btrfs_transaction_cachep;
  35. extern struct kmem_cache *btrfs_bit_radix_cachep;
  36. extern struct kmem_cache *btrfs_path_cachep;
  37. #define BTRFS_MAGIC "_B5RfS_M"
  38. #define BTRFS_MAX_LEVEL 8
  39. /* holds pointers to all of the tree roots */
  40. #define BTRFS_ROOT_TREE_OBJECTID 1ULL
  41. /* stores information about which extents are in use, and reference counts */
  42. #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
  43. /*
  44. * chunk tree stores translations from logical -> physical block numbering
  45. * the super block points to the chunk tree
  46. */
  47. #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
  48. /*
  49. * stores information about which areas of a given device are in use.
  50. * one per device. The tree of tree roots points to the device tree
  51. */
  52. #define BTRFS_DEV_TREE_OBJECTID 4ULL
  53. /* one per subvolume, storing files and directories */
  54. #define BTRFS_FS_TREE_OBJECTID 5ULL
  55. /* directory objectid inside the root tree */
  56. #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
  57. /*
  58. * All files have objectids higher than this.
  59. */
  60. #define BTRFS_FIRST_FREE_OBJECTID 256ULL
  61. #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
  62. /*
  63. * the device items go into the chunk tree. The key is in the form
  64. * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
  65. */
  66. #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
  67. /*
  68. * we can actually store much bigger names, but lets not confuse the rest
  69. * of linux
  70. */
  71. #define BTRFS_NAME_LEN 255
  72. /* 32 bytes in various csum fields */
  73. #define BTRFS_CSUM_SIZE 32
  74. /* four bytes for CRC32 */
  75. #define BTRFS_CRC32_SIZE 4
  76. #define BTRFS_EMPTY_DIR_SIZE 0
  77. #define BTRFS_FT_UNKNOWN 0
  78. #define BTRFS_FT_REG_FILE 1
  79. #define BTRFS_FT_DIR 2
  80. #define BTRFS_FT_CHRDEV 3
  81. #define BTRFS_FT_BLKDEV 4
  82. #define BTRFS_FT_FIFO 5
  83. #define BTRFS_FT_SOCK 6
  84. #define BTRFS_FT_SYMLINK 7
  85. #define BTRFS_FT_XATTR 8
  86. #define BTRFS_FT_MAX 9
  87. /*
  88. * the key defines the order in the tree, and so it also defines (optimal)
  89. * block layout. objectid corresonds to the inode number. The flags
  90. * tells us things about the object, and is a kind of stream selector.
  91. * so for a given inode, keys with flags of 1 might refer to the inode
  92. * data, flags of 2 may point to file data in the btree and flags == 3
  93. * may point to extents.
  94. *
  95. * offset is the starting byte offset for this key in the stream.
  96. *
  97. * btrfs_disk_key is in disk byte order. struct btrfs_key is always
  98. * in cpu native order. Otherwise they are identical and their sizes
  99. * should be the same (ie both packed)
  100. */
  101. struct btrfs_disk_key {
  102. __le64 objectid;
  103. u8 type;
  104. __le64 offset;
  105. } __attribute__ ((__packed__));
  106. struct btrfs_key {
  107. u64 objectid;
  108. u8 type;
  109. u64 offset;
  110. } __attribute__ ((__packed__));
  111. struct btrfs_mapping_tree {
  112. struct extent_map_tree map_tree;
  113. };
  114. #define BTRFS_UUID_SIZE 16
  115. struct btrfs_dev_item {
  116. /* the internal btrfs device id */
  117. __le64 devid;
  118. /* size of the device */
  119. __le64 total_bytes;
  120. /* bytes used */
  121. __le64 bytes_used;
  122. /* optimal io alignment for this device */
  123. __le32 io_align;
  124. /* optimal io width for this device */
  125. __le32 io_width;
  126. /* minimal io size for this device */
  127. __le32 sector_size;
  128. /* type and info about this device */
  129. __le64 type;
  130. /* grouping information for allocation decisions */
  131. __le32 dev_group;
  132. /* seek speed 0-100 where 100 is fastest */
  133. u8 seek_speed;
  134. /* bandwidth 0-100 where 100 is fastest */
  135. u8 bandwidth;
  136. /* btrfs generated uuid for this device */
  137. u8 uuid[BTRFS_UUID_SIZE];
  138. } __attribute__ ((__packed__));
  139. struct btrfs_stripe {
  140. __le64 devid;
  141. __le64 offset;
  142. u8 dev_uuid[BTRFS_UUID_SIZE];
  143. } __attribute__ ((__packed__));
  144. struct btrfs_chunk {
  145. /* size of this chunk in bytes */
  146. __le64 length;
  147. /* objectid of the root referencing this chunk */
  148. __le64 owner;
  149. __le64 stripe_len;
  150. __le64 type;
  151. /* optimal io alignment for this chunk */
  152. __le32 io_align;
  153. /* optimal io width for this chunk */
  154. __le32 io_width;
  155. /* minimal io size for this chunk */
  156. __le32 sector_size;
  157. /* 2^16 stripes is quite a lot, a second limit is the size of a single
  158. * item in the btree
  159. */
  160. __le16 num_stripes;
  161. /* sub stripes only matter for raid10 */
  162. __le16 sub_stripes;
  163. struct btrfs_stripe stripe;
  164. /* additional stripes go here */
  165. } __attribute__ ((__packed__));
  166. static inline unsigned long btrfs_chunk_item_size(int num_stripes)
  167. {
  168. BUG_ON(num_stripes == 0);
  169. return sizeof(struct btrfs_chunk) +
  170. sizeof(struct btrfs_stripe) * (num_stripes - 1);
  171. }
  172. #define BTRFS_FSID_SIZE 16
  173. #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
  174. /*
  175. * every tree block (leaf or node) starts with this header.
  176. */
  177. struct btrfs_header {
  178. /* these first four must match the super block */
  179. u8 csum[BTRFS_CSUM_SIZE];
  180. u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
  181. __le64 bytenr; /* which block this node is supposed to live in */
  182. __le64 flags;
  183. /* allowed to be different from the super from here on down */
  184. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  185. __le64 generation;
  186. __le64 owner;
  187. __le32 nritems;
  188. u8 level;
  189. } __attribute__ ((__packed__));
  190. #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
  191. sizeof(struct btrfs_header)) / \
  192. sizeof(struct btrfs_key_ptr))
  193. #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
  194. #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
  195. #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
  196. sizeof(struct btrfs_item) - \
  197. sizeof(struct btrfs_file_extent_item))
  198. /*
  199. * this is a very generous portion of the super block, giving us
  200. * room to translate 14 chunks with 3 stripes each.
  201. */
  202. #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
  203. #define BTRFS_LABEL_SIZE 256
  204. /*
  205. * the super block basically lists the main trees of the FS
  206. * it currently lacks any block count etc etc
  207. */
  208. struct btrfs_super_block {
  209. u8 csum[BTRFS_CSUM_SIZE];
  210. /* the first 4 fields must match struct btrfs_header */
  211. u8 fsid[16]; /* FS specific uuid */
  212. __le64 bytenr; /* this block number */
  213. __le64 flags;
  214. /* allowed to be different from the btrfs_header from here own down */
  215. __le64 magic;
  216. __le64 generation;
  217. __le64 root;
  218. __le64 chunk_root;
  219. __le64 total_bytes;
  220. __le64 bytes_used;
  221. __le64 root_dir_objectid;
  222. __le64 num_devices;
  223. __le32 sectorsize;
  224. __le32 nodesize;
  225. __le32 leafsize;
  226. __le32 stripesize;
  227. __le32 sys_chunk_array_size;
  228. u8 root_level;
  229. u8 chunk_root_level;
  230. struct btrfs_dev_item dev_item;
  231. char label[BTRFS_LABEL_SIZE];
  232. u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
  233. } __attribute__ ((__packed__));
  234. /*
  235. * A leaf is full of items. offset and size tell us where to find
  236. * the item in the leaf (relative to the start of the data area)
  237. */
  238. struct btrfs_item {
  239. struct btrfs_disk_key key;
  240. __le32 offset;
  241. __le32 size;
  242. } __attribute__ ((__packed__));
  243. /*
  244. * leaves have an item area and a data area:
  245. * [item0, item1....itemN] [free space] [dataN...data1, data0]
  246. *
  247. * The data is separate from the items to get the keys closer together
  248. * during searches.
  249. */
  250. struct btrfs_leaf {
  251. struct btrfs_header header;
  252. struct btrfs_item items[];
  253. } __attribute__ ((__packed__));
  254. /*
  255. * all non-leaf blocks are nodes, they hold only keys and pointers to
  256. * other blocks
  257. */
  258. struct btrfs_key_ptr {
  259. struct btrfs_disk_key key;
  260. __le64 blockptr;
  261. __le64 generation;
  262. } __attribute__ ((__packed__));
  263. struct btrfs_node {
  264. struct btrfs_header header;
  265. struct btrfs_key_ptr ptrs[];
  266. } __attribute__ ((__packed__));
  267. /*
  268. * btrfs_paths remember the path taken from the root down to the leaf.
  269. * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
  270. * to any other levels that are present.
  271. *
  272. * The slots array records the index of the item or block pointer
  273. * used while walking the tree.
  274. */
  275. struct btrfs_path {
  276. struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
  277. int slots[BTRFS_MAX_LEVEL];
  278. /* if there is real range locking, this locks field will change */
  279. int locks[BTRFS_MAX_LEVEL];
  280. int reada;
  281. /* keep some upper locks as we walk down */
  282. int keep_locks;
  283. int skip_locking;
  284. int lowest_level;
  285. };
  286. /*
  287. * items in the extent btree are used to record the objectid of the
  288. * owner of the block and the number of references
  289. */
  290. struct btrfs_extent_item {
  291. __le32 refs;
  292. } __attribute__ ((__packed__));
  293. struct btrfs_extent_ref {
  294. __le64 root;
  295. __le64 generation;
  296. __le64 objectid;
  297. __le64 offset;
  298. } __attribute__ ((__packed__));
  299. /* dev extents record free space on individual devices. The owner
  300. * field points back to the chunk allocation mapping tree that allocated
  301. * the extent. The chunk tree uuid field is a way to double check the owner
  302. */
  303. struct btrfs_dev_extent {
  304. __le64 chunk_tree;
  305. __le64 chunk_objectid;
  306. __le64 chunk_offset;
  307. __le64 length;
  308. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  309. } __attribute__ ((__packed__));
  310. struct btrfs_inode_ref {
  311. __le16 name_len;
  312. /* name goes here */
  313. } __attribute__ ((__packed__));
  314. struct btrfs_timespec {
  315. __le64 sec;
  316. __le32 nsec;
  317. } __attribute__ ((__packed__));
  318. /*
  319. * there is no padding here on purpose. If you want to extent the inode,
  320. * make a new item type
  321. */
  322. struct btrfs_inode_item {
  323. __le64 generation;
  324. __le64 size;
  325. __le64 nblocks;
  326. __le64 block_group;
  327. __le32 nlink;
  328. __le32 uid;
  329. __le32 gid;
  330. __le32 mode;
  331. __le64 rdev;
  332. __le16 flags;
  333. __le16 compat_flags;
  334. struct btrfs_timespec atime;
  335. struct btrfs_timespec ctime;
  336. struct btrfs_timespec mtime;
  337. struct btrfs_timespec otime;
  338. } __attribute__ ((__packed__));
  339. struct btrfs_dir_item {
  340. struct btrfs_disk_key location;
  341. __le16 data_len;
  342. __le16 name_len;
  343. u8 type;
  344. } __attribute__ ((__packed__));
  345. struct btrfs_root_item {
  346. struct btrfs_inode_item inode;
  347. __le64 root_dirid;
  348. __le64 bytenr;
  349. __le64 byte_limit;
  350. __le64 bytes_used;
  351. __le32 flags;
  352. __le32 refs;
  353. struct btrfs_disk_key drop_progress;
  354. u8 drop_level;
  355. u8 level;
  356. } __attribute__ ((__packed__));
  357. #define BTRFS_FILE_EXTENT_REG 0
  358. #define BTRFS_FILE_EXTENT_INLINE 1
  359. struct btrfs_file_extent_item {
  360. __le64 generation;
  361. u8 type;
  362. /*
  363. * disk space consumed by the extent, checksum blocks are included
  364. * in these numbers
  365. */
  366. __le64 disk_bytenr;
  367. __le64 disk_num_bytes;
  368. /*
  369. * the logical offset in file blocks (no csums)
  370. * this extent record is for. This allows a file extent to point
  371. * into the middle of an existing extent on disk, sharing it
  372. * between two snapshots (useful if some bytes in the middle of the
  373. * extent have changed
  374. */
  375. __le64 offset;
  376. /*
  377. * the logical number of file blocks (no csums included)
  378. */
  379. __le64 num_bytes;
  380. } __attribute__ ((__packed__));
  381. struct btrfs_csum_item {
  382. u8 csum;
  383. } __attribute__ ((__packed__));
  384. /* different types of block groups (and chunks) */
  385. #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
  386. #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
  387. #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
  388. #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
  389. #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
  390. #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
  391. #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
  392. struct btrfs_block_group_item {
  393. __le64 used;
  394. __le64 chunk_objectid;
  395. __le64 flags;
  396. } __attribute__ ((__packed__));
  397. struct btrfs_space_info {
  398. u64 flags;
  399. u64 total_bytes;
  400. u64 bytes_used;
  401. u64 bytes_pinned;
  402. int full;
  403. int force_alloc;
  404. struct list_head list;
  405. };
  406. struct btrfs_block_group_cache {
  407. struct btrfs_key key;
  408. struct btrfs_block_group_item item;
  409. struct btrfs_space_info *space_info;
  410. u64 pinned;
  411. u64 flags;
  412. int cached;
  413. int ro;
  414. };
  415. struct btrfs_device;
  416. struct btrfs_fs_devices;
  417. struct btrfs_fs_info {
  418. u8 fsid[BTRFS_FSID_SIZE];
  419. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  420. struct btrfs_root *extent_root;
  421. struct btrfs_root *tree_root;
  422. struct btrfs_root *chunk_root;
  423. struct btrfs_root *dev_root;
  424. struct radix_tree_root fs_roots_radix;
  425. struct extent_io_tree free_space_cache;
  426. struct extent_io_tree block_group_cache;
  427. struct extent_io_tree pinned_extents;
  428. struct extent_io_tree pending_del;
  429. struct extent_io_tree extent_ins;
  430. /* logical->physical extent mapping */
  431. struct btrfs_mapping_tree mapping_tree;
  432. u64 generation;
  433. u64 last_trans_committed;
  434. unsigned long mount_opt;
  435. u64 max_extent;
  436. u64 max_inline;
  437. u64 alloc_start;
  438. struct btrfs_transaction *running_transaction;
  439. struct btrfs_super_block super_copy;
  440. struct btrfs_super_block super_for_commit;
  441. struct block_device *__bdev;
  442. struct super_block *sb;
  443. struct inode *btree_inode;
  444. struct backing_dev_info bdi;
  445. spinlock_t hash_lock;
  446. struct mutex trans_mutex;
  447. struct mutex transaction_kthread_mutex;
  448. struct mutex cleaner_mutex;
  449. struct mutex alloc_mutex;
  450. struct mutex chunk_mutex;
  451. struct mutex drop_mutex;
  452. struct mutex volume_mutex;
  453. struct list_head trans_list;
  454. struct list_head hashers;
  455. struct list_head dead_roots;
  456. atomic_t nr_async_submits;
  457. /*
  458. * there is a pool of worker threads for checksumming during writes
  459. * and a pool for checksumming after reads. This is because readers
  460. * can run with FS locks held, and the writers may be waiting for
  461. * those locks. We don't want ordering in the pending list to cause
  462. * deadlocks, and so the two are serviced separately.
  463. *
  464. * A third pool does submit_bio to avoid deadlocking with the other
  465. * two
  466. */
  467. struct btrfs_workers workers;
  468. struct btrfs_workers endio_workers;
  469. struct btrfs_workers submit_workers;
  470. struct task_struct *transaction_kthread;
  471. struct task_struct *cleaner_kthread;
  472. int thread_pool_size;
  473. struct kobject super_kobj;
  474. struct completion kobj_unregister;
  475. int do_barriers;
  476. int closing;
  477. atomic_t throttles;
  478. u64 total_pinned;
  479. struct list_head dirty_cowonly_roots;
  480. struct btrfs_fs_devices *fs_devices;
  481. struct list_head space_info;
  482. spinlock_t delalloc_lock;
  483. spinlock_t new_trans_lock;
  484. u64 delalloc_bytes;
  485. u64 last_alloc;
  486. u64 last_data_alloc;
  487. u64 avail_data_alloc_bits;
  488. u64 avail_metadata_alloc_bits;
  489. u64 avail_system_alloc_bits;
  490. u64 data_alloc_profile;
  491. u64 metadata_alloc_profile;
  492. u64 system_alloc_profile;
  493. void *bdev_holder;
  494. };
  495. /*
  496. * in ram representation of the tree. extent_root is used for all allocations
  497. * and for the extent tree extent_root root.
  498. */
  499. struct btrfs_root {
  500. struct extent_buffer *node;
  501. /* the node lock is held while changing the node pointer */
  502. spinlock_t node_lock;
  503. struct extent_buffer *commit_root;
  504. struct btrfs_root_item root_item;
  505. struct btrfs_key root_key;
  506. struct btrfs_fs_info *fs_info;
  507. struct inode *inode;
  508. struct kobject root_kobj;
  509. struct completion kobj_unregister;
  510. struct mutex objectid_mutex;
  511. u64 objectid;
  512. u64 last_trans;
  513. /* data allocations are done in sectorsize units */
  514. u32 sectorsize;
  515. /* node allocations are done in nodesize units */
  516. u32 nodesize;
  517. /* leaf allocations are done in leafsize units */
  518. u32 leafsize;
  519. u32 stripesize;
  520. u32 type;
  521. u64 highest_inode;
  522. u64 last_inode_alloc;
  523. int ref_cows;
  524. int track_dirty;
  525. u64 defrag_trans_start;
  526. struct btrfs_key defrag_progress;
  527. struct btrfs_key defrag_max;
  528. int defrag_running;
  529. int defrag_level;
  530. char *name;
  531. int in_sysfs;
  532. /* the dirty list is only used by non-reference counted roots */
  533. struct list_head dirty_list;
  534. };
  535. /*
  536. * inode items have the data typically returned from stat and store other
  537. * info about object characteristics. There is one for every file and dir in
  538. * the FS
  539. */
  540. #define BTRFS_INODE_ITEM_KEY 1
  541. #define BTRFS_INODE_REF_KEY 2
  542. #define BTRFS_XATTR_ITEM_KEY 8
  543. /* reserve 2-15 close to the inode for later flexibility */
  544. /*
  545. * dir items are the name -> inode pointers in a directory. There is one
  546. * for every name in a directory.
  547. */
  548. #define BTRFS_DIR_ITEM_KEY 16
  549. #define BTRFS_DIR_INDEX_KEY 17
  550. /*
  551. * extent data is for file data
  552. */
  553. #define BTRFS_EXTENT_DATA_KEY 18
  554. /*
  555. * csum items have the checksums for data in the extents
  556. */
  557. #define BTRFS_CSUM_ITEM_KEY 19
  558. /* reserve 20-31 for other file stuff */
  559. /*
  560. * root items point to tree roots. There are typically in the root
  561. * tree used by the super block to find all the other trees
  562. */
  563. #define BTRFS_ROOT_ITEM_KEY 32
  564. /*
  565. * extent items are in the extent map tree. These record which blocks
  566. * are used, and how many references there are to each block
  567. */
  568. #define BTRFS_EXTENT_ITEM_KEY 33
  569. #define BTRFS_EXTENT_REF_KEY 34
  570. /*
  571. * block groups give us hints into the extent allocation trees. Which
  572. * blocks are free etc etc
  573. */
  574. #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
  575. #define BTRFS_DEV_EXTENT_KEY 75
  576. #define BTRFS_DEV_ITEM_KEY 76
  577. #define BTRFS_CHUNK_ITEM_KEY 77
  578. /*
  579. * string items are for debugging. They just store a short string of
  580. * data in the FS
  581. */
  582. #define BTRFS_STRING_ITEM_KEY 253
  583. #define BTRFS_MOUNT_NODATASUM (1 << 0)
  584. #define BTRFS_MOUNT_NODATACOW (1 << 1)
  585. #define BTRFS_MOUNT_NOBARRIER (1 << 2)
  586. #define BTRFS_MOUNT_SSD (1 << 3)
  587. #define BTRFS_MOUNT_DEGRADED (1 << 4)
  588. #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
  589. #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
  590. #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \
  591. BTRFS_MOUNT_##opt)
  592. /*
  593. * Inode flags
  594. */
  595. #define BTRFS_INODE_NODATASUM (1 << 0)
  596. #define BTRFS_INODE_NODATACOW (1 << 1)
  597. #define BTRFS_INODE_READONLY (1 << 2)
  598. #define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \
  599. ~BTRFS_INODE_##flag)
  600. #define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \
  601. BTRFS_INODE_##flag)
  602. #define btrfs_test_flag(inode, flag) (BTRFS_I(inode)->flags & \
  603. BTRFS_INODE_##flag)
  604. /* some macros to generate set/get funcs for the struct fields. This
  605. * assumes there is a lefoo_to_cpu for every type, so lets make a simple
  606. * one for u8:
  607. */
  608. #define le8_to_cpu(v) (v)
  609. #define cpu_to_le8(v) (v)
  610. #define __le8 u8
  611. #define read_eb_member(eb, ptr, type, member, result) ( \
  612. read_extent_buffer(eb, (char *)(result), \
  613. ((unsigned long)(ptr)) + \
  614. offsetof(type, member), \
  615. sizeof(((type *)0)->member)))
  616. #define write_eb_member(eb, ptr, type, member, result) ( \
  617. write_extent_buffer(eb, (char *)(result), \
  618. ((unsigned long)(ptr)) + \
  619. offsetof(type, member), \
  620. sizeof(((type *)0)->member)))
  621. #ifndef BTRFS_SETGET_FUNCS
  622. #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
  623. u##bits btrfs_##name(struct extent_buffer *eb, type *s); \
  624. void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val);
  625. #endif
  626. #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
  627. static inline u##bits btrfs_##name(struct extent_buffer *eb) \
  628. { \
  629. type *p = kmap_atomic(eb->first_page, KM_USER0); \
  630. u##bits res = le##bits##_to_cpu(p->member); \
  631. kunmap_atomic(p, KM_USER0); \
  632. return res; \
  633. } \
  634. static inline void btrfs_set_##name(struct extent_buffer *eb, \
  635. u##bits val) \
  636. { \
  637. type *p = kmap_atomic(eb->first_page, KM_USER0); \
  638. p->member = cpu_to_le##bits(val); \
  639. kunmap_atomic(p, KM_USER0); \
  640. }
  641. #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
  642. static inline u##bits btrfs_##name(type *s) \
  643. { \
  644. return le##bits##_to_cpu(s->member); \
  645. } \
  646. static inline void btrfs_set_##name(type *s, u##bits val) \
  647. { \
  648. s->member = cpu_to_le##bits(val); \
  649. }
  650. BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
  651. BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
  652. BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
  653. BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
  654. BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
  655. BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
  656. BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
  657. BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
  658. BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
  659. BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
  660. BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
  661. BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
  662. total_bytes, 64);
  663. BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
  664. bytes_used, 64);
  665. BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
  666. io_align, 32);
  667. BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
  668. io_width, 32);
  669. BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
  670. sector_size, 32);
  671. BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
  672. BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
  673. dev_group, 32);
  674. BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
  675. seek_speed, 8);
  676. BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
  677. bandwidth, 8);
  678. static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
  679. {
  680. return (char *)d + offsetof(struct btrfs_dev_item, uuid);
  681. }
  682. BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
  683. BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
  684. BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
  685. BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
  686. BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
  687. BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
  688. BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
  689. BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
  690. BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
  691. BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
  692. BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
  693. static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
  694. {
  695. return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
  696. }
  697. BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
  698. BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
  699. BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
  700. stripe_len, 64);
  701. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
  702. io_align, 32);
  703. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
  704. io_width, 32);
  705. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
  706. sector_size, 32);
  707. BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
  708. BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
  709. num_stripes, 16);
  710. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
  711. sub_stripes, 16);
  712. BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
  713. BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
  714. static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
  715. int nr)
  716. {
  717. unsigned long offset = (unsigned long)c;
  718. offset += offsetof(struct btrfs_chunk, stripe);
  719. offset += nr * sizeof(struct btrfs_stripe);
  720. return (struct btrfs_stripe *)offset;
  721. }
  722. static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
  723. {
  724. return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
  725. }
  726. static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
  727. struct btrfs_chunk *c, int nr)
  728. {
  729. return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
  730. }
  731. static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
  732. struct btrfs_chunk *c, int nr,
  733. u64 val)
  734. {
  735. btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
  736. }
  737. static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
  738. struct btrfs_chunk *c, int nr)
  739. {
  740. return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
  741. }
  742. static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
  743. struct btrfs_chunk *c, int nr,
  744. u64 val)
  745. {
  746. btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
  747. }
  748. /* struct btrfs_block_group_item */
  749. BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
  750. used, 64);
  751. BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
  752. used, 64);
  753. BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
  754. struct btrfs_block_group_item, chunk_objectid, 64);
  755. BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
  756. struct btrfs_block_group_item, chunk_objectid, 64);
  757. BTRFS_SETGET_FUNCS(disk_block_group_flags,
  758. struct btrfs_block_group_item, flags, 64);
  759. BTRFS_SETGET_STACK_FUNCS(block_group_flags,
  760. struct btrfs_block_group_item, flags, 64);
  761. /* struct btrfs_inode_ref */
  762. BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
  763. /* struct btrfs_inode_item */
  764. BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
  765. BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
  766. BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
  767. BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
  768. BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
  769. BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
  770. BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
  771. BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
  772. BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
  773. BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
  774. BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
  775. compat_flags, 16);
  776. static inline struct btrfs_timespec *
  777. btrfs_inode_atime(struct btrfs_inode_item *inode_item)
  778. {
  779. unsigned long ptr = (unsigned long)inode_item;
  780. ptr += offsetof(struct btrfs_inode_item, atime);
  781. return (struct btrfs_timespec *)ptr;
  782. }
  783. static inline struct btrfs_timespec *
  784. btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
  785. {
  786. unsigned long ptr = (unsigned long)inode_item;
  787. ptr += offsetof(struct btrfs_inode_item, mtime);
  788. return (struct btrfs_timespec *)ptr;
  789. }
  790. static inline struct btrfs_timespec *
  791. btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
  792. {
  793. unsigned long ptr = (unsigned long)inode_item;
  794. ptr += offsetof(struct btrfs_inode_item, ctime);
  795. return (struct btrfs_timespec *)ptr;
  796. }
  797. static inline struct btrfs_timespec *
  798. btrfs_inode_otime(struct btrfs_inode_item *inode_item)
  799. {
  800. unsigned long ptr = (unsigned long)inode_item;
  801. ptr += offsetof(struct btrfs_inode_item, otime);
  802. return (struct btrfs_timespec *)ptr;
  803. }
  804. BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
  805. BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
  806. /* struct btrfs_extent_item */
  807. BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
  808. /* struct btrfs_dev_extent */
  809. BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
  810. chunk_tree, 64);
  811. BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
  812. chunk_objectid, 64);
  813. BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
  814. chunk_offset, 64);
  815. BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
  816. static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
  817. {
  818. unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
  819. return (u8 *)((unsigned long)dev + ptr);
  820. }
  821. /* struct btrfs_extent_ref */
  822. BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
  823. BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
  824. BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
  825. BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
  826. BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
  827. BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
  828. generation, 64);
  829. BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
  830. objectid, 64);
  831. BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64);
  832. BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
  833. refs, 32);
  834. /* struct btrfs_node */
  835. BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
  836. BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
  837. static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
  838. {
  839. unsigned long ptr;
  840. ptr = offsetof(struct btrfs_node, ptrs) +
  841. sizeof(struct btrfs_key_ptr) * nr;
  842. return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
  843. }
  844. static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
  845. int nr, u64 val)
  846. {
  847. unsigned long ptr;
  848. ptr = offsetof(struct btrfs_node, ptrs) +
  849. sizeof(struct btrfs_key_ptr) * nr;
  850. btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
  851. }
  852. static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
  853. {
  854. unsigned long ptr;
  855. ptr = offsetof(struct btrfs_node, ptrs) +
  856. sizeof(struct btrfs_key_ptr) * nr;
  857. return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
  858. }
  859. static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
  860. int nr, u64 val)
  861. {
  862. unsigned long ptr;
  863. ptr = offsetof(struct btrfs_node, ptrs) +
  864. sizeof(struct btrfs_key_ptr) * nr;
  865. btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
  866. }
  867. static inline unsigned long btrfs_node_key_ptr_offset(int nr)
  868. {
  869. return offsetof(struct btrfs_node, ptrs) +
  870. sizeof(struct btrfs_key_ptr) * nr;
  871. }
  872. void btrfs_node_key(struct extent_buffer *eb,
  873. struct btrfs_disk_key *disk_key, int nr);
  874. static inline void btrfs_set_node_key(struct extent_buffer *eb,
  875. struct btrfs_disk_key *disk_key, int nr)
  876. {
  877. unsigned long ptr;
  878. ptr = btrfs_node_key_ptr_offset(nr);
  879. write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
  880. struct btrfs_key_ptr, key, disk_key);
  881. }
  882. /* struct btrfs_item */
  883. BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
  884. BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
  885. static inline unsigned long btrfs_item_nr_offset(int nr)
  886. {
  887. return offsetof(struct btrfs_leaf, items) +
  888. sizeof(struct btrfs_item) * nr;
  889. }
  890. static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
  891. int nr)
  892. {
  893. return (struct btrfs_item *)btrfs_item_nr_offset(nr);
  894. }
  895. static inline u32 btrfs_item_end(struct extent_buffer *eb,
  896. struct btrfs_item *item)
  897. {
  898. return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
  899. }
  900. static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
  901. {
  902. return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
  903. }
  904. static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
  905. {
  906. return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
  907. }
  908. static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
  909. {
  910. return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
  911. }
  912. static inline void btrfs_item_key(struct extent_buffer *eb,
  913. struct btrfs_disk_key *disk_key, int nr)
  914. {
  915. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  916. read_eb_member(eb, item, struct btrfs_item, key, disk_key);
  917. }
  918. static inline void btrfs_set_item_key(struct extent_buffer *eb,
  919. struct btrfs_disk_key *disk_key, int nr)
  920. {
  921. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  922. write_eb_member(eb, item, struct btrfs_item, key, disk_key);
  923. }
  924. /* struct btrfs_dir_item */
  925. BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
  926. BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
  927. BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
  928. static inline void btrfs_dir_item_key(struct extent_buffer *eb,
  929. struct btrfs_dir_item *item,
  930. struct btrfs_disk_key *key)
  931. {
  932. read_eb_member(eb, item, struct btrfs_dir_item, location, key);
  933. }
  934. static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
  935. struct btrfs_dir_item *item,
  936. struct btrfs_disk_key *key)
  937. {
  938. write_eb_member(eb, item, struct btrfs_dir_item, location, key);
  939. }
  940. /* struct btrfs_disk_key */
  941. BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
  942. objectid, 64);
  943. BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
  944. BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
  945. static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
  946. struct btrfs_disk_key *disk)
  947. {
  948. cpu->offset = le64_to_cpu(disk->offset);
  949. cpu->type = disk->type;
  950. cpu->objectid = le64_to_cpu(disk->objectid);
  951. }
  952. static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
  953. struct btrfs_key *cpu)
  954. {
  955. disk->offset = cpu_to_le64(cpu->offset);
  956. disk->type = cpu->type;
  957. disk->objectid = cpu_to_le64(cpu->objectid);
  958. }
  959. static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
  960. struct btrfs_key *key, int nr)
  961. {
  962. struct btrfs_disk_key disk_key;
  963. btrfs_node_key(eb, &disk_key, nr);
  964. btrfs_disk_key_to_cpu(key, &disk_key);
  965. }
  966. static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
  967. struct btrfs_key *key, int nr)
  968. {
  969. struct btrfs_disk_key disk_key;
  970. btrfs_item_key(eb, &disk_key, nr);
  971. btrfs_disk_key_to_cpu(key, &disk_key);
  972. }
  973. static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
  974. struct btrfs_dir_item *item,
  975. struct btrfs_key *key)
  976. {
  977. struct btrfs_disk_key disk_key;
  978. btrfs_dir_item_key(eb, item, &disk_key);
  979. btrfs_disk_key_to_cpu(key, &disk_key);
  980. }
  981. static inline u8 btrfs_key_type(struct btrfs_key *key)
  982. {
  983. return key->type;
  984. }
  985. static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
  986. {
  987. key->type = val;
  988. }
  989. /* struct btrfs_header */
  990. BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
  991. BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
  992. generation, 64);
  993. BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
  994. BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
  995. BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
  996. BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
  997. static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
  998. {
  999. return (btrfs_header_flags(eb) & flag) == flag;
  1000. }
  1001. static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
  1002. {
  1003. u64 flags = btrfs_header_flags(eb);
  1004. btrfs_set_header_flags(eb, flags | flag);
  1005. return (flags & flag) == flag;
  1006. }
  1007. static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
  1008. {
  1009. u64 flags = btrfs_header_flags(eb);
  1010. btrfs_set_header_flags(eb, flags & ~flag);
  1011. return (flags & flag) == flag;
  1012. }
  1013. static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
  1014. {
  1015. unsigned long ptr = offsetof(struct btrfs_header, fsid);
  1016. return (u8 *)ptr;
  1017. }
  1018. static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
  1019. {
  1020. unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
  1021. return (u8 *)ptr;
  1022. }
  1023. static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
  1024. {
  1025. unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
  1026. return (u8 *)ptr;
  1027. }
  1028. static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
  1029. {
  1030. unsigned long ptr = offsetof(struct btrfs_header, csum);
  1031. return (u8 *)ptr;
  1032. }
  1033. static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
  1034. {
  1035. return NULL;
  1036. }
  1037. static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
  1038. {
  1039. return NULL;
  1040. }
  1041. static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
  1042. {
  1043. return NULL;
  1044. }
  1045. static inline int btrfs_is_leaf(struct extent_buffer *eb)
  1046. {
  1047. return (btrfs_header_level(eb) == 0);
  1048. }
  1049. /* struct btrfs_root_item */
  1050. BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
  1051. BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
  1052. BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
  1053. BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
  1054. BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
  1055. BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
  1056. BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
  1057. BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
  1058. BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
  1059. BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
  1060. /* struct btrfs_super_block */
  1061. BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
  1062. BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
  1063. BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
  1064. generation, 64);
  1065. BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
  1066. BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
  1067. struct btrfs_super_block, sys_chunk_array_size, 32);
  1068. BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
  1069. root_level, 8);
  1070. BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
  1071. chunk_root, 64);
  1072. BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
  1073. chunk_root_level, 64);
  1074. BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
  1075. total_bytes, 64);
  1076. BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
  1077. bytes_used, 64);
  1078. BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
  1079. sectorsize, 32);
  1080. BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
  1081. nodesize, 32);
  1082. BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
  1083. leafsize, 32);
  1084. BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
  1085. stripesize, 32);
  1086. BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
  1087. root_dir_objectid, 64);
  1088. BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
  1089. num_devices, 64);
  1090. static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
  1091. {
  1092. return offsetof(struct btrfs_leaf, items);
  1093. }
  1094. /* struct btrfs_file_extent_item */
  1095. BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
  1096. static inline unsigned long btrfs_file_extent_inline_start(struct
  1097. btrfs_file_extent_item *e)
  1098. {
  1099. unsigned long offset = (unsigned long)e;
  1100. offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
  1101. return offset;
  1102. }
  1103. static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
  1104. {
  1105. return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
  1106. }
  1107. static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
  1108. struct btrfs_item *e)
  1109. {
  1110. unsigned long offset;
  1111. offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
  1112. return btrfs_item_size(eb, e) - offset;
  1113. }
  1114. BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
  1115. disk_bytenr, 64);
  1116. BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
  1117. generation, 64);
  1118. BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
  1119. disk_num_bytes, 64);
  1120. BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
  1121. offset, 64);
  1122. BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
  1123. num_bytes, 64);
  1124. static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
  1125. {
  1126. return sb->s_fs_info;
  1127. }
  1128. static inline int btrfs_set_root_name(struct btrfs_root *root,
  1129. const char *name, int len)
  1130. {
  1131. /* if we already have a name just free it */
  1132. if (root->name)
  1133. kfree(root->name);
  1134. root->name = kmalloc(len+1, GFP_KERNEL);
  1135. if (!root->name)
  1136. return -ENOMEM;
  1137. memcpy(root->name, name, len);
  1138. root->name[len] ='\0';
  1139. return 0;
  1140. }
  1141. static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
  1142. if (level == 0)
  1143. return root->leafsize;
  1144. return root->nodesize;
  1145. }
  1146. /* helper function to cast into the data area of the leaf. */
  1147. #define btrfs_item_ptr(leaf, slot, type) \
  1148. ((type *)(btrfs_leaf_data(leaf) + \
  1149. btrfs_item_offset_nr(leaf, slot)))
  1150. #define btrfs_item_ptr_offset(leaf, slot) \
  1151. ((unsigned long)(btrfs_leaf_data(leaf) + \
  1152. btrfs_item_offset_nr(leaf, slot)))
  1153. static inline struct dentry *fdentry(struct file *file) {
  1154. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
  1155. return file->f_dentry;
  1156. #else
  1157. return file->f_path.dentry;
  1158. #endif
  1159. }
  1160. /* extent-tree.c */
  1161. u32 btrfs_count_snapshots_in_path(struct btrfs_root *root,
  1162. struct btrfs_path *count_path,
  1163. u64 expected_owner, u64 first_extent);
  1164. int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
  1165. struct btrfs_root *root);
  1166. int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
  1167. struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
  1168. btrfs_fs_info *info,
  1169. u64 bytenr);
  1170. struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
  1171. struct btrfs_block_group_cache
  1172. *hint, u64 search_start,
  1173. int data, int owner);
  1174. struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
  1175. struct btrfs_root *root,
  1176. u32 blocksize,
  1177. u64 root_objectid,
  1178. u64 ref_generation,
  1179. u64 first_objectid,
  1180. int level,
  1181. u64 hint,
  1182. u64 empty_size);
  1183. int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
  1184. int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
  1185. struct btrfs_root *root,
  1186. struct btrfs_path *path, u64 bytenr,
  1187. u64 root_objectid, u64 ref_generation,
  1188. u64 owner, u64 owner_offset);
  1189. int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
  1190. struct btrfs_root *root,
  1191. u64 num_bytes, u64 min_bytes,
  1192. u64 root_objectid, u64 ref_generation,
  1193. u64 owner, u64 owner_offset,
  1194. u64 empty_size, u64 hint_byte,
  1195. u64 search_end, struct btrfs_key *ins, u64 data);
  1196. int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1197. struct extent_buffer *buf);
  1198. int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
  1199. *root, u64 bytenr, u64 num_bytes,
  1200. u64 root_objectid, u64 ref_generation,
  1201. u64 owner_objectid, u64 owner_offset, int pin);
  1202. int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
  1203. struct btrfs_root *root,
  1204. struct extent_io_tree *unpin);
  1205. int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
  1206. struct btrfs_root *root,
  1207. u64 bytenr, u64 num_bytes,
  1208. u64 root_objectid, u64 ref_generation,
  1209. u64 owner, u64 owner_offset);
  1210. int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
  1211. struct btrfs_root *root);
  1212. int btrfs_free_block_groups(struct btrfs_fs_info *info);
  1213. int btrfs_read_block_groups(struct btrfs_root *root);
  1214. int btrfs_make_block_group(struct btrfs_trans_handle *trans,
  1215. struct btrfs_root *root, u64 bytes_used,
  1216. u64 type, u64 chunk_objectid, u64 chunk_offset,
  1217. u64 size);
  1218. /* ctree.c */
  1219. int btrfs_previous_item(struct btrfs_root *root,
  1220. struct btrfs_path *path, u64 min_objectid,
  1221. int type);
  1222. struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
  1223. struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
  1224. int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
  1225. struct btrfs_key *key, int lowest_level,
  1226. int cache_only, u64 min_trans);
  1227. int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
  1228. struct btrfs_path *path, int cache_only,
  1229. u64 min_trans);
  1230. int btrfs_cow_block(struct btrfs_trans_handle *trans,
  1231. struct btrfs_root *root, struct extent_buffer *buf,
  1232. struct extent_buffer *parent, int parent_slot,
  1233. struct extent_buffer **cow_ret);
  1234. int btrfs_copy_root(struct btrfs_trans_handle *trans,
  1235. struct btrfs_root *root,
  1236. struct extent_buffer *buf,
  1237. struct extent_buffer **cow_ret, u64 new_root_objectid);
  1238. int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1239. *root, struct btrfs_path *path, u32 data_size);
  1240. int btrfs_truncate_item(struct btrfs_trans_handle *trans,
  1241. struct btrfs_root *root,
  1242. struct btrfs_path *path,
  1243. u32 new_size, int from_end);
  1244. int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
  1245. *root, struct btrfs_key *key, struct btrfs_path *p, int
  1246. ins_len, int cow);
  1247. int btrfs_realloc_node(struct btrfs_trans_handle *trans,
  1248. struct btrfs_root *root, struct extent_buffer *parent,
  1249. int start_slot, int cache_only, u64 *last_ret,
  1250. struct btrfs_key *progress);
  1251. void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
  1252. struct btrfs_path *btrfs_alloc_path(void);
  1253. void btrfs_free_path(struct btrfs_path *p);
  1254. void btrfs_init_path(struct btrfs_path *p);
  1255. int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1256. struct btrfs_path *path, int slot, int nr);
  1257. static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
  1258. struct btrfs_root *root,
  1259. struct btrfs_path *path)
  1260. {
  1261. return btrfs_del_items(trans, root, path, path->slots[0], 1);
  1262. }
  1263. int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1264. *root, struct btrfs_key *key, void *data, u32 data_size);
  1265. int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
  1266. struct btrfs_root *root,
  1267. struct btrfs_path *path,
  1268. struct btrfs_key *cpu_key, u32 *data_size, int nr);
  1269. static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
  1270. struct btrfs_root *root,
  1271. struct btrfs_path *path,
  1272. struct btrfs_key *key,
  1273. u32 data_size)
  1274. {
  1275. return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
  1276. }
  1277. int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
  1278. int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
  1279. int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
  1280. int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
  1281. *root);
  1282. /* root-item.c */
  1283. int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1284. struct btrfs_key *key);
  1285. int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
  1286. *root, struct btrfs_key *key, struct btrfs_root_item
  1287. *item);
  1288. int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
  1289. *root, struct btrfs_key *key, struct btrfs_root_item
  1290. *item);
  1291. int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
  1292. btrfs_root_item *item, struct btrfs_key *key);
  1293. int btrfs_search_root(struct btrfs_root *root, u64 search_start,
  1294. u64 *found_objectid);
  1295. int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
  1296. struct btrfs_root *latest_root);
  1297. /* dir-item.c */
  1298. int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1299. *root, const char *name, int name_len, u64 dir,
  1300. struct btrfs_key *location, u8 type);
  1301. struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
  1302. struct btrfs_root *root,
  1303. struct btrfs_path *path, u64 dir,
  1304. const char *name, int name_len,
  1305. int mod);
  1306. struct btrfs_dir_item *
  1307. btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
  1308. struct btrfs_root *root,
  1309. struct btrfs_path *path, u64 dir,
  1310. u64 objectid, const char *name, int name_len,
  1311. int mod);
  1312. struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
  1313. struct btrfs_path *path,
  1314. const char *name, int name_len);
  1315. int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
  1316. struct btrfs_root *root,
  1317. struct btrfs_path *path,
  1318. struct btrfs_dir_item *di);
  1319. int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
  1320. struct btrfs_root *root, const char *name,
  1321. u16 name_len, const void *data, u16 data_len,
  1322. u64 dir);
  1323. struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
  1324. struct btrfs_root *root,
  1325. struct btrfs_path *path, u64 dir,
  1326. const char *name, u16 name_len,
  1327. int mod);
  1328. /* inode-map.c */
  1329. int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
  1330. struct btrfs_root *fs_root,
  1331. u64 dirid, u64 *objectid);
  1332. int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
  1333. /* inode-item.c */
  1334. int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
  1335. struct btrfs_root *root,
  1336. const char *name, int name_len,
  1337. u64 inode_objectid, u64 ref_objectid);
  1338. int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
  1339. struct btrfs_root *root,
  1340. const char *name, int name_len,
  1341. u64 inode_objectid, u64 ref_objectid);
  1342. int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
  1343. struct btrfs_root *root,
  1344. struct btrfs_path *path, u64 objectid);
  1345. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  1346. *root, struct btrfs_path *path,
  1347. struct btrfs_key *location, int mod);
  1348. /* file-item.c */
  1349. int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
  1350. struct btrfs_root *root,
  1351. u64 objectid, u64 pos, u64 disk_offset,
  1352. u64 disk_num_bytes,
  1353. u64 num_bytes, u64 offset);
  1354. int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
  1355. struct btrfs_root *root,
  1356. struct btrfs_path *path, u64 objectid,
  1357. u64 bytenr, int mod);
  1358. int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
  1359. struct btrfs_root *root, struct inode *inode,
  1360. struct bio *bio, char *sums);
  1361. int btrfs_csum_one_bio(struct btrfs_root *root,
  1362. struct bio *bio, char **sums_ret);
  1363. struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
  1364. struct btrfs_root *root,
  1365. struct btrfs_path *path,
  1366. u64 objectid, u64 offset,
  1367. int cow);
  1368. int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
  1369. struct btrfs_root *root, struct btrfs_path *path,
  1370. u64 isize);
  1371. /* inode.c */
  1372. int btrfs_create_subvol_root(struct btrfs_root *new_root,
  1373. struct btrfs_trans_handle *trans, u64 new_dirid,
  1374. struct btrfs_block_group_cache *block_group);
  1375. void btrfs_invalidate_dcache_root(struct btrfs_root *root, char *name,
  1376. int namelen);
  1377. int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
  1378. size_t size, struct bio *bio);
  1379. static inline void dec_i_blocks(struct inode *inode, u64 dec)
  1380. {
  1381. dec = dec >> 9;
  1382. if (dec <= inode->i_blocks)
  1383. inode->i_blocks -= dec;
  1384. else
  1385. inode->i_blocks = 0;
  1386. }
  1387. unsigned long btrfs_force_ra(struct address_space *mapping,
  1388. struct file_ra_state *ra, struct file *file,
  1389. pgoff_t offset, pgoff_t last_index);
  1390. int btrfs_check_free_space(struct btrfs_root *root, u64 num_required,
  1391. int for_del);
  1392. int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
  1393. int btrfs_readpage(struct file *file, struct page *page);
  1394. void btrfs_delete_inode(struct inode *inode);
  1395. void btrfs_put_inode(struct inode *inode);
  1396. void btrfs_read_locked_inode(struct inode *inode);
  1397. int btrfs_write_inode(struct inode *inode, int wait);
  1398. void btrfs_dirty_inode(struct inode *inode);
  1399. struct inode *btrfs_alloc_inode(struct super_block *sb);
  1400. void btrfs_destroy_inode(struct inode *inode);
  1401. int btrfs_init_cachep(void);
  1402. void btrfs_destroy_cachep(void);
  1403. long btrfs_ioctl_trans_end(struct file *file);
  1404. struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
  1405. struct btrfs_root *root);
  1406. struct inode *btrfs_ilookup(struct super_block *s, u64 objectid,
  1407. u64 root_objectid);
  1408. int btrfs_commit_write(struct file *file, struct page *page,
  1409. unsigned from, unsigned to);
  1410. struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
  1411. size_t page_offset, u64 start, u64 end,
  1412. int create);
  1413. int btrfs_update_inode(struct btrfs_trans_handle *trans,
  1414. struct btrfs_root *root,
  1415. struct inode *inode);
  1416. /* ioctl.c */
  1417. long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  1418. /* file.c */
  1419. int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end);
  1420. int btrfs_check_file(struct btrfs_root *root, struct inode *inode);
  1421. extern struct file_operations btrfs_file_operations;
  1422. int btrfs_drop_extents(struct btrfs_trans_handle *trans,
  1423. struct btrfs_root *root, struct inode *inode,
  1424. u64 start, u64 end, u64 inline_limit, u64 *hint_block);
  1425. int btrfs_release_file(struct inode *inode, struct file *file);
  1426. /* tree-defrag.c */
  1427. int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
  1428. struct btrfs_root *root, int cache_only);
  1429. /* sysfs.c */
  1430. int btrfs_init_sysfs(void);
  1431. void btrfs_exit_sysfs(void);
  1432. int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
  1433. int btrfs_sysfs_add_root(struct btrfs_root *root);
  1434. void btrfs_sysfs_del_root(struct btrfs_root *root);
  1435. void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
  1436. /* xattr.c */
  1437. ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  1438. int btrfs_delete_xattrs(struct btrfs_trans_handle *trans,
  1439. struct btrfs_root *root, struct inode *inode);
  1440. /* super.c */
  1441. u64 btrfs_parse_size(char *str);
  1442. int btrfs_parse_options(struct btrfs_root *root, char *options);
  1443. int btrfs_sync_fs(struct super_block *sb, int wait);
  1444. #endif