ctree.h 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  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 <linux/wait.h>
  27. #include <asm/kmap_types.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. struct btrfs_ordered_sum;
  38. #define BTRFS_MAGIC "_BHRfS_M"
  39. #define BTRFS_ACL_NOT_CACHED ((void *)-1)
  40. #ifdef CONFIG_LOCKDEP
  41. # define BTRFS_MAX_LEVEL 7
  42. #else
  43. # define BTRFS_MAX_LEVEL 8
  44. #endif
  45. /* holds pointers to all of the tree roots */
  46. #define BTRFS_ROOT_TREE_OBJECTID 1ULL
  47. /* stores information about which extents are in use, and reference counts */
  48. #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
  49. /*
  50. * chunk tree stores translations from logical -> physical block numbering
  51. * the super block points to the chunk tree
  52. */
  53. #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
  54. /*
  55. * stores information about which areas of a given device are in use.
  56. * one per device. The tree of tree roots points to the device tree
  57. */
  58. #define BTRFS_DEV_TREE_OBJECTID 4ULL
  59. /* one per subvolume, storing files and directories */
  60. #define BTRFS_FS_TREE_OBJECTID 5ULL
  61. /* directory objectid inside the root tree */
  62. #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
  63. /* holds checksums of all the data extents */
  64. #define BTRFS_CSUM_TREE_OBJECTID 7ULL
  65. /* orhpan objectid for tracking unlinked/truncated files */
  66. #define BTRFS_ORPHAN_OBJECTID -5ULL
  67. /* does write ahead logging to speed up fsyncs */
  68. #define BTRFS_TREE_LOG_OBJECTID -6ULL
  69. #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
  70. /* for space balancing */
  71. #define BTRFS_TREE_RELOC_OBJECTID -8ULL
  72. #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
  73. /*
  74. * extent checksums all have this objectid
  75. * this allows them to share the logging tree
  76. * for fsyncs
  77. */
  78. #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
  79. /* dummy objectid represents multiple objectids */
  80. #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
  81. /*
  82. * All files have objectids in this range.
  83. */
  84. #define BTRFS_FIRST_FREE_OBJECTID 256ULL
  85. #define BTRFS_LAST_FREE_OBJECTID -256ULL
  86. #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
  87. /*
  88. * the device items go into the chunk tree. The key is in the form
  89. * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
  90. */
  91. #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
  92. /*
  93. * we can actually store much bigger names, but lets not confuse the rest
  94. * of linux
  95. */
  96. #define BTRFS_NAME_LEN 255
  97. /* 32 bytes in various csum fields */
  98. #define BTRFS_CSUM_SIZE 32
  99. /* csum types */
  100. #define BTRFS_CSUM_TYPE_CRC32 0
  101. static int btrfs_csum_sizes[] = { 4, 0 };
  102. /* four bytes for CRC32 */
  103. #define BTRFS_EMPTY_DIR_SIZE 0
  104. #define BTRFS_FT_UNKNOWN 0
  105. #define BTRFS_FT_REG_FILE 1
  106. #define BTRFS_FT_DIR 2
  107. #define BTRFS_FT_CHRDEV 3
  108. #define BTRFS_FT_BLKDEV 4
  109. #define BTRFS_FT_FIFO 5
  110. #define BTRFS_FT_SOCK 6
  111. #define BTRFS_FT_SYMLINK 7
  112. #define BTRFS_FT_XATTR 8
  113. #define BTRFS_FT_MAX 9
  114. /*
  115. * the key defines the order in the tree, and so it also defines (optimal)
  116. * block layout. objectid corresonds to the inode number. The flags
  117. * tells us things about the object, and is a kind of stream selector.
  118. * so for a given inode, keys with flags of 1 might refer to the inode
  119. * data, flags of 2 may point to file data in the btree and flags == 3
  120. * may point to extents.
  121. *
  122. * offset is the starting byte offset for this key in the stream.
  123. *
  124. * btrfs_disk_key is in disk byte order. struct btrfs_key is always
  125. * in cpu native order. Otherwise they are identical and their sizes
  126. * should be the same (ie both packed)
  127. */
  128. struct btrfs_disk_key {
  129. __le64 objectid;
  130. u8 type;
  131. __le64 offset;
  132. } __attribute__ ((__packed__));
  133. struct btrfs_key {
  134. u64 objectid;
  135. u8 type;
  136. u64 offset;
  137. } __attribute__ ((__packed__));
  138. struct btrfs_mapping_tree {
  139. struct extent_map_tree map_tree;
  140. };
  141. #define BTRFS_UUID_SIZE 16
  142. struct btrfs_dev_item {
  143. /* the internal btrfs device id */
  144. __le64 devid;
  145. /* size of the device */
  146. __le64 total_bytes;
  147. /* bytes used */
  148. __le64 bytes_used;
  149. /* optimal io alignment for this device */
  150. __le32 io_align;
  151. /* optimal io width for this device */
  152. __le32 io_width;
  153. /* minimal io size for this device */
  154. __le32 sector_size;
  155. /* type and info about this device */
  156. __le64 type;
  157. /* expected generation for this device */
  158. __le64 generation;
  159. /*
  160. * starting byte of this partition on the device,
  161. * to allowr for stripe alignment in the future
  162. */
  163. __le64 start_offset;
  164. /* grouping information for allocation decisions */
  165. __le32 dev_group;
  166. /* seek speed 0-100 where 100 is fastest */
  167. u8 seek_speed;
  168. /* bandwidth 0-100 where 100 is fastest */
  169. u8 bandwidth;
  170. /* btrfs generated uuid for this device */
  171. u8 uuid[BTRFS_UUID_SIZE];
  172. /* uuid of FS who owns this device */
  173. u8 fsid[BTRFS_UUID_SIZE];
  174. } __attribute__ ((__packed__));
  175. struct btrfs_stripe {
  176. __le64 devid;
  177. __le64 offset;
  178. u8 dev_uuid[BTRFS_UUID_SIZE];
  179. } __attribute__ ((__packed__));
  180. struct btrfs_chunk {
  181. /* size of this chunk in bytes */
  182. __le64 length;
  183. /* objectid of the root referencing this chunk */
  184. __le64 owner;
  185. __le64 stripe_len;
  186. __le64 type;
  187. /* optimal io alignment for this chunk */
  188. __le32 io_align;
  189. /* optimal io width for this chunk */
  190. __le32 io_width;
  191. /* minimal io size for this chunk */
  192. __le32 sector_size;
  193. /* 2^16 stripes is quite a lot, a second limit is the size of a single
  194. * item in the btree
  195. */
  196. __le16 num_stripes;
  197. /* sub stripes only matter for raid10 */
  198. __le16 sub_stripes;
  199. struct btrfs_stripe stripe;
  200. /* additional stripes go here */
  201. } __attribute__ ((__packed__));
  202. static inline unsigned long btrfs_chunk_item_size(int num_stripes)
  203. {
  204. BUG_ON(num_stripes == 0);
  205. return sizeof(struct btrfs_chunk) +
  206. sizeof(struct btrfs_stripe) * (num_stripes - 1);
  207. }
  208. #define BTRFS_FSID_SIZE 16
  209. #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
  210. /*
  211. * every tree block (leaf or node) starts with this header.
  212. */
  213. struct btrfs_header {
  214. /* these first four must match the super block */
  215. u8 csum[BTRFS_CSUM_SIZE];
  216. u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
  217. __le64 bytenr; /* which block this node is supposed to live in */
  218. __le64 flags;
  219. /* allowed to be different from the super from here on down */
  220. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  221. __le64 generation;
  222. __le64 owner;
  223. __le32 nritems;
  224. u8 level;
  225. } __attribute__ ((__packed__));
  226. #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
  227. sizeof(struct btrfs_header)) / \
  228. sizeof(struct btrfs_key_ptr))
  229. #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
  230. #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
  231. #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
  232. sizeof(struct btrfs_item) - \
  233. sizeof(struct btrfs_file_extent_item))
  234. #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
  235. /*
  236. * this is a very generous portion of the super block, giving us
  237. * room to translate 14 chunks with 3 stripes each.
  238. */
  239. #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
  240. #define BTRFS_LABEL_SIZE 256
  241. /*
  242. * the super block basically lists the main trees of the FS
  243. * it currently lacks any block count etc etc
  244. */
  245. struct btrfs_super_block {
  246. u8 csum[BTRFS_CSUM_SIZE];
  247. /* the first 4 fields must match struct btrfs_header */
  248. u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
  249. __le64 bytenr; /* this block number */
  250. __le64 flags;
  251. /* allowed to be different from the btrfs_header from here own down */
  252. __le64 magic;
  253. __le64 generation;
  254. __le64 root;
  255. __le64 chunk_root;
  256. __le64 log_root;
  257. /* this will help find the new super based on the log root */
  258. __le64 log_root_transid;
  259. __le64 total_bytes;
  260. __le64 bytes_used;
  261. __le64 root_dir_objectid;
  262. __le64 num_devices;
  263. __le32 sectorsize;
  264. __le32 nodesize;
  265. __le32 leafsize;
  266. __le32 stripesize;
  267. __le32 sys_chunk_array_size;
  268. __le64 chunk_root_generation;
  269. __le64 compat_flags;
  270. __le64 compat_ro_flags;
  271. __le64 incompat_flags;
  272. __le16 csum_type;
  273. u8 root_level;
  274. u8 chunk_root_level;
  275. u8 log_root_level;
  276. struct btrfs_dev_item dev_item;
  277. char label[BTRFS_LABEL_SIZE];
  278. /* future expansion */
  279. __le64 reserved[32];
  280. u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
  281. } __attribute__ ((__packed__));
  282. /*
  283. * Compat flags that we support. If any incompat flags are set other than the
  284. * ones specified below then we will fail to mount
  285. */
  286. #define BTRFS_FEATURE_COMPAT_SUPP 0x0
  287. #define BTRFS_FEATURE_COMPAT_RO_SUPP 0x0
  288. #define BTRFS_FEATURE_INCOMPAT_SUPP 0x0
  289. /*
  290. * A leaf is full of items. offset and size tell us where to find
  291. * the item in the leaf (relative to the start of the data area)
  292. */
  293. struct btrfs_item {
  294. struct btrfs_disk_key key;
  295. __le32 offset;
  296. __le32 size;
  297. } __attribute__ ((__packed__));
  298. /*
  299. * leaves have an item area and a data area:
  300. * [item0, item1....itemN] [free space] [dataN...data1, data0]
  301. *
  302. * The data is separate from the items to get the keys closer together
  303. * during searches.
  304. */
  305. struct btrfs_leaf {
  306. struct btrfs_header header;
  307. struct btrfs_item items[];
  308. } __attribute__ ((__packed__));
  309. /*
  310. * all non-leaf blocks are nodes, they hold only keys and pointers to
  311. * other blocks
  312. */
  313. struct btrfs_key_ptr {
  314. struct btrfs_disk_key key;
  315. __le64 blockptr;
  316. __le64 generation;
  317. } __attribute__ ((__packed__));
  318. struct btrfs_node {
  319. struct btrfs_header header;
  320. struct btrfs_key_ptr ptrs[];
  321. } __attribute__ ((__packed__));
  322. /*
  323. * btrfs_paths remember the path taken from the root down to the leaf.
  324. * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
  325. * to any other levels that are present.
  326. *
  327. * The slots array records the index of the item or block pointer
  328. * used while walking the tree.
  329. */
  330. struct btrfs_path {
  331. struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
  332. int slots[BTRFS_MAX_LEVEL];
  333. /* if there is real range locking, this locks field will change */
  334. int locks[BTRFS_MAX_LEVEL];
  335. int reada;
  336. /* keep some upper locks as we walk down */
  337. int keep_locks;
  338. int skip_locking;
  339. int lowest_level;
  340. /*
  341. * set by btrfs_split_item, tells search_slot to keep all locks
  342. * and to force calls to keep space in the nodes
  343. */
  344. int search_for_split;
  345. };
  346. /*
  347. * items in the extent btree are used to record the objectid of the
  348. * owner of the block and the number of references
  349. */
  350. struct btrfs_extent_item {
  351. __le32 refs;
  352. } __attribute__ ((__packed__));
  353. struct btrfs_extent_ref {
  354. __le64 root;
  355. __le64 generation;
  356. __le64 objectid;
  357. __le32 num_refs;
  358. } __attribute__ ((__packed__));
  359. /* dev extents record free space on individual devices. The owner
  360. * field points back to the chunk allocation mapping tree that allocated
  361. * the extent. The chunk tree uuid field is a way to double check the owner
  362. */
  363. struct btrfs_dev_extent {
  364. __le64 chunk_tree;
  365. __le64 chunk_objectid;
  366. __le64 chunk_offset;
  367. __le64 length;
  368. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  369. } __attribute__ ((__packed__));
  370. struct btrfs_inode_ref {
  371. __le64 index;
  372. __le16 name_len;
  373. /* name goes here */
  374. } __attribute__ ((__packed__));
  375. struct btrfs_timespec {
  376. __le64 sec;
  377. __le32 nsec;
  378. } __attribute__ ((__packed__));
  379. typedef enum {
  380. BTRFS_COMPRESS_NONE = 0,
  381. BTRFS_COMPRESS_ZLIB = 1,
  382. BTRFS_COMPRESS_LAST = 2,
  383. } btrfs_compression_type;
  384. /* we don't understand any encryption methods right now */
  385. typedef enum {
  386. BTRFS_ENCRYPTION_NONE = 0,
  387. BTRFS_ENCRYPTION_LAST = 1,
  388. } btrfs_encryption_type;
  389. struct btrfs_inode_item {
  390. /* nfs style generation number */
  391. __le64 generation;
  392. /* transid that last touched this inode */
  393. __le64 transid;
  394. __le64 size;
  395. __le64 nbytes;
  396. __le64 block_group;
  397. __le32 nlink;
  398. __le32 uid;
  399. __le32 gid;
  400. __le32 mode;
  401. __le64 rdev;
  402. __le64 flags;
  403. /* modification sequence number for NFS */
  404. __le64 sequence;
  405. /*
  406. * a little future expansion, for more than this we can
  407. * just grow the inode item and version it
  408. */
  409. __le64 reserved[4];
  410. struct btrfs_timespec atime;
  411. struct btrfs_timespec ctime;
  412. struct btrfs_timespec mtime;
  413. struct btrfs_timespec otime;
  414. } __attribute__ ((__packed__));
  415. struct btrfs_dir_log_item {
  416. __le64 end;
  417. } __attribute__ ((__packed__));
  418. struct btrfs_dir_item {
  419. struct btrfs_disk_key location;
  420. __le64 transid;
  421. __le16 data_len;
  422. __le16 name_len;
  423. u8 type;
  424. } __attribute__ ((__packed__));
  425. struct btrfs_root_item {
  426. struct btrfs_inode_item inode;
  427. __le64 generation;
  428. __le64 root_dirid;
  429. __le64 bytenr;
  430. __le64 byte_limit;
  431. __le64 bytes_used;
  432. __le64 last_snapshot;
  433. __le64 flags;
  434. __le32 refs;
  435. struct btrfs_disk_key drop_progress;
  436. u8 drop_level;
  437. u8 level;
  438. } __attribute__ ((__packed__));
  439. /*
  440. * this is used for both forward and backward root refs
  441. */
  442. struct btrfs_root_ref {
  443. __le64 dirid;
  444. __le64 sequence;
  445. __le16 name_len;
  446. } __attribute__ ((__packed__));
  447. #define BTRFS_FILE_EXTENT_INLINE 0
  448. #define BTRFS_FILE_EXTENT_REG 1
  449. #define BTRFS_FILE_EXTENT_PREALLOC 2
  450. struct btrfs_file_extent_item {
  451. /*
  452. * transaction id that created this extent
  453. */
  454. __le64 generation;
  455. /*
  456. * max number of bytes to hold this extent in ram
  457. * when we split a compressed extent we can't know how big
  458. * each of the resulting pieces will be. So, this is
  459. * an upper limit on the size of the extent in ram instead of
  460. * an exact limit.
  461. */
  462. __le64 ram_bytes;
  463. /*
  464. * 32 bits for the various ways we might encode the data,
  465. * including compression and encryption. If any of these
  466. * are set to something a given disk format doesn't understand
  467. * it is treated like an incompat flag for reading and writing,
  468. * but not for stat.
  469. */
  470. u8 compression;
  471. u8 encryption;
  472. __le16 other_encoding; /* spare for later use */
  473. /* are we inline data or a real extent? */
  474. u8 type;
  475. /*
  476. * disk space consumed by the extent, checksum blocks are included
  477. * in these numbers
  478. */
  479. __le64 disk_bytenr;
  480. __le64 disk_num_bytes;
  481. /*
  482. * the logical offset in file blocks (no csums)
  483. * this extent record is for. This allows a file extent to point
  484. * into the middle of an existing extent on disk, sharing it
  485. * between two snapshots (useful if some bytes in the middle of the
  486. * extent have changed
  487. */
  488. __le64 offset;
  489. /*
  490. * the logical number of file blocks (no csums included). This
  491. * always reflects the size uncompressed and without encoding.
  492. */
  493. __le64 num_bytes;
  494. } __attribute__ ((__packed__));
  495. struct btrfs_csum_item {
  496. u8 csum;
  497. } __attribute__ ((__packed__));
  498. /* different types of block groups (and chunks) */
  499. #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
  500. #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
  501. #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
  502. #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
  503. #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
  504. #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
  505. #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
  506. struct btrfs_block_group_item {
  507. __le64 used;
  508. __le64 chunk_objectid;
  509. __le64 flags;
  510. } __attribute__ ((__packed__));
  511. struct btrfs_space_info {
  512. u64 flags;
  513. u64 total_bytes;
  514. u64 bytes_used;
  515. u64 bytes_pinned;
  516. u64 bytes_reserved;
  517. u64 bytes_readonly;
  518. int full;
  519. int force_alloc;
  520. struct list_head list;
  521. /* for block groups in our same type */
  522. struct list_head block_groups;
  523. spinlock_t lock;
  524. struct rw_semaphore groups_sem;
  525. };
  526. struct btrfs_free_space {
  527. struct rb_node bytes_index;
  528. struct rb_node offset_index;
  529. u64 offset;
  530. u64 bytes;
  531. };
  532. struct btrfs_block_group_cache {
  533. struct btrfs_key key;
  534. struct btrfs_block_group_item item;
  535. spinlock_t lock;
  536. struct mutex alloc_mutex;
  537. struct mutex cache_mutex;
  538. u64 pinned;
  539. u64 reserved;
  540. u64 flags;
  541. int cached;
  542. int ro;
  543. int dirty;
  544. struct btrfs_space_info *space_info;
  545. /* free space cache stuff */
  546. struct rb_root free_space_bytes;
  547. struct rb_root free_space_offset;
  548. /* block group cache stuff */
  549. struct rb_node cache_node;
  550. /* for block groups in the same raid type */
  551. struct list_head list;
  552. /* usage count */
  553. atomic_t count;
  554. };
  555. struct btrfs_leaf_ref_tree {
  556. struct rb_root root;
  557. struct list_head list;
  558. spinlock_t lock;
  559. };
  560. struct btrfs_device;
  561. struct btrfs_fs_devices;
  562. struct btrfs_fs_info {
  563. u8 fsid[BTRFS_FSID_SIZE];
  564. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  565. struct btrfs_root *extent_root;
  566. struct btrfs_root *tree_root;
  567. struct btrfs_root *chunk_root;
  568. struct btrfs_root *dev_root;
  569. struct btrfs_root *fs_root;
  570. struct btrfs_root *csum_root;
  571. /* the log root tree is a directory of all the other log roots */
  572. struct btrfs_root *log_root_tree;
  573. struct radix_tree_root fs_roots_radix;
  574. /* block group cache stuff */
  575. spinlock_t block_group_cache_lock;
  576. struct rb_root block_group_cache_tree;
  577. struct extent_io_tree pinned_extents;
  578. struct extent_io_tree pending_del;
  579. struct extent_io_tree extent_ins;
  580. /* logical->physical extent mapping */
  581. struct btrfs_mapping_tree mapping_tree;
  582. u64 generation;
  583. u64 last_trans_committed;
  584. u64 last_trans_new_blockgroup;
  585. u64 open_ioctl_trans;
  586. unsigned long mount_opt;
  587. u64 max_extent;
  588. u64 max_inline;
  589. u64 alloc_start;
  590. struct btrfs_transaction *running_transaction;
  591. wait_queue_head_t transaction_throttle;
  592. wait_queue_head_t transaction_wait;
  593. wait_queue_head_t async_submit_wait;
  594. wait_queue_head_t tree_log_wait;
  595. struct btrfs_super_block super_copy;
  596. struct btrfs_super_block super_for_commit;
  597. struct block_device *__bdev;
  598. struct super_block *sb;
  599. struct inode *btree_inode;
  600. struct backing_dev_info bdi;
  601. spinlock_t hash_lock;
  602. struct mutex trans_mutex;
  603. struct mutex tree_log_mutex;
  604. struct mutex transaction_kthread_mutex;
  605. struct mutex cleaner_mutex;
  606. struct mutex extent_ins_mutex;
  607. struct mutex pinned_mutex;
  608. struct mutex chunk_mutex;
  609. struct mutex drop_mutex;
  610. struct mutex volume_mutex;
  611. struct mutex tree_reloc_mutex;
  612. struct list_head trans_list;
  613. struct list_head hashers;
  614. struct list_head dead_roots;
  615. atomic_t nr_async_submits;
  616. atomic_t async_submit_draining;
  617. atomic_t nr_async_bios;
  618. atomic_t async_delalloc_pages;
  619. atomic_t tree_log_writers;
  620. atomic_t tree_log_commit;
  621. unsigned long tree_log_batch;
  622. u64 tree_log_transid;
  623. /*
  624. * this is used by the balancing code to wait for all the pending
  625. * ordered extents
  626. */
  627. spinlock_t ordered_extent_lock;
  628. struct list_head ordered_extents;
  629. struct list_head delalloc_inodes;
  630. /*
  631. * there is a pool of worker threads for checksumming during writes
  632. * and a pool for checksumming after reads. This is because readers
  633. * can run with FS locks held, and the writers may be waiting for
  634. * those locks. We don't want ordering in the pending list to cause
  635. * deadlocks, and so the two are serviced separately.
  636. *
  637. * A third pool does submit_bio to avoid deadlocking with the other
  638. * two
  639. */
  640. struct btrfs_workers workers;
  641. struct btrfs_workers delalloc_workers;
  642. struct btrfs_workers endio_workers;
  643. struct btrfs_workers endio_meta_workers;
  644. struct btrfs_workers endio_meta_write_workers;
  645. struct btrfs_workers endio_write_workers;
  646. struct btrfs_workers submit_workers;
  647. /*
  648. * fixup workers take dirty pages that didn't properly go through
  649. * the cow mechanism and make them safe to write. It happens
  650. * for the sys_munmap function call path
  651. */
  652. struct btrfs_workers fixup_workers;
  653. struct task_struct *transaction_kthread;
  654. struct task_struct *cleaner_kthread;
  655. int thread_pool_size;
  656. /* tree relocation relocated fields */
  657. struct list_head dead_reloc_roots;
  658. struct btrfs_leaf_ref_tree reloc_ref_tree;
  659. struct btrfs_leaf_ref_tree shared_ref_tree;
  660. struct kobject super_kobj;
  661. struct completion kobj_unregister;
  662. int do_barriers;
  663. int closing;
  664. int log_root_recovering;
  665. atomic_t throttles;
  666. atomic_t throttle_gen;
  667. u64 total_pinned;
  668. struct list_head dirty_cowonly_roots;
  669. struct btrfs_fs_devices *fs_devices;
  670. struct list_head space_info;
  671. spinlock_t delalloc_lock;
  672. spinlock_t new_trans_lock;
  673. u64 delalloc_bytes;
  674. u64 last_alloc;
  675. u64 last_data_alloc;
  676. spinlock_t ref_cache_lock;
  677. u64 total_ref_cache_size;
  678. u64 avail_data_alloc_bits;
  679. u64 avail_metadata_alloc_bits;
  680. u64 avail_system_alloc_bits;
  681. u64 data_alloc_profile;
  682. u64 metadata_alloc_profile;
  683. u64 system_alloc_profile;
  684. void *bdev_holder;
  685. };
  686. /*
  687. * in ram representation of the tree. extent_root is used for all allocations
  688. * and for the extent tree extent_root root.
  689. */
  690. struct btrfs_dirty_root;
  691. struct btrfs_root {
  692. struct extent_buffer *node;
  693. /* the node lock is held while changing the node pointer */
  694. spinlock_t node_lock;
  695. struct extent_buffer *commit_root;
  696. struct btrfs_leaf_ref_tree *ref_tree;
  697. struct btrfs_leaf_ref_tree ref_tree_struct;
  698. struct btrfs_dirty_root *dirty_root;
  699. struct btrfs_root *log_root;
  700. struct btrfs_root *reloc_root;
  701. struct btrfs_root_item root_item;
  702. struct btrfs_key root_key;
  703. struct btrfs_fs_info *fs_info;
  704. struct extent_io_tree dirty_log_pages;
  705. struct kobject root_kobj;
  706. struct completion kobj_unregister;
  707. struct mutex objectid_mutex;
  708. struct mutex log_mutex;
  709. u64 objectid;
  710. u64 last_trans;
  711. /* data allocations are done in sectorsize units */
  712. u32 sectorsize;
  713. /* node allocations are done in nodesize units */
  714. u32 nodesize;
  715. /* leaf allocations are done in leafsize units */
  716. u32 leafsize;
  717. u32 stripesize;
  718. u32 type;
  719. u64 highest_inode;
  720. u64 last_inode_alloc;
  721. int ref_cows;
  722. int track_dirty;
  723. u64 defrag_trans_start;
  724. struct btrfs_key defrag_progress;
  725. struct btrfs_key defrag_max;
  726. int defrag_running;
  727. int defrag_level;
  728. char *name;
  729. int in_sysfs;
  730. /* the dirty list is only used by non-reference counted roots */
  731. struct list_head dirty_list;
  732. spinlock_t list_lock;
  733. struct list_head dead_list;
  734. struct list_head orphan_list;
  735. /*
  736. * right now this just gets used so that a root has its own devid
  737. * for stat. It may be used for more later
  738. */
  739. struct super_block anon_super;
  740. };
  741. /*
  742. * inode items have the data typically returned from stat and store other
  743. * info about object characteristics. There is one for every file and dir in
  744. * the FS
  745. */
  746. #define BTRFS_INODE_ITEM_KEY 1
  747. #define BTRFS_INODE_REF_KEY 12
  748. #define BTRFS_XATTR_ITEM_KEY 24
  749. #define BTRFS_ORPHAN_ITEM_KEY 48
  750. /* reserve 2-15 close to the inode for later flexibility */
  751. /*
  752. * dir items are the name -> inode pointers in a directory. There is one
  753. * for every name in a directory.
  754. */
  755. #define BTRFS_DIR_LOG_ITEM_KEY 60
  756. #define BTRFS_DIR_LOG_INDEX_KEY 72
  757. #define BTRFS_DIR_ITEM_KEY 84
  758. #define BTRFS_DIR_INDEX_KEY 96
  759. /*
  760. * extent data is for file data
  761. */
  762. #define BTRFS_EXTENT_DATA_KEY 108
  763. /*
  764. * extent csums are stored in a separate tree and hold csums for
  765. * an entire extent on disk.
  766. */
  767. #define BTRFS_EXTENT_CSUM_KEY 128
  768. /*
  769. * root items point to tree roots. There are typically in the root
  770. * tree used by the super block to find all the other trees
  771. */
  772. #define BTRFS_ROOT_ITEM_KEY 132
  773. /*
  774. * root backrefs tie subvols and snapshots to the directory entries that
  775. * reference them
  776. */
  777. #define BTRFS_ROOT_BACKREF_KEY 144
  778. /*
  779. * root refs make a fast index for listing all of the snapshots and
  780. * subvolumes referenced by a given root. They point directly to the
  781. * directory item in the root that references the subvol
  782. */
  783. #define BTRFS_ROOT_REF_KEY 156
  784. /*
  785. * extent items are in the extent map tree. These record which blocks
  786. * are used, and how many references there are to each block
  787. */
  788. #define BTRFS_EXTENT_ITEM_KEY 168
  789. #define BTRFS_EXTENT_REF_KEY 180
  790. /*
  791. * block groups give us hints into the extent allocation trees. Which
  792. * blocks are free etc etc
  793. */
  794. #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
  795. #define BTRFS_DEV_EXTENT_KEY 204
  796. #define BTRFS_DEV_ITEM_KEY 216
  797. #define BTRFS_CHUNK_ITEM_KEY 228
  798. /*
  799. * string items are for debugging. They just store a short string of
  800. * data in the FS
  801. */
  802. #define BTRFS_STRING_ITEM_KEY 253
  803. #define BTRFS_MOUNT_NODATASUM (1 << 0)
  804. #define BTRFS_MOUNT_NODATACOW (1 << 1)
  805. #define BTRFS_MOUNT_NOBARRIER (1 << 2)
  806. #define BTRFS_MOUNT_SSD (1 << 3)
  807. #define BTRFS_MOUNT_DEGRADED (1 << 4)
  808. #define BTRFS_MOUNT_COMPRESS (1 << 5)
  809. #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
  810. #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
  811. #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \
  812. BTRFS_MOUNT_##opt)
  813. /*
  814. * Inode flags
  815. */
  816. #define BTRFS_INODE_NODATASUM (1 << 0)
  817. #define BTRFS_INODE_NODATACOW (1 << 1)
  818. #define BTRFS_INODE_READONLY (1 << 2)
  819. #define BTRFS_INODE_NOCOMPRESS (1 << 3)
  820. #define BTRFS_INODE_PREALLOC (1 << 4)
  821. #define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \
  822. ~BTRFS_INODE_##flag)
  823. #define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \
  824. BTRFS_INODE_##flag)
  825. #define btrfs_test_flag(inode, flag) (BTRFS_I(inode)->flags & \
  826. BTRFS_INODE_##flag)
  827. /* some macros to generate set/get funcs for the struct fields. This
  828. * assumes there is a lefoo_to_cpu for every type, so lets make a simple
  829. * one for u8:
  830. */
  831. #define le8_to_cpu(v) (v)
  832. #define cpu_to_le8(v) (v)
  833. #define __le8 u8
  834. #define read_eb_member(eb, ptr, type, member, result) ( \
  835. read_extent_buffer(eb, (char *)(result), \
  836. ((unsigned long)(ptr)) + \
  837. offsetof(type, member), \
  838. sizeof(((type *)0)->member)))
  839. #define write_eb_member(eb, ptr, type, member, result) ( \
  840. write_extent_buffer(eb, (char *)(result), \
  841. ((unsigned long)(ptr)) + \
  842. offsetof(type, member), \
  843. sizeof(((type *)0)->member)))
  844. #ifndef BTRFS_SETGET_FUNCS
  845. #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
  846. u##bits btrfs_##name(struct extent_buffer *eb, type *s); \
  847. void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val);
  848. #endif
  849. #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
  850. static inline u##bits btrfs_##name(struct extent_buffer *eb) \
  851. { \
  852. type *p = kmap_atomic(eb->first_page, KM_USER0); \
  853. u##bits res = le##bits##_to_cpu(p->member); \
  854. kunmap_atomic(p, KM_USER0); \
  855. return res; \
  856. } \
  857. static inline void btrfs_set_##name(struct extent_buffer *eb, \
  858. u##bits val) \
  859. { \
  860. type *p = kmap_atomic(eb->first_page, KM_USER0); \
  861. p->member = cpu_to_le##bits(val); \
  862. kunmap_atomic(p, KM_USER0); \
  863. }
  864. #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
  865. static inline u##bits btrfs_##name(type *s) \
  866. { \
  867. return le##bits##_to_cpu(s->member); \
  868. } \
  869. static inline void btrfs_set_##name(type *s, u##bits val) \
  870. { \
  871. s->member = cpu_to_le##bits(val); \
  872. }
  873. BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
  874. BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
  875. BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
  876. BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
  877. BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
  878. BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item,
  879. start_offset, 64);
  880. BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
  881. BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
  882. BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
  883. BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
  884. BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
  885. BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
  886. BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
  887. BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
  888. total_bytes, 64);
  889. BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
  890. bytes_used, 64);
  891. BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
  892. io_align, 32);
  893. BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
  894. io_width, 32);
  895. BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
  896. sector_size, 32);
  897. BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
  898. BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
  899. dev_group, 32);
  900. BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
  901. seek_speed, 8);
  902. BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
  903. bandwidth, 8);
  904. BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
  905. generation, 64);
  906. static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
  907. {
  908. return (char *)d + offsetof(struct btrfs_dev_item, uuid);
  909. }
  910. static inline char *btrfs_device_fsid(struct btrfs_dev_item *d)
  911. {
  912. return (char *)d + offsetof(struct btrfs_dev_item, fsid);
  913. }
  914. BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
  915. BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
  916. BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
  917. BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
  918. BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
  919. BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
  920. BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
  921. BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
  922. BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
  923. BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
  924. BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
  925. static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
  926. {
  927. return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
  928. }
  929. BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
  930. BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
  931. BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
  932. stripe_len, 64);
  933. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
  934. io_align, 32);
  935. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
  936. io_width, 32);
  937. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
  938. sector_size, 32);
  939. BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
  940. BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
  941. num_stripes, 16);
  942. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
  943. sub_stripes, 16);
  944. BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
  945. BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
  946. static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
  947. int nr)
  948. {
  949. unsigned long offset = (unsigned long)c;
  950. offset += offsetof(struct btrfs_chunk, stripe);
  951. offset += nr * sizeof(struct btrfs_stripe);
  952. return (struct btrfs_stripe *)offset;
  953. }
  954. static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
  955. {
  956. return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
  957. }
  958. static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
  959. struct btrfs_chunk *c, int nr)
  960. {
  961. return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
  962. }
  963. static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
  964. struct btrfs_chunk *c, int nr,
  965. u64 val)
  966. {
  967. btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
  968. }
  969. static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
  970. struct btrfs_chunk *c, int nr)
  971. {
  972. return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
  973. }
  974. static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
  975. struct btrfs_chunk *c, int nr,
  976. u64 val)
  977. {
  978. btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
  979. }
  980. /* struct btrfs_block_group_item */
  981. BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
  982. used, 64);
  983. BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
  984. used, 64);
  985. BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
  986. struct btrfs_block_group_item, chunk_objectid, 64);
  987. BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
  988. struct btrfs_block_group_item, chunk_objectid, 64);
  989. BTRFS_SETGET_FUNCS(disk_block_group_flags,
  990. struct btrfs_block_group_item, flags, 64);
  991. BTRFS_SETGET_STACK_FUNCS(block_group_flags,
  992. struct btrfs_block_group_item, flags, 64);
  993. /* struct btrfs_inode_ref */
  994. BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
  995. BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
  996. /* struct btrfs_inode_item */
  997. BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
  998. BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
  999. BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
  1000. BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
  1001. BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
  1002. BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
  1003. BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
  1004. BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
  1005. BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
  1006. BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
  1007. BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
  1008. BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
  1009. static inline struct btrfs_timespec *
  1010. btrfs_inode_atime(struct btrfs_inode_item *inode_item)
  1011. {
  1012. unsigned long ptr = (unsigned long)inode_item;
  1013. ptr += offsetof(struct btrfs_inode_item, atime);
  1014. return (struct btrfs_timespec *)ptr;
  1015. }
  1016. static inline struct btrfs_timespec *
  1017. btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
  1018. {
  1019. unsigned long ptr = (unsigned long)inode_item;
  1020. ptr += offsetof(struct btrfs_inode_item, mtime);
  1021. return (struct btrfs_timespec *)ptr;
  1022. }
  1023. static inline struct btrfs_timespec *
  1024. btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
  1025. {
  1026. unsigned long ptr = (unsigned long)inode_item;
  1027. ptr += offsetof(struct btrfs_inode_item, ctime);
  1028. return (struct btrfs_timespec *)ptr;
  1029. }
  1030. static inline struct btrfs_timespec *
  1031. btrfs_inode_otime(struct btrfs_inode_item *inode_item)
  1032. {
  1033. unsigned long ptr = (unsigned long)inode_item;
  1034. ptr += offsetof(struct btrfs_inode_item, otime);
  1035. return (struct btrfs_timespec *)ptr;
  1036. }
  1037. BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
  1038. BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
  1039. /* struct btrfs_dev_extent */
  1040. BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
  1041. chunk_tree, 64);
  1042. BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
  1043. chunk_objectid, 64);
  1044. BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
  1045. chunk_offset, 64);
  1046. BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
  1047. static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
  1048. {
  1049. unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
  1050. return (u8 *)((unsigned long)dev + ptr);
  1051. }
  1052. /* struct btrfs_extent_ref */
  1053. BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
  1054. BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
  1055. BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
  1056. BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32);
  1057. BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
  1058. BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
  1059. generation, 64);
  1060. BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
  1061. objectid, 64);
  1062. BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref,
  1063. num_refs, 32);
  1064. /* struct btrfs_extent_item */
  1065. BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
  1066. BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
  1067. refs, 32);
  1068. /* struct btrfs_node */
  1069. BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
  1070. BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
  1071. static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
  1072. {
  1073. unsigned long ptr;
  1074. ptr = offsetof(struct btrfs_node, ptrs) +
  1075. sizeof(struct btrfs_key_ptr) * nr;
  1076. return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
  1077. }
  1078. static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
  1079. int nr, u64 val)
  1080. {
  1081. unsigned long ptr;
  1082. ptr = offsetof(struct btrfs_node, ptrs) +
  1083. sizeof(struct btrfs_key_ptr) * nr;
  1084. btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
  1085. }
  1086. static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
  1087. {
  1088. unsigned long ptr;
  1089. ptr = offsetof(struct btrfs_node, ptrs) +
  1090. sizeof(struct btrfs_key_ptr) * nr;
  1091. return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
  1092. }
  1093. static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
  1094. int nr, u64 val)
  1095. {
  1096. unsigned long ptr;
  1097. ptr = offsetof(struct btrfs_node, ptrs) +
  1098. sizeof(struct btrfs_key_ptr) * nr;
  1099. btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
  1100. }
  1101. static inline unsigned long btrfs_node_key_ptr_offset(int nr)
  1102. {
  1103. return offsetof(struct btrfs_node, ptrs) +
  1104. sizeof(struct btrfs_key_ptr) * nr;
  1105. }
  1106. void btrfs_node_key(struct extent_buffer *eb,
  1107. struct btrfs_disk_key *disk_key, int nr);
  1108. static inline void btrfs_set_node_key(struct extent_buffer *eb,
  1109. struct btrfs_disk_key *disk_key, int nr)
  1110. {
  1111. unsigned long ptr;
  1112. ptr = btrfs_node_key_ptr_offset(nr);
  1113. write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
  1114. struct btrfs_key_ptr, key, disk_key);
  1115. }
  1116. /* struct btrfs_item */
  1117. BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
  1118. BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
  1119. static inline unsigned long btrfs_item_nr_offset(int nr)
  1120. {
  1121. return offsetof(struct btrfs_leaf, items) +
  1122. sizeof(struct btrfs_item) * nr;
  1123. }
  1124. static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
  1125. int nr)
  1126. {
  1127. return (struct btrfs_item *)btrfs_item_nr_offset(nr);
  1128. }
  1129. static inline u32 btrfs_item_end(struct extent_buffer *eb,
  1130. struct btrfs_item *item)
  1131. {
  1132. return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
  1133. }
  1134. static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
  1135. {
  1136. return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
  1137. }
  1138. static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
  1139. {
  1140. return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
  1141. }
  1142. static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
  1143. {
  1144. return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
  1145. }
  1146. static inline void btrfs_item_key(struct extent_buffer *eb,
  1147. struct btrfs_disk_key *disk_key, int nr)
  1148. {
  1149. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  1150. read_eb_member(eb, item, struct btrfs_item, key, disk_key);
  1151. }
  1152. static inline void btrfs_set_item_key(struct extent_buffer *eb,
  1153. struct btrfs_disk_key *disk_key, int nr)
  1154. {
  1155. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  1156. write_eb_member(eb, item, struct btrfs_item, key, disk_key);
  1157. }
  1158. BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);
  1159. /*
  1160. * struct btrfs_root_ref
  1161. */
  1162. BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
  1163. BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
  1164. BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
  1165. /* struct btrfs_dir_item */
  1166. BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
  1167. BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
  1168. BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
  1169. BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
  1170. static inline void btrfs_dir_item_key(struct extent_buffer *eb,
  1171. struct btrfs_dir_item *item,
  1172. struct btrfs_disk_key *key)
  1173. {
  1174. read_eb_member(eb, item, struct btrfs_dir_item, location, key);
  1175. }
  1176. static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
  1177. struct btrfs_dir_item *item,
  1178. struct btrfs_disk_key *key)
  1179. {
  1180. write_eb_member(eb, item, struct btrfs_dir_item, location, key);
  1181. }
  1182. /* struct btrfs_disk_key */
  1183. BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
  1184. objectid, 64);
  1185. BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
  1186. BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
  1187. static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
  1188. struct btrfs_disk_key *disk)
  1189. {
  1190. cpu->offset = le64_to_cpu(disk->offset);
  1191. cpu->type = disk->type;
  1192. cpu->objectid = le64_to_cpu(disk->objectid);
  1193. }
  1194. static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
  1195. struct btrfs_key *cpu)
  1196. {
  1197. disk->offset = cpu_to_le64(cpu->offset);
  1198. disk->type = cpu->type;
  1199. disk->objectid = cpu_to_le64(cpu->objectid);
  1200. }
  1201. static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
  1202. struct btrfs_key *key, int nr)
  1203. {
  1204. struct btrfs_disk_key disk_key;
  1205. btrfs_node_key(eb, &disk_key, nr);
  1206. btrfs_disk_key_to_cpu(key, &disk_key);
  1207. }
  1208. static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
  1209. struct btrfs_key *key, int nr)
  1210. {
  1211. struct btrfs_disk_key disk_key;
  1212. btrfs_item_key(eb, &disk_key, nr);
  1213. btrfs_disk_key_to_cpu(key, &disk_key);
  1214. }
  1215. static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
  1216. struct btrfs_dir_item *item,
  1217. struct btrfs_key *key)
  1218. {
  1219. struct btrfs_disk_key disk_key;
  1220. btrfs_dir_item_key(eb, item, &disk_key);
  1221. btrfs_disk_key_to_cpu(key, &disk_key);
  1222. }
  1223. static inline u8 btrfs_key_type(struct btrfs_key *key)
  1224. {
  1225. return key->type;
  1226. }
  1227. static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
  1228. {
  1229. key->type = val;
  1230. }
  1231. /* struct btrfs_header */
  1232. BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
  1233. BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
  1234. generation, 64);
  1235. BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
  1236. BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
  1237. BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
  1238. BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
  1239. static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
  1240. {
  1241. return (btrfs_header_flags(eb) & flag) == flag;
  1242. }
  1243. static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
  1244. {
  1245. u64 flags = btrfs_header_flags(eb);
  1246. btrfs_set_header_flags(eb, flags | flag);
  1247. return (flags & flag) == flag;
  1248. }
  1249. static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
  1250. {
  1251. u64 flags = btrfs_header_flags(eb);
  1252. btrfs_set_header_flags(eb, flags & ~flag);
  1253. return (flags & flag) == flag;
  1254. }
  1255. static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
  1256. {
  1257. unsigned long ptr = offsetof(struct btrfs_header, fsid);
  1258. return (u8 *)ptr;
  1259. }
  1260. static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
  1261. {
  1262. unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
  1263. return (u8 *)ptr;
  1264. }
  1265. static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
  1266. {
  1267. unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
  1268. return (u8 *)ptr;
  1269. }
  1270. static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
  1271. {
  1272. unsigned long ptr = offsetof(struct btrfs_header, csum);
  1273. return (u8 *)ptr;
  1274. }
  1275. static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
  1276. {
  1277. return NULL;
  1278. }
  1279. static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
  1280. {
  1281. return NULL;
  1282. }
  1283. static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
  1284. {
  1285. return NULL;
  1286. }
  1287. static inline int btrfs_is_leaf(struct extent_buffer *eb)
  1288. {
  1289. return btrfs_header_level(eb) == 0;
  1290. }
  1291. /* struct btrfs_root_item */
  1292. BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
  1293. generation, 64);
  1294. BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
  1295. BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
  1296. BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
  1297. BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
  1298. generation, 64);
  1299. BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
  1300. BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
  1301. BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
  1302. BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
  1303. BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
  1304. BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
  1305. BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
  1306. BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
  1307. last_snapshot, 64);
  1308. /* struct btrfs_super_block */
  1309. BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
  1310. BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
  1311. BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
  1312. generation, 64);
  1313. BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
  1314. BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
  1315. struct btrfs_super_block, sys_chunk_array_size, 32);
  1316. BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
  1317. struct btrfs_super_block, chunk_root_generation, 64);
  1318. BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
  1319. root_level, 8);
  1320. BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
  1321. chunk_root, 64);
  1322. BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
  1323. chunk_root_level, 8);
  1324. BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
  1325. log_root, 64);
  1326. BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
  1327. log_root_transid, 64);
  1328. BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
  1329. log_root_level, 8);
  1330. BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
  1331. total_bytes, 64);
  1332. BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
  1333. bytes_used, 64);
  1334. BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
  1335. sectorsize, 32);
  1336. BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
  1337. nodesize, 32);
  1338. BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
  1339. leafsize, 32);
  1340. BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
  1341. stripesize, 32);
  1342. BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
  1343. root_dir_objectid, 64);
  1344. BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
  1345. num_devices, 64);
  1346. BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
  1347. compat_flags, 64);
  1348. BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
  1349. compat_flags, 64);
  1350. BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
  1351. incompat_flags, 64);
  1352. BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
  1353. csum_type, 16);
  1354. static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
  1355. {
  1356. int t = btrfs_super_csum_type(s);
  1357. BUG_ON(t >= ARRAY_SIZE(btrfs_csum_sizes));
  1358. return btrfs_csum_sizes[t];
  1359. }
  1360. static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
  1361. {
  1362. return offsetof(struct btrfs_leaf, items);
  1363. }
  1364. /* struct btrfs_file_extent_item */
  1365. BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
  1366. static inline unsigned long
  1367. btrfs_file_extent_inline_start(struct btrfs_file_extent_item *e)
  1368. {
  1369. unsigned long offset = (unsigned long)e;
  1370. offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
  1371. return offset;
  1372. }
  1373. static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
  1374. {
  1375. return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
  1376. }
  1377. BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
  1378. disk_bytenr, 64);
  1379. BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
  1380. generation, 64);
  1381. BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
  1382. disk_num_bytes, 64);
  1383. BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
  1384. offset, 64);
  1385. BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
  1386. num_bytes, 64);
  1387. BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
  1388. ram_bytes, 64);
  1389. BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
  1390. compression, 8);
  1391. BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
  1392. encryption, 8);
  1393. BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
  1394. other_encoding, 16);
  1395. /* this returns the number of file bytes represented by the inline item.
  1396. * If an item is compressed, this is the uncompressed size
  1397. */
  1398. static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
  1399. struct btrfs_file_extent_item *e)
  1400. {
  1401. return btrfs_file_extent_ram_bytes(eb, e);
  1402. }
  1403. /*
  1404. * this returns the number of bytes used by the item on disk, minus the
  1405. * size of any extent headers. If a file is compressed on disk, this is
  1406. * the compressed size
  1407. */
  1408. static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
  1409. struct btrfs_item *e)
  1410. {
  1411. unsigned long offset;
  1412. offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
  1413. return btrfs_item_size(eb, e) - offset;
  1414. }
  1415. static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
  1416. {
  1417. return sb->s_fs_info;
  1418. }
  1419. static inline int btrfs_set_root_name(struct btrfs_root *root,
  1420. const char *name, int len)
  1421. {
  1422. /* if we already have a name just free it */
  1423. kfree(root->name);
  1424. root->name = kmalloc(len+1, GFP_KERNEL);
  1425. if (!root->name)
  1426. return -ENOMEM;
  1427. memcpy(root->name, name, len);
  1428. root->name[len] = '\0';
  1429. return 0;
  1430. }
  1431. static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
  1432. {
  1433. if (level == 0)
  1434. return root->leafsize;
  1435. return root->nodesize;
  1436. }
  1437. /* helper function to cast into the data area of the leaf. */
  1438. #define btrfs_item_ptr(leaf, slot, type) \
  1439. ((type *)(btrfs_leaf_data(leaf) + \
  1440. btrfs_item_offset_nr(leaf, slot)))
  1441. #define btrfs_item_ptr_offset(leaf, slot) \
  1442. ((unsigned long)(btrfs_leaf_data(leaf) + \
  1443. btrfs_item_offset_nr(leaf, slot)))
  1444. static inline struct dentry *fdentry(struct file *file)
  1445. {
  1446. return file->f_path.dentry;
  1447. }
  1448. /* extent-tree.c */
  1449. int btrfs_lookup_extent(struct btrfs_root *root, u64 start, u64 len);
  1450. int btrfs_lookup_extent_ref(struct btrfs_trans_handle *trans,
  1451. struct btrfs_root *root, u64 bytenr,
  1452. u64 num_bytes, u32 *refs);
  1453. int btrfs_update_pinned_extents(struct btrfs_root *root,
  1454. u64 bytenr, u64 num, int pin);
  1455. int btrfs_drop_leaf_ref(struct btrfs_trans_handle *trans,
  1456. struct btrfs_root *root, struct extent_buffer *leaf);
  1457. int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans,
  1458. struct btrfs_root *root, u64 objectid, u64 bytenr);
  1459. int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
  1460. struct btrfs_root *root);
  1461. int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
  1462. struct btrfs_block_group_cache *btrfs_lookup_block_group(
  1463. struct btrfs_fs_info *info,
  1464. u64 bytenr);
  1465. u64 btrfs_find_block_group(struct btrfs_root *root,
  1466. u64 search_start, u64 search_hint, int owner);
  1467. struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
  1468. struct btrfs_root *root,
  1469. u32 blocksize, u64 parent,
  1470. u64 root_objectid,
  1471. u64 ref_generation,
  1472. int level,
  1473. u64 hint,
  1474. u64 empty_size);
  1475. struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans,
  1476. struct btrfs_root *root,
  1477. u64 bytenr, u32 blocksize);
  1478. int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
  1479. struct btrfs_root *root,
  1480. u64 num_bytes, u64 parent, u64 min_bytes,
  1481. u64 root_objectid, u64 ref_generation,
  1482. u64 owner, u64 empty_size, u64 hint_byte,
  1483. u64 search_end, struct btrfs_key *ins, u64 data);
  1484. int btrfs_alloc_reserved_extent(struct btrfs_trans_handle *trans,
  1485. struct btrfs_root *root, u64 parent,
  1486. u64 root_objectid, u64 ref_generation,
  1487. u64 owner, struct btrfs_key *ins);
  1488. int btrfs_alloc_logged_extent(struct btrfs_trans_handle *trans,
  1489. struct btrfs_root *root, u64 parent,
  1490. u64 root_objectid, u64 ref_generation,
  1491. u64 owner, struct btrfs_key *ins);
  1492. int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
  1493. struct btrfs_root *root,
  1494. u64 num_bytes, u64 min_alloc_size,
  1495. u64 empty_size, u64 hint_byte,
  1496. u64 search_end, struct btrfs_key *ins,
  1497. u64 data);
  1498. int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1499. struct extent_buffer *orig_buf, struct extent_buffer *buf,
  1500. u32 *nr_extents);
  1501. int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1502. struct extent_buffer *buf, u32 nr_extents);
  1503. int btrfs_update_ref(struct btrfs_trans_handle *trans,
  1504. struct btrfs_root *root, struct extent_buffer *orig_buf,
  1505. struct extent_buffer *buf, int start_slot, int nr);
  1506. int btrfs_free_extent(struct btrfs_trans_handle *trans,
  1507. struct btrfs_root *root,
  1508. u64 bytenr, u64 num_bytes, u64 parent,
  1509. u64 root_objectid, u64 ref_generation,
  1510. u64 owner_objectid, int pin);
  1511. int btrfs_free_reserved_extent(struct btrfs_root *root, u64 start, u64 len);
  1512. int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
  1513. struct btrfs_root *root,
  1514. struct extent_io_tree *unpin);
  1515. int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
  1516. struct btrfs_root *root,
  1517. u64 bytenr, u64 num_bytes, u64 parent,
  1518. u64 root_objectid, u64 ref_generation,
  1519. u64 owner_objectid);
  1520. int btrfs_update_extent_ref(struct btrfs_trans_handle *trans,
  1521. struct btrfs_root *root, u64 bytenr,
  1522. u64 orig_parent, u64 parent,
  1523. u64 root_objectid, u64 ref_generation,
  1524. u64 owner_objectid);
  1525. int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
  1526. struct btrfs_root *root);
  1527. int btrfs_extent_readonly(struct btrfs_root *root, u64 bytenr);
  1528. int btrfs_free_block_groups(struct btrfs_fs_info *info);
  1529. int btrfs_read_block_groups(struct btrfs_root *root);
  1530. int btrfs_make_block_group(struct btrfs_trans_handle *trans,
  1531. struct btrfs_root *root, u64 bytes_used,
  1532. u64 type, u64 chunk_objectid, u64 chunk_offset,
  1533. u64 size);
  1534. int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
  1535. struct btrfs_root *root, u64 group_start);
  1536. int btrfs_relocate_block_group(struct btrfs_root *root, u64 group_start);
  1537. int btrfs_free_reloc_root(struct btrfs_trans_handle *trans,
  1538. struct btrfs_root *root);
  1539. int btrfs_drop_dead_reloc_roots(struct btrfs_root *root);
  1540. int btrfs_reloc_tree_cache_ref(struct btrfs_trans_handle *trans,
  1541. struct btrfs_root *root,
  1542. struct extent_buffer *buf, u64 orig_start);
  1543. int btrfs_add_dead_reloc_root(struct btrfs_root *root);
  1544. int btrfs_cleanup_reloc_trees(struct btrfs_root *root);
  1545. int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len);
  1546. u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags);
  1547. /* ctree.c */
  1548. int btrfs_previous_item(struct btrfs_root *root,
  1549. struct btrfs_path *path, u64 min_objectid,
  1550. int type);
  1551. int btrfs_merge_path(struct btrfs_trans_handle *trans,
  1552. struct btrfs_root *root,
  1553. struct btrfs_key *node_keys,
  1554. u64 *nodes, int lowest_level);
  1555. int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
  1556. struct btrfs_root *root, struct btrfs_path *path,
  1557. struct btrfs_key *new_key);
  1558. struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
  1559. struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
  1560. int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
  1561. struct btrfs_key *key, int lowest_level,
  1562. int cache_only, u64 min_trans);
  1563. int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
  1564. struct btrfs_key *max_key,
  1565. struct btrfs_path *path, int cache_only,
  1566. u64 min_trans);
  1567. int btrfs_cow_block(struct btrfs_trans_handle *trans,
  1568. struct btrfs_root *root, struct extent_buffer *buf,
  1569. struct extent_buffer *parent, int parent_slot,
  1570. struct extent_buffer **cow_ret, u64 prealloc_dest);
  1571. int btrfs_copy_root(struct btrfs_trans_handle *trans,
  1572. struct btrfs_root *root,
  1573. struct extent_buffer *buf,
  1574. struct extent_buffer **cow_ret, u64 new_root_objectid);
  1575. int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1576. *root, struct btrfs_path *path, u32 data_size);
  1577. int btrfs_truncate_item(struct btrfs_trans_handle *trans,
  1578. struct btrfs_root *root,
  1579. struct btrfs_path *path,
  1580. u32 new_size, int from_end);
  1581. int btrfs_split_item(struct btrfs_trans_handle *trans,
  1582. struct btrfs_root *root,
  1583. struct btrfs_path *path,
  1584. struct btrfs_key *new_key,
  1585. unsigned long split_offset);
  1586. int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
  1587. *root, struct btrfs_key *key, struct btrfs_path *p, int
  1588. ins_len, int cow);
  1589. int btrfs_realloc_node(struct btrfs_trans_handle *trans,
  1590. struct btrfs_root *root, struct extent_buffer *parent,
  1591. int start_slot, int cache_only, u64 *last_ret,
  1592. struct btrfs_key *progress);
  1593. void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
  1594. struct btrfs_path *btrfs_alloc_path(void);
  1595. void btrfs_free_path(struct btrfs_path *p);
  1596. void btrfs_init_path(struct btrfs_path *p);
  1597. int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1598. struct btrfs_path *path, int slot, int nr);
  1599. int btrfs_del_leaf(struct btrfs_trans_handle *trans,
  1600. struct btrfs_root *root,
  1601. struct btrfs_path *path, u64 bytenr);
  1602. static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
  1603. struct btrfs_root *root,
  1604. struct btrfs_path *path)
  1605. {
  1606. return btrfs_del_items(trans, root, path, path->slots[0], 1);
  1607. }
  1608. int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1609. *root, struct btrfs_key *key, void *data, u32 data_size);
  1610. int btrfs_insert_some_items(struct btrfs_trans_handle *trans,
  1611. struct btrfs_root *root,
  1612. struct btrfs_path *path,
  1613. struct btrfs_key *cpu_key, u32 *data_size,
  1614. int nr);
  1615. int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
  1616. struct btrfs_root *root,
  1617. struct btrfs_path *path,
  1618. struct btrfs_key *cpu_key, u32 *data_size, int nr);
  1619. static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
  1620. struct btrfs_root *root,
  1621. struct btrfs_path *path,
  1622. struct btrfs_key *key,
  1623. u32 data_size)
  1624. {
  1625. return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
  1626. }
  1627. int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
  1628. int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
  1629. int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
  1630. int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
  1631. *root);
  1632. int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
  1633. struct btrfs_root *root,
  1634. struct extent_buffer *node,
  1635. struct extent_buffer *parent);
  1636. /* root-item.c */
  1637. int btrfs_find_root_ref(struct btrfs_root *tree_root,
  1638. struct btrfs_path *path,
  1639. u64 root_id, u64 ref_id);
  1640. int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
  1641. struct btrfs_root *tree_root,
  1642. u64 root_id, u8 type, u64 ref_id,
  1643. u64 dirid, u64 sequence,
  1644. const char *name, int name_len);
  1645. int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1646. struct btrfs_key *key);
  1647. int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
  1648. *root, struct btrfs_key *key, struct btrfs_root_item
  1649. *item);
  1650. int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
  1651. *root, struct btrfs_key *key, struct btrfs_root_item
  1652. *item);
  1653. int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
  1654. btrfs_root_item *item, struct btrfs_key *key);
  1655. int btrfs_search_root(struct btrfs_root *root, u64 search_start,
  1656. u64 *found_objectid);
  1657. int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
  1658. struct btrfs_root *latest_root);
  1659. /* dir-item.c */
  1660. int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
  1661. struct btrfs_root *root, const char *name,
  1662. int name_len, u64 dir,
  1663. struct btrfs_key *location, u8 type, u64 index);
  1664. struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
  1665. struct btrfs_root *root,
  1666. struct btrfs_path *path, u64 dir,
  1667. const char *name, int name_len,
  1668. int mod);
  1669. struct btrfs_dir_item *
  1670. btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
  1671. struct btrfs_root *root,
  1672. struct btrfs_path *path, u64 dir,
  1673. u64 objectid, const char *name, int name_len,
  1674. int mod);
  1675. struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
  1676. struct btrfs_path *path,
  1677. const char *name, int name_len);
  1678. int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
  1679. struct btrfs_root *root,
  1680. struct btrfs_path *path,
  1681. struct btrfs_dir_item *di);
  1682. int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
  1683. struct btrfs_root *root, const char *name,
  1684. u16 name_len, const void *data, u16 data_len,
  1685. u64 dir);
  1686. struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
  1687. struct btrfs_root *root,
  1688. struct btrfs_path *path, u64 dir,
  1689. const char *name, u16 name_len,
  1690. int mod);
  1691. /* orphan.c */
  1692. int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
  1693. struct btrfs_root *root, u64 offset);
  1694. int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
  1695. struct btrfs_root *root, u64 offset);
  1696. /* inode-map.c */
  1697. int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
  1698. struct btrfs_root *fs_root,
  1699. u64 dirid, u64 *objectid);
  1700. int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
  1701. /* inode-item.c */
  1702. int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
  1703. struct btrfs_root *root,
  1704. const char *name, int name_len,
  1705. u64 inode_objectid, u64 ref_objectid, u64 index);
  1706. int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
  1707. struct btrfs_root *root,
  1708. const char *name, int name_len,
  1709. u64 inode_objectid, u64 ref_objectid, u64 *index);
  1710. int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
  1711. struct btrfs_root *root,
  1712. struct btrfs_path *path, u64 objectid);
  1713. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  1714. *root, struct btrfs_path *path,
  1715. struct btrfs_key *location, int mod);
  1716. /* file-item.c */
  1717. int btrfs_del_csums(struct btrfs_trans_handle *trans,
  1718. struct btrfs_root *root, u64 bytenr, u64 len);
  1719. int btrfs_lookup_bio_sums(struct btrfs_root *root, struct inode *inode,
  1720. struct bio *bio, u32 *dst);
  1721. int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
  1722. struct btrfs_root *root,
  1723. u64 objectid, u64 pos,
  1724. u64 disk_offset, u64 disk_num_bytes,
  1725. u64 num_bytes, u64 offset, u64 ram_bytes,
  1726. u8 compression, u8 encryption, u16 other_encoding);
  1727. int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
  1728. struct btrfs_root *root,
  1729. struct btrfs_path *path, u64 objectid,
  1730. u64 bytenr, int mod);
  1731. int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
  1732. struct btrfs_root *root,
  1733. struct btrfs_ordered_sum *sums);
  1734. int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,
  1735. struct bio *bio, u64 file_start, int contig);
  1736. int btrfs_csum_file_bytes(struct btrfs_root *root, struct inode *inode,
  1737. u64 start, unsigned long len);
  1738. struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
  1739. struct btrfs_root *root,
  1740. struct btrfs_path *path,
  1741. u64 bytenr, int cow);
  1742. int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
  1743. struct btrfs_root *root, struct btrfs_path *path,
  1744. u64 isize);
  1745. int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start,
  1746. u64 end, struct list_head *list);
  1747. /* inode.c */
  1748. /* RHEL and EL kernels have a patch that renames PG_checked to FsMisc */
  1749. #if defined(ClearPageFsMisc) && !defined(ClearPageChecked)
  1750. #define ClearPageChecked ClearPageFsMisc
  1751. #define SetPageChecked SetPageFsMisc
  1752. #define PageChecked PageFsMisc
  1753. #endif
  1754. struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry);
  1755. int btrfs_set_inode_index(struct inode *dir, u64 *index);
  1756. int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
  1757. struct btrfs_root *root,
  1758. struct inode *dir, struct inode *inode,
  1759. const char *name, int name_len);
  1760. int btrfs_add_link(struct btrfs_trans_handle *trans,
  1761. struct inode *parent_inode, struct inode *inode,
  1762. const char *name, int name_len, int add_backref, u64 index);
  1763. int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
  1764. struct btrfs_root *root,
  1765. struct inode *inode, u64 new_size,
  1766. u32 min_type);
  1767. int btrfs_start_delalloc_inodes(struct btrfs_root *root);
  1768. int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end);
  1769. int btrfs_writepages(struct address_space *mapping,
  1770. struct writeback_control *wbc);
  1771. int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
  1772. struct btrfs_root *new_root, struct dentry *dentry,
  1773. u64 new_dirid, u64 alloc_hint);
  1774. int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
  1775. size_t size, struct bio *bio, unsigned long bio_flags);
  1776. unsigned long btrfs_force_ra(struct address_space *mapping,
  1777. struct file_ra_state *ra, struct file *file,
  1778. pgoff_t offset, pgoff_t last_index);
  1779. int btrfs_check_free_space(struct btrfs_root *root, u64 num_required,
  1780. int for_del);
  1781. int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
  1782. int btrfs_readpage(struct file *file, struct page *page);
  1783. void btrfs_delete_inode(struct inode *inode);
  1784. void btrfs_put_inode(struct inode *inode);
  1785. void btrfs_read_locked_inode(struct inode *inode);
  1786. int btrfs_write_inode(struct inode *inode, int wait);
  1787. void btrfs_dirty_inode(struct inode *inode);
  1788. struct inode *btrfs_alloc_inode(struct super_block *sb);
  1789. void btrfs_destroy_inode(struct inode *inode);
  1790. int btrfs_init_cachep(void);
  1791. void btrfs_destroy_cachep(void);
  1792. long btrfs_ioctl_trans_end(struct file *file);
  1793. struct inode *btrfs_ilookup(struct super_block *s, u64 objectid,
  1794. struct btrfs_root *root, int wait);
  1795. struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
  1796. struct btrfs_root *root);
  1797. struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
  1798. struct btrfs_root *root, int *is_new);
  1799. int btrfs_commit_write(struct file *file, struct page *page,
  1800. unsigned from, unsigned to);
  1801. struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
  1802. size_t page_offset, u64 start, u64 end,
  1803. int create);
  1804. int btrfs_update_inode(struct btrfs_trans_handle *trans,
  1805. struct btrfs_root *root,
  1806. struct inode *inode);
  1807. int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode);
  1808. int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode);
  1809. void btrfs_orphan_cleanup(struct btrfs_root *root);
  1810. int btrfs_cont_expand(struct inode *inode, loff_t size);
  1811. /* ioctl.c */
  1812. long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  1813. /* file.c */
  1814. int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync);
  1815. int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
  1816. int skip_pinned);
  1817. int btrfs_check_file(struct btrfs_root *root, struct inode *inode);
  1818. extern struct file_operations btrfs_file_operations;
  1819. int btrfs_drop_extents(struct btrfs_trans_handle *trans,
  1820. struct btrfs_root *root, struct inode *inode,
  1821. u64 start, u64 end, u64 inline_limit, u64 *hint_block);
  1822. int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
  1823. struct btrfs_root *root,
  1824. struct inode *inode, u64 start, u64 end);
  1825. int btrfs_release_file(struct inode *inode, struct file *file);
  1826. /* tree-defrag.c */
  1827. int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
  1828. struct btrfs_root *root, int cache_only);
  1829. /* sysfs.c */
  1830. int btrfs_init_sysfs(void);
  1831. void btrfs_exit_sysfs(void);
  1832. int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
  1833. int btrfs_sysfs_add_root(struct btrfs_root *root);
  1834. void btrfs_sysfs_del_root(struct btrfs_root *root);
  1835. void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
  1836. /* xattr.c */
  1837. ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  1838. /* super.c */
  1839. u64 btrfs_parse_size(char *str);
  1840. int btrfs_parse_options(struct btrfs_root *root, char *options);
  1841. int btrfs_sync_fs(struct super_block *sb, int wait);
  1842. /* acl.c */
  1843. int btrfs_check_acl(struct inode *inode, int mask);
  1844. int btrfs_init_acl(struct inode *inode, struct inode *dir);
  1845. int btrfs_acl_chmod(struct inode *inode);
  1846. /* free-space-cache.c */
  1847. int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
  1848. u64 bytenr, u64 size);
  1849. int btrfs_add_free_space_lock(struct btrfs_block_group_cache *block_group,
  1850. u64 offset, u64 bytes);
  1851. int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
  1852. u64 bytenr, u64 size);
  1853. int btrfs_remove_free_space_lock(struct btrfs_block_group_cache *block_group,
  1854. u64 offset, u64 bytes);
  1855. void btrfs_remove_free_space_cache(struct btrfs_block_group_cache
  1856. *block_group);
  1857. struct btrfs_free_space *btrfs_find_free_space(struct btrfs_block_group_cache
  1858. *block_group, u64 offset,
  1859. u64 bytes);
  1860. void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
  1861. u64 bytes);
  1862. u64 btrfs_block_group_free_space(struct btrfs_block_group_cache *block_group);
  1863. #endif