ctree.h 70 KB

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