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