Btrfs: initial move to kernel module land
[linux-2.6-block.git] / fs / btrfs / ctree.h
CommitLineData
234b63a0
CM
1#ifndef __BTRFS__
2#define __BTRFS__
eb60ceac 3
e089f05c
CM
4struct btrfs_trans_handle;
5
3768f368 6#define BTRFS_MAGIC "_BtRfS_M"
eb60ceac 7
3768f368
CM
8#define BTRFS_ROOT_TREE_OBJECTID 1
9#define BTRFS_EXTENT_TREE_OBJECTID 2
9f5fae2f
CM
10#define BTRFS_INODE_MAP_OBJECTID 3
11#define BTRFS_FS_TREE_OBJECTID 4
3768f368 12
fec577fb
CM
13/*
14 * the key defines the order in the tree, and so it also defines (optimal)
15 * block layout. objectid corresonds to the inode number. The flags
16 * tells us things about the object, and is a kind of stream selector.
17 * so for a given inode, keys with flags of 1 might refer to the inode
18 * data, flags of 2 may point to file data in the btree and flags == 3
19 * may point to extents.
20 *
21 * offset is the starting byte offset for this key in the stream.
e2fa7227
CM
22 *
23 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
24 * in cpu native order. Otherwise they are identical and their sizes
25 * should be the same (ie both packed)
fec577fb 26 */
e2fa7227
CM
27struct btrfs_disk_key {
28 __le64 objectid;
a1516c89 29 __le32 flags;
a8a2ee0c 30 __le64 offset;
e2fa7227
CM
31} __attribute__ ((__packed__));
32
33struct btrfs_key {
eb60ceac 34 u64 objectid;
a1516c89 35 u32 flags;
a8a2ee0c 36 u64 offset;
eb60ceac
CM
37} __attribute__ ((__packed__));
38
fec577fb
CM
39/*
40 * every tree block (leaf or node) starts with this header.
41 */
bb492bb0 42struct btrfs_header {
3768f368 43 u8 fsid[16]; /* FS specific uuid */
bb492bb0
CM
44 __le64 blocknr; /* which block this node is supposed to live in */
45 __le64 parentid; /* objectid of the tree root */
46 __le32 csum;
47 __le32 ham;
48 __le16 nritems;
49 __le16 flags;
fec577fb 50 /* generation flags to be added */
eb60ceac
CM
51} __attribute__ ((__packed__));
52
234b63a0 53#define BTRFS_MAX_LEVEL 8
123abc88
CM
54#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
55 sizeof(struct btrfs_header)) / \
56 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
57#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
58#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
eb60ceac 59
234b63a0 60struct btrfs_buffer;
fec577fb
CM
61/*
62 * the super block basically lists the main trees of the FS
63 * it currently lacks any block count etc etc
64 */
234b63a0 65struct btrfs_super_block {
3768f368
CM
66 u8 fsid[16]; /* FS specific uuid */
67 __le64 blocknr; /* this block number */
68 __le32 csum;
69 __le64 magic;
123abc88 70 __le32 blocksize;
3768f368
CM
71 __le64 generation;
72 __le64 root;
73 __le64 total_blocks;
74 __le64 blocks_used;
2e635a27 75 __le64 root_dir_objectid;
cfaa7295
CM
76} __attribute__ ((__packed__));
77
fec577fb 78/*
62e2749e 79 * A leaf is full of items. offset and size tell us where to find
fec577fb
CM
80 * the item in the leaf (relative to the start of the data area)
81 */
0783fcfc 82struct btrfs_item {
e2fa7227 83 struct btrfs_disk_key key;
123abc88 84 __le32 offset;
0783fcfc 85 __le16 size;
eb60ceac
CM
86} __attribute__ ((__packed__));
87
fec577fb
CM
88/*
89 * leaves have an item area and a data area:
90 * [item0, item1....itemN] [free space] [dataN...data1, data0]
91 *
92 * The data is separate from the items to get the keys closer together
93 * during searches.
94 */
234b63a0 95struct btrfs_leaf {
bb492bb0 96 struct btrfs_header header;
123abc88 97 struct btrfs_item items[];
eb60ceac
CM
98} __attribute__ ((__packed__));
99
fec577fb
CM
100/*
101 * all non-leaf blocks are nodes, they hold only keys and pointers to
102 * other blocks
103 */
123abc88
CM
104struct btrfs_key_ptr {
105 struct btrfs_disk_key key;
106 __le64 blockptr;
107} __attribute__ ((__packed__));
108
234b63a0 109struct btrfs_node {
bb492bb0 110 struct btrfs_header header;
123abc88 111 struct btrfs_key_ptr ptrs[];
eb60ceac
CM
112} __attribute__ ((__packed__));
113
fec577fb 114/*
234b63a0
CM
115 * btrfs_paths remember the path taken from the root down to the leaf.
116 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
fec577fb
CM
117 * to any other levels that are present.
118 *
119 * The slots array records the index of the item or block pointer
120 * used while walking the tree.
121 */
234b63a0
CM
122struct btrfs_path {
123 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
124 int slots[BTRFS_MAX_LEVEL];
eb60ceac 125};
5de08d7d 126
62e2749e
CM
127/*
128 * items in the extent btree are used to record the objectid of the
129 * owner of the block and the number of references
130 */
131struct btrfs_extent_item {
132 __le32 refs;
133 __le64 owner;
134} __attribute__ ((__packed__));
135
1e1d2701
CM
136struct btrfs_inode_timespec {
137 __le32 sec;
138 __le32 nsec;
139} __attribute__ ((__packed__));
140
141/*
142 * there is no padding here on purpose. If you want to extent the inode,
143 * make a new item type
144 */
145struct btrfs_inode_item {
146 __le64 generation;
147 __le64 size;
148 __le64 nblocks;
149 __le32 nlink;
150 __le32 uid;
151 __le32 gid;
152 __le32 mode;
153 __le32 rdev;
154 __le16 flags;
155 __le16 compat_flags;
156 struct btrfs_inode_timespec atime;
157 struct btrfs_inode_timespec ctime;
158 struct btrfs_inode_timespec mtime;
159 struct btrfs_inode_timespec otime;
160} __attribute__ ((__packed__));
161
162/* inline data is just a blob of bytes */
163struct btrfs_inline_data_item {
164 u8 data;
165} __attribute__ ((__packed__));
166
62e2749e
CM
167struct btrfs_dir_item {
168 __le64 objectid;
169 __le16 flags;
a8a2ee0c 170 __le16 name_len;
62e2749e
CM
171 u8 type;
172} __attribute__ ((__packed__));
173
174struct btrfs_root_item {
175 __le64 blocknr;
176 __le32 flags;
177 __le64 block_limit;
178 __le64 blocks_used;
179 __le32 refs;
9f5fae2f 180} __attribute__ ((__packed__));
62e2749e 181
9f5fae2f
CM
182struct btrfs_file_extent_item {
183 /*
184 * disk space consumed by the extent, checksum blocks are included
185 * in these numbers
186 */
187 __le64 disk_blocknr;
188 __le64 disk_num_blocks;
189 /*
190 * the logical offset in file bytes (no csums)
191 * this extent record is for. This allows a file extent to point
192 * into the middle of an existing extent on disk, sharing it
193 * between two snapshots (useful if some bytes in the middle of the
194 * extent have changed
195 */
196 __le64 offset;
197 /*
198 * the logical number of file blocks (no csums included)
199 */
200 __le64 num_blocks;
201} __attribute__ ((__packed__));
202
203struct btrfs_inode_map_item {
204 struct btrfs_disk_key key;
205} __attribute__ ((__packed__));
206
207struct btrfs_fs_info {
208 struct btrfs_root *fs_root;
62e2749e
CM
209 struct btrfs_root *extent_root;
210 struct btrfs_root *tree_root;
9f5fae2f 211 struct btrfs_root *inode_root;
62e2749e
CM
212 struct btrfs_key current_insert;
213 struct btrfs_key last_insert;
62e2749e
CM
214 struct radix_tree_root cache_radix;
215 struct radix_tree_root pinned_radix;
216 struct list_head trans;
217 struct list_head cache;
9f5fae2f
CM
218 u64 last_inode_alloc;
219 u64 last_inode_alloc_dirid;
293ffd5f 220 u64 generation;
62e2749e 221 int cache_size;
9f5fae2f
CM
222 int fp;
223 struct btrfs_trans_handle *running_transaction;
1261ec42 224 struct btrfs_super_block *disk_super;
9f5fae2f
CM
225};
226
227/*
228 * in ram representation of the tree. extent_root is used for all allocations
229 * and for the extent tree extent_root root. current_insert is used
230 * only for the extent tree.
231 */
232struct btrfs_root {
233 struct btrfs_buffer *node;
234 struct btrfs_buffer *commit_root;
62e2749e
CM
235 struct btrfs_root_item root_item;
236 struct btrfs_key root_key;
9f5fae2f 237 struct btrfs_fs_info *fs_info;
62e2749e 238 u32 blocksize;
9f5fae2f
CM
239 int ref_cows;
240 u32 type;
62e2749e
CM
241};
242
62e2749e
CM
243/* the lower bits in the key flags defines the item type */
244#define BTRFS_KEY_TYPE_MAX 256
245#define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1)
1e1d2701
CM
246
247/*
248 * inode items have the data typically returned from stat and store other
249 * info about object characteristics. There is one for every file and dir in
250 * the FS
251 */
62e2749e 252#define BTRFS_INODE_ITEM_KEY 1
1e1d2701
CM
253
254/*
255 * dir items are the name -> inode pointers in a directory. There is one
256 * for every name in a directory.
257 */
62e2749e 258#define BTRFS_DIR_ITEM_KEY 2
1e1d2701
CM
259/*
260 * inline data is file data that fits in the btree.
261 */
262#define BTRFS_INLINE_DATA_KEY 3
263/*
264 * extent data is for data that can't fit in the btree. It points to
265 * a (hopefully) huge chunk of disk
266 */
267#define BTRFS_EXTENT_DATA_KEY 4
268/*
269 * root items point to tree roots. There are typically in the root
270 * tree used by the super block to find all the other trees
271 */
272#define BTRFS_ROOT_ITEM_KEY 5
273/*
274 * extent items are in the extent map tree. These record which blocks
275 * are used, and how many references there are to each block
276 */
277#define BTRFS_EXTENT_ITEM_KEY 6
9f5fae2f
CM
278
279/*
280 * the inode map records which inode numbers are in use and where
281 * they actually live on disk
282 */
283#define BTRFS_INODE_MAP_ITEM_KEY 7
1e1d2701
CM
284/*
285 * string items are for debugging. They just store a short string of
286 * data in the FS
287 */
9f5fae2f 288#define BTRFS_STRING_ITEM_KEY 8
1e1d2701
CM
289
290static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
291{
292 return le64_to_cpu(i->generation);
293}
294
295static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
296 u64 val)
297{
298 i->generation = cpu_to_le64(val);
299}
300
301static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
302{
303 return le64_to_cpu(i->size);
304}
305
306static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
307{
308 i->size = cpu_to_le64(val);
309}
310
311static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
312{
313 return le64_to_cpu(i->nblocks);
314}
315
316static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
317{
318 i->nblocks = cpu_to_le64(val);
319}
320
321static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
322{
323 return le32_to_cpu(i->nlink);
324}
325
326static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
327{
328 i->nlink = cpu_to_le32(val);
329}
330
331static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
332{
333 return le32_to_cpu(i->uid);
334}
335
336static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
337{
338 i->uid = cpu_to_le32(val);
339}
340
341static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
342{
343 return le32_to_cpu(i->gid);
344}
345
346static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
347{
348 i->gid = cpu_to_le32(val);
349}
350
351static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
352{
353 return le32_to_cpu(i->mode);
354}
355
356static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
357{
358 i->mode = cpu_to_le32(val);
359}
360
361static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
362{
363 return le32_to_cpu(i->rdev);
364}
365
366static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
367{
368 i->rdev = cpu_to_le32(val);
369}
370
371static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
372{
373 return le16_to_cpu(i->flags);
374}
375
376static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
377{
378 i->flags = cpu_to_le16(val);
379}
380
381static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
382{
383 return le16_to_cpu(i->compat_flags);
384}
385
386static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
387 u16 val)
388{
389 i->compat_flags = cpu_to_le16(val);
390}
391
62e2749e 392
234b63a0 393static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
cf27e1ee
CM
394{
395 return le64_to_cpu(ei->owner);
396}
397
234b63a0 398static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
cf27e1ee
CM
399{
400 ei->owner = cpu_to_le64(val);
401}
402
234b63a0 403static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
cf27e1ee
CM
404{
405 return le32_to_cpu(ei->refs);
406}
407
234b63a0 408static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
cf27e1ee
CM
409{
410 ei->refs = cpu_to_le32(val);
411}
412
234b63a0 413static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
1d4f8a0c 414{
123abc88 415 return le64_to_cpu(n->ptrs[nr].blockptr);
1d4f8a0c
CM
416}
417
234b63a0
CM
418static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
419 u64 val)
1d4f8a0c 420{
123abc88 421 n->ptrs[nr].blockptr = cpu_to_le64(val);
1d4f8a0c
CM
422}
423
123abc88 424static inline u32 btrfs_item_offset(struct btrfs_item *item)
0783fcfc 425{
123abc88 426 return le32_to_cpu(item->offset);
0783fcfc
CM
427}
428
123abc88 429static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
0783fcfc 430{
123abc88 431 item->offset = cpu_to_le32(val);
0783fcfc
CM
432}
433
123abc88 434static inline u32 btrfs_item_end(struct btrfs_item *item)
0783fcfc 435{
123abc88 436 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
0783fcfc
CM
437}
438
439static inline u16 btrfs_item_size(struct btrfs_item *item)
440{
441 return le16_to_cpu(item->size);
442}
443
444static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
445{
446 item->size = cpu_to_le16(val);
447}
448
1d4f6404
CM
449static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d)
450{
451 return le64_to_cpu(d->objectid);
452}
453
454static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val)
455{
456 d->objectid = cpu_to_le64(val);
457}
458
459static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
460{
461 return le16_to_cpu(d->flags);
462}
463
464static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
465{
466 d->flags = cpu_to_le16(val);
467}
468
469static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
470{
471 return d->type;
472}
473
474static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
475{
476 d->type = val;
477}
478
a8a2ee0c
CM
479static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
480{
481 return le16_to_cpu(d->name_len);
482}
483
484static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
1d4f6404 485{
a8a2ee0c 486 d->name_len = cpu_to_le16(val);
1d4f6404
CM
487}
488
e2fa7227
CM
489static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
490 struct btrfs_disk_key *disk)
491{
492 cpu->offset = le64_to_cpu(disk->offset);
493 cpu->flags = le32_to_cpu(disk->flags);
494 cpu->objectid = le64_to_cpu(disk->objectid);
495}
496
497static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
498 struct btrfs_key *cpu)
499{
500 disk->offset = cpu_to_le64(cpu->offset);
501 disk->flags = cpu_to_le32(cpu->flags);
502 disk->objectid = cpu_to_le64(cpu->objectid);
503}
504
62e2749e 505static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
e2fa7227
CM
506{
507 return le64_to_cpu(disk->objectid);
508}
509
62e2749e
CM
510static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
511 u64 val)
e2fa7227
CM
512{
513 disk->objectid = cpu_to_le64(val);
514}
515
62e2749e 516static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
e2fa7227
CM
517{
518 return le64_to_cpu(disk->offset);
519}
520
62e2749e
CM
521static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
522 u64 val)
e2fa7227
CM
523{
524 disk->offset = cpu_to_le64(val);
525}
526
62e2749e 527static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
e2fa7227
CM
528{
529 return le32_to_cpu(disk->flags);
530}
531
62e2749e
CM
532static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
533 u32 val)
e2fa7227
CM
534{
535 disk->flags = cpu_to_le32(val);
536}
537
62e2749e
CM
538static inline u32 btrfs_key_type(struct btrfs_key *key)
539{
540 return key->flags & BTRFS_KEY_TYPE_MASK;
541}
542
543static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
544{
545 return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK;
546}
547
548static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type)
549{
550 BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
551 key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
552}
553
554static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type)
555{
556 u32 flags = btrfs_disk_key_flags(key);
557 BUG_ON(type >= BTRFS_KEY_TYPE_MAX);
558 flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type;
559 btrfs_set_disk_key_flags(key, flags);
560}
561
bb492bb0 562static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
7518a238 563{
bb492bb0 564 return le64_to_cpu(h->blocknr);
7518a238
CM
565}
566
bb492bb0 567static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
7518a238 568{
bb492bb0 569 h->blocknr = cpu_to_le64(blocknr);
7518a238
CM
570}
571
bb492bb0 572static inline u64 btrfs_header_parentid(struct btrfs_header *h)
7518a238 573{
bb492bb0 574 return le64_to_cpu(h->parentid);
7518a238
CM
575}
576
bb492bb0
CM
577static inline void btrfs_set_header_parentid(struct btrfs_header *h,
578 u64 parentid)
7518a238 579{
bb492bb0 580 h->parentid = cpu_to_le64(parentid);
7518a238
CM
581}
582
bb492bb0 583static inline u16 btrfs_header_nritems(struct btrfs_header *h)
7518a238 584{
bb492bb0 585 return le16_to_cpu(h->nritems);
7518a238
CM
586}
587
bb492bb0 588static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
7518a238 589{
bb492bb0 590 h->nritems = cpu_to_le16(val);
7518a238
CM
591}
592
bb492bb0 593static inline u16 btrfs_header_flags(struct btrfs_header *h)
7518a238 594{
bb492bb0 595 return le16_to_cpu(h->flags);
7518a238
CM
596}
597
bb492bb0 598static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
7518a238 599{
bb492bb0 600 h->flags = cpu_to_le16(val);
7518a238
CM
601}
602
bb492bb0 603static inline int btrfs_header_level(struct btrfs_header *h)
7518a238 604{
234b63a0 605 return btrfs_header_flags(h) & (BTRFS_MAX_LEVEL - 1);
7518a238
CM
606}
607
bb492bb0 608static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
7518a238 609{
bb492bb0 610 u16 flags;
234b63a0
CM
611 BUG_ON(level > BTRFS_MAX_LEVEL);
612 flags = btrfs_header_flags(h) & ~(BTRFS_MAX_LEVEL - 1);
7518a238
CM
613 btrfs_set_header_flags(h, flags | level);
614}
615
234b63a0 616static inline int btrfs_is_leaf(struct btrfs_node *n)
7518a238
CM
617{
618 return (btrfs_header_level(&n->header) == 0);
619}
620
3768f368
CM
621static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
622{
623 return le64_to_cpu(item->blocknr);
624}
625
626static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
627{
628 item->blocknr = cpu_to_le64(val);
629}
630
631static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
632{
633 return le32_to_cpu(item->refs);
634}
635
636static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
637{
638 item->refs = cpu_to_le32(val);
639}
640
641static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
642{
643 return le64_to_cpu(s->blocknr);
644}
645
646static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
647{
648 s->blocknr = cpu_to_le64(val);
649}
650
651static inline u64 btrfs_super_root(struct btrfs_super_block *s)
652{
653 return le64_to_cpu(s->root);
654}
655
656static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
657{
658 s->root = cpu_to_le64(val);
659}
660
661static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
662{
663 return le64_to_cpu(s->total_blocks);
664}
665
666static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
667 u64 val)
668{
669 s->total_blocks = cpu_to_le64(val);
670}
671
672static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
673{
674 return le64_to_cpu(s->blocks_used);
675}
676
677static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
678 u64 val)
679{
680 s->blocks_used = cpu_to_le64(val);
681}
682
123abc88 683static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
3768f368 684{
123abc88 685 return le32_to_cpu(s->blocksize);
3768f368
CM
686}
687
688static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
123abc88
CM
689 u32 val)
690{
691 s->blocksize = cpu_to_le32(val);
692}
693
2e635a27
CM
694static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
695{
696 return le64_to_cpu(s->root_dir_objectid);
697}
698
699static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
700 val)
701{
702 s->root_dir_objectid = cpu_to_le64(val);
703}
704
123abc88 705static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
3768f368 706{
123abc88 707 return (u8 *)l->items;
3768f368 708}
9f5fae2f
CM
709
710static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
711 *e)
712{
713 return le64_to_cpu(e->disk_blocknr);
714}
715
716static inline void btrfs_set_file_extent_disk_blocknr(struct
717 btrfs_file_extent_item
718 *e, u64 val)
719{
720 e->disk_blocknr = cpu_to_le64(val);
721}
722
723static inline u64 btrfs_file_extent_disk_num_blocks(struct
724 btrfs_file_extent_item *e)
725{
726 return le64_to_cpu(e->disk_num_blocks);
727}
728
729static inline void btrfs_set_file_extent_disk_num_blocks(struct
730 btrfs_file_extent_item
731 *e, u64 val)
732{
733 e->disk_num_blocks = cpu_to_le64(val);
734}
735
736static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
737{
738 return le64_to_cpu(e->offset);
739}
740
741static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
742 *e, u64 val)
743{
744 e->offset = cpu_to_le64(val);
745}
746
747static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
748 *e)
749{
750 return le64_to_cpu(e->num_blocks);
751}
752
753static inline void btrfs_set_file_extent_num_blocks(struct
754 btrfs_file_extent_item *e,
755 u64 val)
756{
757 e->num_blocks = cpu_to_le64(val);
758}
759
4beb1b8b
CM
760/* helper function to cast into the data area of the leaf. */
761#define btrfs_item_ptr(leaf, slot, type) \
123abc88
CM
762 ((type *)(btrfs_leaf_data(leaf) + \
763 btrfs_item_offset((leaf)->items + (slot))))
4beb1b8b 764
e089f05c
CM
765struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
766 struct btrfs_root *root);
767int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
768 struct btrfs_buffer *buf);
769int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
770 *root, u64 blocknr, u64 num_blocks, int pin);
771int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
772 *root, struct btrfs_key *key, struct btrfs_path *p, int
773 ins_len, int cow);
234b63a0
CM
774void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
775void btrfs_init_path(struct btrfs_path *p);
e089f05c
CM
776int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
777 struct btrfs_path *path);
778int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
779 *root, struct btrfs_key *key, void *data, u32 data_size);
780int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
781 *root, struct btrfs_path *path, struct btrfs_key
782 *cpu_key, u32 data_size);
234b63a0 783int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
123abc88 784int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
e089f05c
CM
785int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
786 *root, struct btrfs_buffer *snap);
787int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
788 btrfs_root *root);
789int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
790 struct btrfs_key *key);
791int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
792 *root, struct btrfs_key *key, struct btrfs_root_item
793 *item);
794int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
795 *root, struct btrfs_key *key, struct btrfs_root_item
796 *item);
797int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
798 btrfs_root_item *item, struct btrfs_key *key);
799int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
800 *root, char *name, int name_len, u64 dir, u64
801 objectid, u8 type);
802int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
803 *root, struct btrfs_path *path, u64 dir, char *name,
804 int name_len, int mod);
1d4f6404
CM
805int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
806 char *name, int name_len);
9f5fae2f
CM
807int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
808 struct btrfs_root *fs_root,
809 u64 dirid, u64 *objectid);
810int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
811 struct btrfs_root *root,
812 u64 objectid, struct btrfs_key *location);
813int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
814 struct btrfs_root *root, struct btrfs_path *path,
815 u64 objectid, int mod);
293ffd5f
CM
816int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
817 *root, u64 objectid, struct btrfs_inode_item
818 *inode_item);
819int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
820 *root, struct btrfs_path *path, u64 objectid, int mod);
eb60ceac 821#endif