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