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