blob: f1800008be34d1b29b4116d39288268eff2d8250 [file] [log] [blame]
Chris Mason234b63a2007-03-13 10:46:10 -04001#ifndef __BTRFS__
2#define __BTRFS__
Chris Masoneb60cea2007-02-02 09:18:22 -05003
Chris Masone20d96d2007-03-22 12:13:20 -04004#include <linux/fs.h>
Chris Masond6025572007-03-30 14:27:56 -04005#include <linux/buffer_head.h>
Chris Masond6e4a422007-04-06 15:37:36 -04006#include <linux/kobject.h>
Chris Mason8ef97622007-03-26 10:15:30 -04007#include "bit-radix.h"
Chris Masone20d96d2007-03-22 12:13:20 -04008
Chris Masone089f052007-03-16 16:20:31 -04009struct btrfs_trans_handle;
Chris Mason79154b12007-03-22 15:59:16 -040010struct btrfs_transaction;
Chris Mason2c90e5d2007-04-02 10:50:19 -040011extern struct kmem_cache *btrfs_path_cachep;
Chris Masone089f052007-03-16 16:20:31 -040012
Chris Mason3768f362007-03-13 16:47:54 -040013#define BTRFS_MAGIC "_BtRfS_M"
Chris Masoneb60cea2007-02-02 09:18:22 -050014
Chris Mason6407bf62007-03-27 06:33:00 -040015#define BTRFS_ROOT_TREE_OBJECTID 1ULL
Chris Mason0bd93ba2007-04-11 13:57:44 -040016#define BTRFS_DEV_TREE_OBJECTID 2ULL
17#define BTRFS_EXTENT_TREE_OBJECTID 3ULL
18#define BTRFS_FS_TREE_OBJECTID 4ULL
19#define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL
20#define BTRFS_FIRST_FREE_OBJECTID 6ULL
Chris Mason3768f362007-03-13 16:47:54 -040021
Chris Masonfec577f2007-02-26 10:40:21 -050022/*
Chris Masone20d96d2007-03-22 12:13:20 -040023 * we can actually store much bigger names, but lets not confuse the rest
24 * of linux
25 */
26#define BTRFS_NAME_LEN 255
27
Chris Masonf254e522007-03-29 15:15:27 -040028/* 32 bytes in various csum fields */
29#define BTRFS_CSUM_SIZE 32
30
Chris Masone20d96d2007-03-22 12:13:20 -040031/*
Chris Masonfec577f2007-02-26 10:40:21 -050032 * the key defines the order in the tree, and so it also defines (optimal)
33 * block layout. objectid corresonds to the inode number. The flags
34 * tells us things about the object, and is a kind of stream selector.
35 * so for a given inode, keys with flags of 1 might refer to the inode
36 * data, flags of 2 may point to file data in the btree and flags == 3
37 * may point to extents.
38 *
39 * offset is the starting byte offset for this key in the stream.
Chris Masone2fa7222007-03-12 16:22:34 -040040 *
41 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
42 * in cpu native order. Otherwise they are identical and their sizes
43 * should be the same (ie both packed)
Chris Masonfec577f2007-02-26 10:40:21 -050044 */
Chris Masone2fa7222007-03-12 16:22:34 -040045struct btrfs_disk_key {
46 __le64 objectid;
Chris Masonf254e522007-03-29 15:15:27 -040047 __le32 flags;
Chris Mason70b2bef2007-04-17 15:39:32 -040048 __le64 offset;
Chris Masone2fa7222007-03-12 16:22:34 -040049} __attribute__ ((__packed__));
50
51struct btrfs_key {
Chris Masoneb60cea2007-02-02 09:18:22 -050052 u64 objectid;
Chris Masonf254e522007-03-29 15:15:27 -040053 u32 flags;
Chris Mason70b2bef2007-04-17 15:39:32 -040054 u64 offset;
Chris Masoneb60cea2007-02-02 09:18:22 -050055} __attribute__ ((__packed__));
56
Chris Masonfec577f2007-02-26 10:40:21 -050057/*
58 * every tree block (leaf or node) starts with this header.
59 */
Chris Masonbb492bb2007-03-12 12:29:44 -040060struct btrfs_header {
Chris Masonf254e522007-03-29 15:15:27 -040061 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason3768f362007-03-13 16:47:54 -040062 u8 fsid[16]; /* FS specific uuid */
Chris Masonbb492bb2007-03-12 12:29:44 -040063 __le64 blocknr; /* which block this node is supposed to live in */
Chris Mason7f5c1512007-03-23 15:56:19 -040064 __le64 generation;
Chris Masonbb492bb2007-03-12 12:29:44 -040065 __le16 nritems;
66 __le16 flags;
Chris Mason9a6f11e2007-03-27 09:06:38 -040067 u8 level;
Chris Masoneb60cea2007-02-02 09:18:22 -050068} __attribute__ ((__packed__));
69
Chris Mason234b63a2007-03-13 10:46:10 -040070#define BTRFS_MAX_LEVEL 8
Chris Mason123abc82007-03-14 14:14:43 -040071#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
72 sizeof(struct btrfs_header)) / \
73 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
74#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
75#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
Chris Mason236454df2007-04-19 13:37:44 -040076#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
77 sizeof(struct btrfs_item) - \
78 sizeof(struct btrfs_file_extent_item))
Chris Masoneb60cea2007-02-02 09:18:22 -050079
Chris Masone20d96d2007-03-22 12:13:20 -040080struct buffer_head;
Chris Masonfec577f2007-02-26 10:40:21 -050081/*
Chris Masonfec577f2007-02-26 10:40:21 -050082 * the super block basically lists the main trees of the FS
83 * it currently lacks any block count etc etc
84 */
Chris Mason234b63a2007-03-13 10:46:10 -040085struct btrfs_super_block {
Chris Masonf254e522007-03-29 15:15:27 -040086 u8 csum[BTRFS_CSUM_SIZE];
Chris Mason87cbda52007-03-28 19:44:27 -040087 /* the first 3 fields must match struct btrfs_header */
Chris Mason3768f362007-03-13 16:47:54 -040088 u8 fsid[16]; /* FS specific uuid */
89 __le64 blocknr; /* this block number */
Chris Mason3768f362007-03-13 16:47:54 -040090 __le64 magic;
Chris Mason123abc82007-03-14 14:14:43 -040091 __le32 blocksize;
Chris Mason3768f362007-03-13 16:47:54 -040092 __le64 generation;
93 __le64 root;
94 __le64 total_blocks;
95 __le64 blocks_used;
Chris Mason2e635a22007-03-21 11:12:56 -040096 __le64 root_dir_objectid;
Chris Masonb4100d62007-04-12 12:14:00 -040097 __le64 last_device_id;
Chris Mason0bd93ba2007-04-11 13:57:44 -040098 /* fields below here vary with the underlying disk */
99 __le64 device_block_start;
100 __le64 device_num_blocks;
101 __le64 device_root;
Chris Masonb4100d62007-04-12 12:14:00 -0400102 __le64 device_id;
Chris Masoncfaa7292007-02-21 17:04:57 -0500103} __attribute__ ((__packed__));
104
Chris Masonfec577f2007-02-26 10:40:21 -0500105/*
Chris Mason62e27492007-03-15 12:56:47 -0400106 * A leaf is full of items. offset and size tell us where to find
Chris Masonfec577f2007-02-26 10:40:21 -0500107 * the item in the leaf (relative to the start of the data area)
108 */
Chris Mason0783fcf2007-03-12 20:12:07 -0400109struct btrfs_item {
Chris Masone2fa7222007-03-12 16:22:34 -0400110 struct btrfs_disk_key key;
Chris Mason123abc82007-03-14 14:14:43 -0400111 __le32 offset;
Chris Mason0783fcf2007-03-12 20:12:07 -0400112 __le16 size;
Chris Masoneb60cea2007-02-02 09:18:22 -0500113} __attribute__ ((__packed__));
114
Chris Masonfec577f2007-02-26 10:40:21 -0500115/*
116 * leaves have an item area and a data area:
117 * [item0, item1....itemN] [free space] [dataN...data1, data0]
118 *
119 * The data is separate from the items to get the keys closer together
120 * during searches.
121 */
Chris Mason234b63a2007-03-13 10:46:10 -0400122struct btrfs_leaf {
Chris Masonbb492bb2007-03-12 12:29:44 -0400123 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400124 struct btrfs_item items[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500125} __attribute__ ((__packed__));
126
Chris Masonfec577f2007-02-26 10:40:21 -0500127/*
128 * all non-leaf blocks are nodes, they hold only keys and pointers to
129 * other blocks
130 */
Chris Mason123abc82007-03-14 14:14:43 -0400131struct btrfs_key_ptr {
132 struct btrfs_disk_key key;
133 __le64 blockptr;
134} __attribute__ ((__packed__));
135
Chris Mason234b63a2007-03-13 10:46:10 -0400136struct btrfs_node {
Chris Masonbb492bb2007-03-12 12:29:44 -0400137 struct btrfs_header header;
Chris Mason123abc82007-03-14 14:14:43 -0400138 struct btrfs_key_ptr ptrs[];
Chris Masoneb60cea2007-02-02 09:18:22 -0500139} __attribute__ ((__packed__));
140
Chris Masonfec577f2007-02-26 10:40:21 -0500141/*
Chris Mason234b63a2007-03-13 10:46:10 -0400142 * btrfs_paths remember the path taken from the root down to the leaf.
143 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
Chris Masonfec577f2007-02-26 10:40:21 -0500144 * to any other levels that are present.
145 *
146 * The slots array records the index of the item or block pointer
147 * used while walking the tree.
148 */
Chris Mason234b63a2007-03-13 10:46:10 -0400149struct btrfs_path {
Chris Masone20d96d2007-03-22 12:13:20 -0400150 struct buffer_head *nodes[BTRFS_MAX_LEVEL];
Chris Mason234b63a2007-03-13 10:46:10 -0400151 int slots[BTRFS_MAX_LEVEL];
Chris Masoneb60cea2007-02-02 09:18:22 -0500152};
Chris Mason5de08d72007-02-24 06:24:44 -0500153
Chris Mason62e27492007-03-15 12:56:47 -0400154/*
155 * items in the extent btree are used to record the objectid of the
156 * owner of the block and the number of references
157 */
158struct btrfs_extent_item {
159 __le32 refs;
Chris Mason62e27492007-03-15 12:56:47 -0400160} __attribute__ ((__packed__));
161
Chris Mason1e1d2702007-03-15 19:03:33 -0400162struct btrfs_inode_timespec {
Chris Masonf254e522007-03-29 15:15:27 -0400163 __le64 sec;
Chris Mason1e1d2702007-03-15 19:03:33 -0400164 __le32 nsec;
165} __attribute__ ((__packed__));
166
167/*
168 * there is no padding here on purpose. If you want to extent the inode,
169 * make a new item type
170 */
171struct btrfs_inode_item {
172 __le64 generation;
173 __le64 size;
174 __le64 nblocks;
175 __le32 nlink;
176 __le32 uid;
177 __le32 gid;
178 __le32 mode;
179 __le32 rdev;
180 __le16 flags;
181 __le16 compat_flags;
182 struct btrfs_inode_timespec atime;
183 struct btrfs_inode_timespec ctime;
184 struct btrfs_inode_timespec mtime;
185 struct btrfs_inode_timespec otime;
186} __attribute__ ((__packed__));
187
188/* inline data is just a blob of bytes */
189struct btrfs_inline_data_item {
190 u8 data;
191} __attribute__ ((__packed__));
192
Chris Mason62e27492007-03-15 12:56:47 -0400193struct btrfs_dir_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400194 struct btrfs_disk_key location;
Chris Mason62e27492007-03-15 12:56:47 -0400195 __le16 flags;
Chris Masona8a2ee02007-03-16 08:46:49 -0400196 __le16 name_len;
Chris Mason62e27492007-03-15 12:56:47 -0400197 u8 type;
198} __attribute__ ((__packed__));
199
200struct btrfs_root_item {
Chris Masond6e4a422007-04-06 15:37:36 -0400201 struct btrfs_inode_item inode;
202 __le64 root_dirid;
Chris Mason62e27492007-03-15 12:56:47 -0400203 __le64 blocknr;
204 __le32 flags;
205 __le64 block_limit;
206 __le64 blocks_used;
207 __le32 refs;
Chris Mason9f5fae22007-03-20 14:38:32 -0400208} __attribute__ ((__packed__));
209
Chris Mason236454df2007-04-19 13:37:44 -0400210#define BTRFS_FILE_EXTENT_REG 0
211#define BTRFS_FILE_EXTENT_INLINE 1
212
Chris Mason9f5fae22007-03-20 14:38:32 -0400213struct btrfs_file_extent_item {
Chris Mason71951f32007-03-27 09:16:29 -0400214 __le64 generation;
Chris Mason236454df2007-04-19 13:37:44 -0400215 u8 type;
Chris Mason9f5fae22007-03-20 14:38:32 -0400216 /*
217 * disk space consumed by the extent, checksum blocks are included
218 * in these numbers
219 */
220 __le64 disk_blocknr;
221 __le64 disk_num_blocks;
222 /*
Chris Masondee26a92007-03-26 16:00:06 -0400223 * the logical offset in file blocks (no csums)
Chris Mason9f5fae22007-03-20 14:38:32 -0400224 * this extent record is for. This allows a file extent to point
225 * into the middle of an existing extent on disk, sharing it
226 * between two snapshots (useful if some bytes in the middle of the
227 * extent have changed
228 */
229 __le64 offset;
230 /*
231 * the logical number of file blocks (no csums included)
232 */
233 __le64 num_blocks;
234} __attribute__ ((__packed__));
235
Chris Masonf254e522007-03-29 15:15:27 -0400236struct btrfs_csum_item {
237 u8 csum[BTRFS_CSUM_SIZE];
238} __attribute__ ((__packed__));
239
Chris Mason0bd93ba2007-04-11 13:57:44 -0400240struct btrfs_device_item {
241 __le16 pathlen;
Chris Masonb4100d62007-04-12 12:14:00 -0400242 __le64 device_id;
Chris Mason0bd93ba2007-04-11 13:57:44 -0400243} __attribute__ ((__packed__));
244
Chris Mason87cbda52007-03-28 19:44:27 -0400245struct crypto_hash;
Chris Mason9f5fae22007-03-20 14:38:32 -0400246struct btrfs_fs_info {
Chris Mason9f5fae22007-03-20 14:38:32 -0400247 struct btrfs_root *extent_root;
248 struct btrfs_root *tree_root;
Chris Mason0bd93ba2007-04-11 13:57:44 -0400249 struct btrfs_root *dev_root;
Chris Mason9f5fae22007-03-20 14:38:32 -0400250 struct btrfs_key current_insert;
251 struct btrfs_key last_insert;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400252 struct radix_tree_root fs_roots_radix;
Chris Mason8ef97622007-03-26 10:15:30 -0400253 struct radix_tree_root pending_del_radix;
Chris Mason9f5fae22007-03-20 14:38:32 -0400254 struct radix_tree_root pinned_radix;
Chris Mason7eccb902007-04-11 15:53:25 -0400255 struct radix_tree_root dev_radix;
Chris Mason293ffd52007-03-20 15:57:25 -0400256 u64 generation;
Chris Mason79154b12007-03-22 15:59:16 -0400257 struct btrfs_transaction *running_transaction;
Chris Mason1261ec42007-03-20 20:35:03 -0400258 struct btrfs_super_block *disk_super;
Chris Masone20d96d2007-03-22 12:13:20 -0400259 struct buffer_head *sb_buffer;
260 struct super_block *sb;
Chris Masond98237b2007-03-28 13:57:48 -0400261 struct inode *btree_inode;
Chris Mason79154b12007-03-22 15:59:16 -0400262 struct mutex trans_mutex;
Chris Masond561c022007-03-23 19:47:49 -0400263 struct mutex fs_mutex;
Chris Mason87cbda52007-03-28 19:44:27 -0400264 struct crypto_hash *hash_tfm;
265 spinlock_t hash_lock;
Chris Masond6e4a422007-04-06 15:37:36 -0400266 struct kobject kobj;
Chris Mason62e27492007-03-15 12:56:47 -0400267};
268
269/*
270 * in ram representation of the tree. extent_root is used for all allocations
271 * and for the extent tree extent_root root. current_insert is used
272 * only for the extent tree.
273 */
274struct btrfs_root {
Chris Masone20d96d2007-03-22 12:13:20 -0400275 struct buffer_head *node;
276 struct buffer_head *commit_root;
Chris Mason62e27492007-03-15 12:56:47 -0400277 struct btrfs_root_item root_item;
278 struct btrfs_key root_key;
Chris Mason9f5fae22007-03-20 14:38:32 -0400279 struct btrfs_fs_info *fs_info;
Chris Mason0f7d52f2007-04-09 10:42:37 -0400280 struct inode *inode;
281 u64 objectid;
282 u64 last_trans;
Chris Mason62e27492007-03-15 12:56:47 -0400283 u32 blocksize;
Chris Mason9f5fae22007-03-20 14:38:32 -0400284 int ref_cows;
285 u32 type;
Chris Mason1b05da22007-04-10 12:13:09 -0400286 u64 highest_inode;
287 u64 last_inode_alloc;
Chris Mason62e27492007-03-15 12:56:47 -0400288};
289
Chris Mason62e27492007-03-15 12:56:47 -0400290/* the lower bits in the key flags defines the item type */
291#define BTRFS_KEY_TYPE_MAX 256
Chris Masona429e512007-04-18 16:15:28 -0400292#define BTRFS_KEY_TYPE_SHIFT 24
293#define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
294 BTRFS_KEY_TYPE_SHIFT)
Chris Mason1e1d2702007-03-15 19:03:33 -0400295
Chris Mason7fcde0e2007-04-05 12:13:21 -0400296#define BTRFS_KEY_OVERFLOW_MAX 128
Chris Masona429e512007-04-18 16:15:28 -0400297#define BTRFS_KEY_OVERFLOW_MASK ((u32)BTRFS_KEY_OVERFLOW_MAX - 1)
Chris Mason7fcde0e2007-04-05 12:13:21 -0400298
Chris Mason1e1d2702007-03-15 19:03:33 -0400299/*
300 * inode items have the data typically returned from stat and store other
301 * info about object characteristics. There is one for every file and dir in
302 * the FS
303 */
Chris Mason62e27492007-03-15 12:56:47 -0400304#define BTRFS_INODE_ITEM_KEY 1
Chris Mason1e1d2702007-03-15 19:03:33 -0400305
306/*
307 * dir items are the name -> inode pointers in a directory. There is one
308 * for every name in a directory.
309 */
Chris Mason62e27492007-03-15 12:56:47 -0400310#define BTRFS_DIR_ITEM_KEY 2
Chris Masonbae45de2007-04-04 21:22:22 -0400311#define BTRFS_DIR_INDEX_KEY 3
Chris Mason1e1d2702007-03-15 19:03:33 -0400312/*
313 * inline data is file data that fits in the btree.
314 */
Chris Masonbae45de2007-04-04 21:22:22 -0400315#define BTRFS_INLINE_DATA_KEY 4
Chris Mason1e1d2702007-03-15 19:03:33 -0400316/*
317 * extent data is for data that can't fit in the btree. It points to
318 * a (hopefully) huge chunk of disk
319 */
Chris Masonbae45de2007-04-04 21:22:22 -0400320#define BTRFS_EXTENT_DATA_KEY 5
Chris Mason1e1d2702007-03-15 19:03:33 -0400321/*
Chris Masonf254e522007-03-29 15:15:27 -0400322 * csum items have the checksums for data in the extents
323 */
Chris Masonbae45de2007-04-04 21:22:22 -0400324#define BTRFS_CSUM_ITEM_KEY 6
Chris Masonf254e522007-03-29 15:15:27 -0400325
326/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400327 * root items point to tree roots. There are typically in the root
328 * tree used by the super block to find all the other trees
329 */
Chris Masonbae45de2007-04-04 21:22:22 -0400330#define BTRFS_ROOT_ITEM_KEY 7
Chris Mason1e1d2702007-03-15 19:03:33 -0400331/*
332 * extent items are in the extent map tree. These record which blocks
333 * are used, and how many references there are to each block
334 */
Chris Masonbae45de2007-04-04 21:22:22 -0400335#define BTRFS_EXTENT_ITEM_KEY 8
Chris Mason9f5fae22007-03-20 14:38:32 -0400336
337/*
Chris Mason0bd93ba2007-04-11 13:57:44 -0400338 * dev items list the devices that make up the FS
339 */
340#define BTRFS_DEV_ITEM_KEY 9
341
342/*
Chris Mason1e1d2702007-03-15 19:03:33 -0400343 * string items are for debugging. They just store a short string of
344 * data in the FS
345 */
Chris Mason0bd93ba2007-04-11 13:57:44 -0400346#define BTRFS_STRING_ITEM_KEY 10
Chris Mason1e1d2702007-03-15 19:03:33 -0400347
348static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
349{
350 return le64_to_cpu(i->generation);
351}
352
353static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
354 u64 val)
355{
356 i->generation = cpu_to_le64(val);
357}
358
359static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
360{
361 return le64_to_cpu(i->size);
362}
363
364static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
365{
366 i->size = cpu_to_le64(val);
367}
368
369static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
370{
371 return le64_to_cpu(i->nblocks);
372}
373
374static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
375{
376 i->nblocks = cpu_to_le64(val);
377}
378
379static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
380{
381 return le32_to_cpu(i->nlink);
382}
383
384static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
385{
386 i->nlink = cpu_to_le32(val);
387}
388
389static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
390{
391 return le32_to_cpu(i->uid);
392}
393
394static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
395{
396 i->uid = cpu_to_le32(val);
397}
398
399static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
400{
401 return le32_to_cpu(i->gid);
402}
403
404static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
405{
406 i->gid = cpu_to_le32(val);
407}
408
409static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
410{
411 return le32_to_cpu(i->mode);
412}
413
414static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
415{
416 i->mode = cpu_to_le32(val);
417}
418
419static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
420{
421 return le32_to_cpu(i->rdev);
422}
423
424static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
425{
426 i->rdev = cpu_to_le32(val);
427}
428
429static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
430{
431 return le16_to_cpu(i->flags);
432}
433
434static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
435{
436 i->flags = cpu_to_le16(val);
437}
438
439static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
440{
441 return le16_to_cpu(i->compat_flags);
442}
443
444static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
445 u16 val)
446{
447 i->compat_flags = cpu_to_le16(val);
448}
449
Chris Masonf254e522007-03-29 15:15:27 -0400450static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
Chris Masone20d96d2007-03-22 12:13:20 -0400451{
Chris Masonf254e522007-03-29 15:15:27 -0400452 return le64_to_cpu(ts->sec);
Chris Masone20d96d2007-03-22 12:13:20 -0400453}
454
455static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
Chris Masonf254e522007-03-29 15:15:27 -0400456 u64 val)
Chris Masone20d96d2007-03-22 12:13:20 -0400457{
Chris Masonf254e522007-03-29 15:15:27 -0400458 ts->sec = cpu_to_le64(val);
Chris Masone20d96d2007-03-22 12:13:20 -0400459}
460
461static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
462{
463 return le32_to_cpu(ts->nsec);
464}
465
466static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
467 u32 val)
468{
469 ts->nsec = cpu_to_le32(val);
470}
471
Chris Mason234b63a2007-03-13 10:46:10 -0400472static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
Chris Masoncf27e1e2007-03-13 09:49:06 -0400473{
474 return le32_to_cpu(ei->refs);
475}
476
Chris Mason234b63a2007-03-13 10:46:10 -0400477static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
Chris Masoncf27e1e2007-03-13 09:49:06 -0400478{
479 ei->refs = cpu_to_le32(val);
480}
481
Chris Mason234b63a2007-03-13 10:46:10 -0400482static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
Chris Mason1d4f8a02007-03-13 09:28:32 -0400483{
Chris Mason123abc82007-03-14 14:14:43 -0400484 return le64_to_cpu(n->ptrs[nr].blockptr);
Chris Mason1d4f8a02007-03-13 09:28:32 -0400485}
486
Chris Mason234b63a2007-03-13 10:46:10 -0400487static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
488 u64 val)
Chris Mason1d4f8a02007-03-13 09:28:32 -0400489{
Chris Mason123abc82007-03-14 14:14:43 -0400490 n->ptrs[nr].blockptr = cpu_to_le64(val);
Chris Mason1d4f8a02007-03-13 09:28:32 -0400491}
492
Chris Mason123abc82007-03-14 14:14:43 -0400493static inline u32 btrfs_item_offset(struct btrfs_item *item)
Chris Mason0783fcf2007-03-12 20:12:07 -0400494{
Chris Mason123abc82007-03-14 14:14:43 -0400495 return le32_to_cpu(item->offset);
Chris Mason0783fcf2007-03-12 20:12:07 -0400496}
497
Chris Mason123abc82007-03-14 14:14:43 -0400498static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
Chris Mason0783fcf2007-03-12 20:12:07 -0400499{
Chris Mason123abc82007-03-14 14:14:43 -0400500 item->offset = cpu_to_le32(val);
Chris Mason0783fcf2007-03-12 20:12:07 -0400501}
502
Chris Mason123abc82007-03-14 14:14:43 -0400503static inline u32 btrfs_item_end(struct btrfs_item *item)
Chris Mason0783fcf2007-03-12 20:12:07 -0400504{
Chris Mason123abc82007-03-14 14:14:43 -0400505 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
Chris Mason0783fcf2007-03-12 20:12:07 -0400506}
507
508static inline u16 btrfs_item_size(struct btrfs_item *item)
509{
510 return le16_to_cpu(item->size);
511}
512
513static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
514{
515 item->size = cpu_to_le16(val);
516}
517
Chris Mason1d4f6402007-03-15 15:18:43 -0400518static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
519{
520 return le16_to_cpu(d->flags);
521}
522
523static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
524{
525 d->flags = cpu_to_le16(val);
526}
527
528static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
529{
530 return d->type;
531}
532
533static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
534{
535 d->type = val;
536}
537
Chris Masona8a2ee02007-03-16 08:46:49 -0400538static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
Chris Mason1d4f6402007-03-15 15:18:43 -0400539{
Chris Masona8a2ee02007-03-16 08:46:49 -0400540 return le16_to_cpu(d->name_len);
541}
542
543static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
544{
545 d->name_len = cpu_to_le16(val);
Chris Mason1d4f6402007-03-15 15:18:43 -0400546}
547
Chris Masone2fa7222007-03-12 16:22:34 -0400548static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
549 struct btrfs_disk_key *disk)
550{
551 cpu->offset = le64_to_cpu(disk->offset);
552 cpu->flags = le32_to_cpu(disk->flags);
553 cpu->objectid = le64_to_cpu(disk->objectid);
554}
555
556static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
557 struct btrfs_key *cpu)
558{
559 disk->offset = cpu_to_le64(cpu->offset);
560 disk->flags = cpu_to_le32(cpu->flags);
561 disk->objectid = cpu_to_le64(cpu->objectid);
562}
563
Chris Mason62e27492007-03-15 12:56:47 -0400564static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
Chris Masone2fa7222007-03-12 16:22:34 -0400565{
566 return le64_to_cpu(disk->objectid);
567}
568
Chris Mason62e27492007-03-15 12:56:47 -0400569static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
570 u64 val)
Chris Masone2fa7222007-03-12 16:22:34 -0400571{
572 disk->objectid = cpu_to_le64(val);
573}
574
Chris Mason62e27492007-03-15 12:56:47 -0400575static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
Chris Masone2fa7222007-03-12 16:22:34 -0400576{
577 return le64_to_cpu(disk->offset);
578}
579
Chris Mason62e27492007-03-15 12:56:47 -0400580static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
581 u64 val)
Chris Masone2fa7222007-03-12 16:22:34 -0400582{
583 disk->offset = cpu_to_le64(val);
584}
585
Chris Mason62e27492007-03-15 12:56:47 -0400586static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
Chris Masone2fa7222007-03-12 16:22:34 -0400587{
588 return le32_to_cpu(disk->flags);
589}
590
Chris Mason62e27492007-03-15 12:56:47 -0400591static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
592 u32 val)
Chris Masone2fa7222007-03-12 16:22:34 -0400593{
594 disk->flags = cpu_to_le32(val);
595}
596
Chris Masona429e512007-04-18 16:15:28 -0400597static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
598{
599 return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
600}
601
602static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
603 u32 val)
604{
605 u32 flags = btrfs_disk_key_flags(key);
606 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
607 val = val << BTRFS_KEY_TYPE_SHIFT;
608 flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
609 btrfs_set_disk_key_flags(key, flags);
610}
611
612static inline u32 btrfs_key_type(struct btrfs_key *key)
613{
614 return key->flags >> BTRFS_KEY_TYPE_SHIFT;
615}
616
617static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
618{
619 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
620 val = val << BTRFS_KEY_TYPE_SHIFT;
621 key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
622}
623
Chris Mason7fcde0e2007-04-05 12:13:21 -0400624static inline u32 btrfs_key_overflow(struct btrfs_key *key)
625{
Chris Masona429e512007-04-18 16:15:28 -0400626 return key->flags & BTRFS_KEY_OVERFLOW_MASK;
Chris Mason7fcde0e2007-04-05 12:13:21 -0400627}
628
629static inline void btrfs_set_key_overflow(struct btrfs_key *key, u32 over)
630{
Chris Mason0f7d52f2007-04-09 10:42:37 -0400631 BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
Chris Masona429e512007-04-18 16:15:28 -0400632 key->flags = (key->flags & ~BTRFS_KEY_OVERFLOW_MASK) | over;
Chris Mason62e27492007-03-15 12:56:47 -0400633}
634
Chris Mason7fcde0e2007-04-05 12:13:21 -0400635static inline u32 btrfs_disk_key_overflow(struct btrfs_disk_key *key)
636{
Chris Masona429e512007-04-18 16:15:28 -0400637 return le32_to_cpu(key->flags) & BTRFS_KEY_OVERFLOW_MASK;
Chris Mason7fcde0e2007-04-05 12:13:21 -0400638}
639
Chris Masona429e512007-04-18 16:15:28 -0400640static inline void btrfs_set_disk_key_overflow(struct btrfs_disk_key *key,
Chris Mason7fcde0e2007-04-05 12:13:21 -0400641 u32 over)
642{
643 u32 flags = btrfs_disk_key_flags(key);
Chris Mason0f7d52f2007-04-09 10:42:37 -0400644 BUG_ON(over >= BTRFS_KEY_OVERFLOW_MAX);
Chris Masona429e512007-04-18 16:15:28 -0400645 flags = (flags & ~BTRFS_KEY_OVERFLOW_MASK) | over;
Chris Mason7fcde0e2007-04-05 12:13:21 -0400646 btrfs_set_disk_key_flags(key, flags);
647}
648
Chris Masonbb492bb2007-03-12 12:29:44 -0400649static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
Chris Mason7518a232007-03-12 12:01:18 -0400650{
Chris Masonbb492bb2007-03-12 12:29:44 -0400651 return le64_to_cpu(h->blocknr);
Chris Mason7518a232007-03-12 12:01:18 -0400652}
653
Chris Masonbb492bb2007-03-12 12:29:44 -0400654static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
Chris Mason7518a232007-03-12 12:01:18 -0400655{
Chris Masonbb492bb2007-03-12 12:29:44 -0400656 h->blocknr = cpu_to_le64(blocknr);
Chris Mason7518a232007-03-12 12:01:18 -0400657}
658
Chris Mason7f5c1512007-03-23 15:56:19 -0400659static inline u64 btrfs_header_generation(struct btrfs_header *h)
660{
661 return le64_to_cpu(h->generation);
662}
663
664static inline void btrfs_set_header_generation(struct btrfs_header *h,
665 u64 val)
666{
667 h->generation = cpu_to_le64(val);
668}
669
Chris Masonbb492bb2007-03-12 12:29:44 -0400670static inline u16 btrfs_header_nritems(struct btrfs_header *h)
Chris Mason7518a232007-03-12 12:01:18 -0400671{
Chris Masonbb492bb2007-03-12 12:29:44 -0400672 return le16_to_cpu(h->nritems);
Chris Mason7518a232007-03-12 12:01:18 -0400673}
674
Chris Masonbb492bb2007-03-12 12:29:44 -0400675static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
Chris Mason7518a232007-03-12 12:01:18 -0400676{
Chris Masonbb492bb2007-03-12 12:29:44 -0400677 h->nritems = cpu_to_le16(val);
Chris Mason7518a232007-03-12 12:01:18 -0400678}
679
Chris Masonbb492bb2007-03-12 12:29:44 -0400680static inline u16 btrfs_header_flags(struct btrfs_header *h)
Chris Mason7518a232007-03-12 12:01:18 -0400681{
Chris Masonbb492bb2007-03-12 12:29:44 -0400682 return le16_to_cpu(h->flags);
Chris Mason7518a232007-03-12 12:01:18 -0400683}
684
Chris Masonbb492bb2007-03-12 12:29:44 -0400685static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
Chris Mason7518a232007-03-12 12:01:18 -0400686{
Chris Masonbb492bb2007-03-12 12:29:44 -0400687 h->flags = cpu_to_le16(val);
Chris Mason7518a232007-03-12 12:01:18 -0400688}
689
Chris Masonbb492bb2007-03-12 12:29:44 -0400690static inline int btrfs_header_level(struct btrfs_header *h)
Chris Mason7518a232007-03-12 12:01:18 -0400691{
Chris Mason9a6f11e2007-03-27 09:06:38 -0400692 return h->level;
Chris Mason7518a232007-03-12 12:01:18 -0400693}
694
Chris Masonbb492bb2007-03-12 12:29:44 -0400695static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
Chris Mason7518a232007-03-12 12:01:18 -0400696{
Chris Mason234b63a2007-03-13 10:46:10 -0400697 BUG_ON(level > BTRFS_MAX_LEVEL);
Chris Mason9a6f11e2007-03-27 09:06:38 -0400698 h->level = level;
Chris Mason7518a232007-03-12 12:01:18 -0400699}
700
Chris Mason234b63a2007-03-13 10:46:10 -0400701static inline int btrfs_is_leaf(struct btrfs_node *n)
Chris Mason7518a232007-03-12 12:01:18 -0400702{
703 return (btrfs_header_level(&n->header) == 0);
704}
705
Chris Mason3768f362007-03-13 16:47:54 -0400706static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
707{
708 return le64_to_cpu(item->blocknr);
709}
710
711static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
712{
713 item->blocknr = cpu_to_le64(val);
714}
715
Chris Masond6e4a422007-04-06 15:37:36 -0400716static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
717{
718 return le64_to_cpu(item->root_dirid);
719}
720
721static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
722{
723 item->root_dirid = cpu_to_le64(val);
724}
725
Chris Mason3768f362007-03-13 16:47:54 -0400726static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
727{
728 return le32_to_cpu(item->refs);
729}
730
731static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
732{
733 item->refs = cpu_to_le32(val);
734}
735
736static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
737{
738 return le64_to_cpu(s->blocknr);
739}
740
741static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
742{
743 s->blocknr = cpu_to_le64(val);
744}
745
Chris Mason0f7d52f2007-04-09 10:42:37 -0400746static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
747{
748 return le64_to_cpu(s->generation);
749}
750
751static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
752 u64 val)
753{
754 s->generation = cpu_to_le64(val);
755}
756
Chris Mason3768f362007-03-13 16:47:54 -0400757static inline u64 btrfs_super_root(struct btrfs_super_block *s)
758{
759 return le64_to_cpu(s->root);
760}
761
762static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
763{
764 s->root = cpu_to_le64(val);
765}
766
767static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
768{
769 return le64_to_cpu(s->total_blocks);
770}
771
772static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
773 u64 val)
774{
775 s->total_blocks = cpu_to_le64(val);
776}
777
778static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
779{
780 return le64_to_cpu(s->blocks_used);
781}
782
783static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
784 u64 val)
785{
786 s->blocks_used = cpu_to_le64(val);
787}
788
Chris Mason123abc82007-03-14 14:14:43 -0400789static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
Chris Mason3768f362007-03-13 16:47:54 -0400790{
Chris Mason123abc82007-03-14 14:14:43 -0400791 return le32_to_cpu(s->blocksize);
Chris Mason3768f362007-03-13 16:47:54 -0400792}
793
794static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
Chris Mason123abc82007-03-14 14:14:43 -0400795 u32 val)
Chris Mason3768f362007-03-13 16:47:54 -0400796{
Chris Mason123abc82007-03-14 14:14:43 -0400797 s->blocksize = cpu_to_le32(val);
798}
799
Chris Mason2e635a22007-03-21 11:12:56 -0400800static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
801{
802 return le64_to_cpu(s->root_dir_objectid);
803}
804
805static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
806 val)
807{
808 s->root_dir_objectid = cpu_to_le64(val);
809}
810
Chris Masonb4100d62007-04-12 12:14:00 -0400811static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
812{
813 return le64_to_cpu(s->last_device_id);
814}
815
816static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
817 u64 val)
818{
819 s->last_device_id = cpu_to_le64(val);
820}
821
822static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
823{
824 return le64_to_cpu(s->device_id);
825}
826
827static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
828 u64 val)
829{
830 s->device_id = cpu_to_le64(val);
831}
832
Chris Mason0bd93ba2007-04-11 13:57:44 -0400833static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
834{
835 return le64_to_cpu(s->device_block_start);
836}
837
838static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
839 *s, u64 val)
840{
841 s->device_block_start = cpu_to_le64(val);
842}
843
844static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
845{
846 return le64_to_cpu(s->device_num_blocks);
847}
848
849static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
850 *s, u64 val)
851{
852 s->device_num_blocks = cpu_to_le64(val);
853}
854
855static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
856{
857 return le64_to_cpu(s->device_root);
858}
859
860static inline void btrfs_set_super_device_root(struct btrfs_super_block
861 *s, u64 val)
862{
863 s->device_root = cpu_to_le64(val);
864}
865
866
Chris Mason123abc82007-03-14 14:14:43 -0400867static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
868{
869 return (u8 *)l->items;
Chris Mason3768f362007-03-13 16:47:54 -0400870}
Chris Mason9f5fae22007-03-20 14:38:32 -0400871
Chris Mason236454df2007-04-19 13:37:44 -0400872static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
873{
874 return e->type;
875}
876static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
877 u8 val)
878{
879 e->type = val;
880}
881
882static inline char *btrfs_file_extent_inline_start(struct
883 btrfs_file_extent_item *e)
884{
885 return (char *)(&e->disk_blocknr);
886}
887
888static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
889{
890 return (unsigned long)(&((struct
891 btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
892}
893
894static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
895{
896 struct btrfs_file_extent_item *fe = NULL;
897 return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
898}
899
Chris Mason9f5fae22007-03-20 14:38:32 -0400900static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
901 *e)
902{
903 return le64_to_cpu(e->disk_blocknr);
904}
905
906static inline void btrfs_set_file_extent_disk_blocknr(struct
907 btrfs_file_extent_item
908 *e, u64 val)
909{
910 e->disk_blocknr = cpu_to_le64(val);
911}
912
Chris Mason71951f32007-03-27 09:16:29 -0400913static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
914{
915 return le64_to_cpu(e->generation);
916}
917
918static inline void btrfs_set_file_extent_generation(struct
919 btrfs_file_extent_item *e,
920 u64 val)
921{
922 e->generation = cpu_to_le64(val);
923}
924
Chris Mason9f5fae22007-03-20 14:38:32 -0400925static inline u64 btrfs_file_extent_disk_num_blocks(struct
926 btrfs_file_extent_item *e)
927{
928 return le64_to_cpu(e->disk_num_blocks);
929}
930
931static inline void btrfs_set_file_extent_disk_num_blocks(struct
932 btrfs_file_extent_item
933 *e, u64 val)
934{
935 e->disk_num_blocks = cpu_to_le64(val);
936}
937
938static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
939{
940 return le64_to_cpu(e->offset);
941}
942
943static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
944 *e, u64 val)
945{
946 e->offset = cpu_to_le64(val);
947}
948
949static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
950 *e)
951{
952 return le64_to_cpu(e->num_blocks);
953}
954
955static inline void btrfs_set_file_extent_num_blocks(struct
956 btrfs_file_extent_item *e,
957 u64 val)
958{
959 e->num_blocks = cpu_to_le64(val);
960}
961
Chris Mason0bd93ba2007-04-11 13:57:44 -0400962static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
963{
964 return le16_to_cpu(d->pathlen);
965}
966
967static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
968 u16 val)
969{
970 d->pathlen = cpu_to_le16(val);
971}
972
Chris Masonb4100d62007-04-12 12:14:00 -0400973static inline u64 btrfs_device_id(struct btrfs_device_item *d)
974{
975 return le64_to_cpu(d->device_id);
976}
977
978static inline void btrfs_set_device_id(struct btrfs_device_item *d,
979 u64 val)
980{
981 d->device_id = cpu_to_le64(val);
982}
983
Chris Masone20d96d2007-03-22 12:13:20 -0400984static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
985{
986 return sb->s_fs_info;
987}
988
Chris Masond6025572007-03-30 14:27:56 -0400989static inline void btrfs_check_bounds(void *vptr, size_t len,
990 void *vcontainer, size_t container_len)
991{
992 char *ptr = vptr;
993 char *container = vcontainer;
994 WARN_ON(ptr < container);
995 WARN_ON(ptr + len > container + container_len);
996}
997
998static inline void btrfs_memcpy(struct btrfs_root *root,
999 void *dst_block,
1000 void *dst, const void *src, size_t nr)
1001{
1002 btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize);
1003 memcpy(dst, src, nr);
1004}
1005
1006static inline void btrfs_memmove(struct btrfs_root *root,
1007 void *dst_block,
1008 void *dst, void *src, size_t nr)
1009{
1010 btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize);
1011 memmove(dst, src, nr);
1012}
1013
1014static inline void btrfs_mark_buffer_dirty(struct buffer_head *bh)
1015{
1016 WARN_ON(!atomic_read(&bh->b_count));
1017 mark_buffer_dirty(bh);
1018}
1019
Chris Mason4beb1b82007-03-14 10:31:29 -04001020/* helper function to cast into the data area of the leaf. */
1021#define btrfs_item_ptr(leaf, slot, type) \
Chris Mason123abc82007-03-14 14:14:43 -04001022 ((type *)(btrfs_leaf_data(leaf) + \
1023 btrfs_item_offset((leaf)->items + (slot))))
Chris Mason4beb1b82007-03-14 10:31:29 -04001024
Chris Masonb18c6682007-04-17 13:26:50 -04001025/* extent-tree.c */
Chris Masonc5739bb2007-04-10 09:27:04 -04001026int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1027 struct btrfs_root *root);
Chris Masone20d96d2007-03-22 12:13:20 -04001028struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
Chris Masone089f052007-03-16 16:20:31 -04001029 struct btrfs_root *root);
Chris Masondee26a92007-03-26 16:00:06 -04001030int btrfs_alloc_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1031 *root, u64 num_blocks, u64 search_start, u64
Chris Masond0dbc6242007-04-10 12:36:36 -04001032 search_end, struct btrfs_key *ins);
Chris Masone089f052007-03-16 16:20:31 -04001033int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Chris Masone20d96d2007-03-22 12:13:20 -04001034 struct buffer_head *buf);
Chris Masone089f052007-03-16 16:20:31 -04001035int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1036 *root, u64 blocknr, u64 num_blocks, int pin);
Chris Masondee26a92007-03-26 16:00:06 -04001037int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1038 btrfs_root *root);
Chris Masonb18c6682007-04-17 13:26:50 -04001039int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1040 struct btrfs_root *root,
1041 u64 blocknr, u64 num_blocks);
Chris Masondee26a92007-03-26 16:00:06 -04001042/* ctree.c */
Chris Mason6567e832007-04-16 09:22:45 -04001043int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1044 *root, struct btrfs_path *path, u32 data_size);
Chris Masonb18c6682007-04-17 13:26:50 -04001045int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1046 struct btrfs_root *root,
1047 struct btrfs_path *path,
1048 u32 new_size);
Chris Masone089f052007-03-16 16:20:31 -04001049int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1050 *root, struct btrfs_key *key, struct btrfs_path *p, int
1051 ins_len, int cow);
Chris Mason234b63a2007-03-13 10:46:10 -04001052void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
Chris Mason2c90e5d2007-04-02 10:50:19 -04001053struct btrfs_path *btrfs_alloc_path(void);
1054void btrfs_free_path(struct btrfs_path *p);
Chris Mason234b63a2007-03-13 10:46:10 -04001055void btrfs_init_path(struct btrfs_path *p);
Chris Masone089f052007-03-16 16:20:31 -04001056int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1057 struct btrfs_path *path);
1058int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1059 *root, struct btrfs_key *key, void *data, u32 data_size);
1060int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1061 *root, struct btrfs_path *path, struct btrfs_key
1062 *cpu_key, u32 data_size);
Chris Mason234b63a2007-03-13 10:46:10 -04001063int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
Chris Mason123abc82007-03-14 14:14:43 -04001064int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
Chris Masone089f052007-03-16 16:20:31 -04001065int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masone20d96d2007-03-22 12:13:20 -04001066 *root, struct buffer_head *snap);
Chris Masondee26a92007-03-26 16:00:06 -04001067/* root-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001068int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1069 struct btrfs_key *key);
1070int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1071 *root, struct btrfs_key *key, struct btrfs_root_item
1072 *item);
1073int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1074 *root, struct btrfs_key *key, struct btrfs_root_item
1075 *item);
1076int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1077 btrfs_root_item *item, struct btrfs_key *key);
Chris Masondee26a92007-03-26 16:00:06 -04001078/* dir-item.c */
Chris Masone089f052007-03-16 16:20:31 -04001079int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001080 *root, const char *name, int name_len, u64 dir,
1081 struct btrfs_key *location, u8 type);
Chris Masone089f052007-03-16 16:20:31 -04001082int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masone20d96d2007-03-22 12:13:20 -04001083 *root, struct btrfs_path *path, u64 dir,
1084 const char *name, int name_len, int mod);
Chris Mason5f26f772007-04-05 10:38:44 -04001085int btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1086 struct btrfs_root *root,
1087 struct btrfs_path *path, u64 dir,
1088 u64 objectid, int mod);
Chris Mason1d4f6402007-03-15 15:18:43 -04001089int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
Chris Mason7f5c1512007-03-23 15:56:19 -04001090 const char *name, int name_len);
Chris Masondee26a92007-03-26 16:00:06 -04001091/* inode-map.c */
Chris Mason9f5fae22007-03-20 14:38:32 -04001092int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1093 struct btrfs_root *fs_root,
1094 u64 dirid, u64 *objectid);
Chris Mason5be6f7f2007-04-05 13:35:25 -04001095int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1096
Chris Masondee26a92007-03-26 16:00:06 -04001097/* inode-item.c */
Chris Mason293ffd52007-03-20 15:57:25 -04001098int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1099 *root, u64 objectid, struct btrfs_inode_item
1100 *inode_item);
1101int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Masond6e4a422007-04-06 15:37:36 -04001102 *root, struct btrfs_path *path,
1103 struct btrfs_key *location, int mod);
Chris Masondee26a92007-03-26 16:00:06 -04001104
1105/* file-item.c */
Chris Masonb18c6682007-04-17 13:26:50 -04001106int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
Chris Masondee26a92007-03-26 16:00:06 -04001107 struct btrfs_root *root,
Chris Masonb18c6682007-04-17 13:26:50 -04001108 u64 objectid, u64 pos, u64 offset,
1109 u64 num_blocks);
Chris Masondee26a92007-03-26 16:00:06 -04001110int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1111 struct btrfs_root *root,
1112 struct btrfs_path *path, u64 objectid,
Chris Mason9773a782007-03-27 11:26:26 -04001113 u64 blocknr, int mod);
Chris Masonf254e522007-03-29 15:15:27 -04001114int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1115 struct btrfs_root *root,
1116 u64 objectid, u64 offset,
1117 char *data, size_t len);
1118int btrfs_csum_verify_file_block(struct btrfs_root *root,
1119 u64 objectid, u64 offset,
1120 char *data, size_t len);
Chris Masonb18c6682007-04-17 13:26:50 -04001121struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1122 struct btrfs_root *root,
1123 struct btrfs_path *path,
1124 u64 objectid, u64 offset,
1125 int cow);
Chris Masond6e4a422007-04-06 15:37:36 -04001126/* super.c */
1127extern struct subsystem btrfs_subsys;
1128
Chris Masoneb60cea2007-02-02 09:18:22 -05001129#endif