ctree.h 66 KB

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