ctree.h 68 KB

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