ctree.h 52 KB

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