calculate checksums during IO
[btrfs-progs-unstable/devel.git] / ctree.h
blobfc84de32d315b7352fd7cf58b7930cbed5011c80
1 /*
2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
19 #ifndef __BTRFS__
20 #define __BTRFS__
22 #include "list.h"
23 #include "kerncompat.h"
25 struct btrfs_trans_handle;
27 #define BTRFS_MAGIC "_BtRfS_M"
29 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
30 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
31 #define BTRFS_FS_TREE_OBJECTID 3ULL
32 #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
33 #define BTRFS_FIRST_FREE_OBJECTID 5ULL
36 * we can actually store much bigger names, but lets not confuse the rest
37 * of linux
39 #define BTRFS_NAME_LEN 255
41 /* 32 bytes in various csum fields */
42 #define BTRFS_CSUM_SIZE 32
43 /* four bytes for CRC32 */
44 #define BTRFS_CRC32_SIZE 4
46 #define BTRFS_FT_UNKNOWN 0
47 #define BTRFS_FT_REG_FILE 1
48 #define BTRFS_FT_DIR 2
49 #define BTRFS_FT_CHRDEV 3
50 #define BTRFS_FT_BLKDEV 4
51 #define BTRFS_FT_FIFO 5
52 #define BTRFS_FT_SOCK 6
53 #define BTRFS_FT_SYMLINK 7
54 #define BTRFS_FT_MAX 8
57 * the key defines the order in the tree, and so it also defines (optimal)
58 * block layout. objectid corresonds to the inode number. The flags
59 * tells us things about the object, and is a kind of stream selector.
60 * so for a given inode, keys with flags of 1 might refer to the inode
61 * data, flags of 2 may point to file data in the btree and flags == 3
62 * may point to extents.
64 * offset is the starting byte offset for this key in the stream.
66 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
67 * in cpu native order. Otherwise they are identical and their sizes
68 * should be the same (ie both packed)
70 struct btrfs_disk_key {
71 __le64 objectid;
72 __le32 flags;
73 __le64 offset;
74 } __attribute__ ((__packed__));
76 struct btrfs_key {
77 u64 objectid;
78 u32 flags;
79 u64 offset;
80 } __attribute__ ((__packed__));
83 * every tree block (leaf or node) starts with this header.
85 struct btrfs_header {
86 u8 csum[BTRFS_CSUM_SIZE];
87 u8 fsid[16]; /* FS specific uuid */
88 __le64 blocknr; /* which block this node is supposed to live in */
89 __le64 generation;
90 __le64 owner;
91 __le16 nritems;
92 __le16 flags;
93 u8 level;
94 } __attribute__ ((__packed__));
96 #define BTRFS_MAX_LEVEL 8
97 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
98 sizeof(struct btrfs_header)) / \
99 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
100 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
101 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
103 struct btrfs_buffer;
105 * the super block basically lists the main trees of the FS
106 * it currently lacks any block count etc etc
108 struct btrfs_super_block {
109 u8 csum[BTRFS_CSUM_SIZE];
110 /* the first 3 fields must match struct btrfs_header */
111 u8 fsid[16]; /* FS specific uuid */
112 __le64 blocknr; /* this block number */
113 __le64 magic;
114 __le64 generation;
115 __le64 root;
116 __le64 total_blocks;
117 __le64 blocks_used;
118 __le64 root_dir_objectid;
119 __le32 blocksize;
120 } __attribute__ ((__packed__));
123 * A leaf is full of items. offset and size tell us where to find
124 * the item in the leaf (relative to the start of the data area)
126 struct btrfs_item {
127 struct btrfs_disk_key key;
128 __le32 offset;
129 __le16 size;
130 } __attribute__ ((__packed__));
133 * leaves have an item area and a data area:
134 * [item0, item1....itemN] [free space] [dataN...data1, data0]
136 * The data is separate from the items to get the keys closer together
137 * during searches.
139 struct btrfs_leaf {
140 struct btrfs_header header;
141 struct btrfs_item items[];
142 } __attribute__ ((__packed__));
145 * all non-leaf blocks are nodes, they hold only keys and pointers to
146 * other blocks
148 struct btrfs_key_ptr {
149 struct btrfs_disk_key key;
150 __le64 blockptr;
151 } __attribute__ ((__packed__));
153 struct btrfs_node {
154 struct btrfs_header header;
155 struct btrfs_key_ptr ptrs[];
156 } __attribute__ ((__packed__));
159 * btrfs_paths remember the path taken from the root down to the leaf.
160 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
161 * to any other levels that are present.
163 * The slots array records the index of the item or block pointer
164 * used while walking the tree.
166 struct btrfs_path {
167 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
168 int slots[BTRFS_MAX_LEVEL];
172 * items in the extent btree are used to record the objectid of the
173 * owner of the block and the number of references
175 struct btrfs_extent_item {
176 __le32 refs;
177 __le64 owner;
178 } __attribute__ ((__packed__));
180 struct btrfs_inode_timespec {
181 __le64 sec;
182 __le32 nsec;
183 } __attribute__ ((__packed__));
186 * there is no padding here on purpose. If you want to extent the inode,
187 * make a new item type
189 struct btrfs_inode_item {
190 __le64 generation;
191 __le64 size;
192 __le64 nblocks;
193 __le64 block_group;
194 __le32 nlink;
195 __le32 uid;
196 __le32 gid;
197 __le32 mode;
198 __le32 rdev;
199 __le16 flags;
200 __le16 compat_flags;
201 struct btrfs_inode_timespec atime;
202 struct btrfs_inode_timespec ctime;
203 struct btrfs_inode_timespec mtime;
204 struct btrfs_inode_timespec otime;
205 } __attribute__ ((__packed__));
207 /* inline data is just a blob of bytes */
208 struct btrfs_inline_data_item {
209 u8 data;
210 } __attribute__ ((__packed__));
212 struct btrfs_dir_item {
213 struct btrfs_disk_key location;
214 __le16 flags;
215 __le16 name_len;
216 u8 type;
217 } __attribute__ ((__packed__));
219 struct btrfs_root_item {
220 struct btrfs_inode_item inode;
221 __le64 root_dirid;
222 __le64 blocknr;
223 __le64 block_limit;
224 __le64 blocks_used;
225 __le32 flags;
226 __le32 refs;
227 struct btrfs_disk_key drop_progress;
228 u8 drop_level;
229 } __attribute__ ((__packed__));
231 #define BTRFS_FILE_EXTENT_REG 0
232 #define BTRFS_FILE_EXTENT_INLINE 1
234 struct btrfs_file_extent_item {
235 __le64 generation;
236 u8 type;
238 * disk space consumed by the extent, checksum blocks are included
239 * in these numbers
241 __le64 disk_blocknr;
242 __le64 disk_num_blocks;
244 * the logical offset in file blocks (no csums)
245 * this extent record is for. This allows a file extent to point
246 * into the middle of an existing extent on disk, sharing it
247 * between two snapshots (useful if some bytes in the middle of the
248 * extent have changed
250 __le64 offset;
252 * the logical number of file blocks (no csums included)
254 __le64 num_blocks;
255 } __attribute__ ((__packed__));
257 struct btrfs_csum_item {
258 u8 csum[BTRFS_CSUM_SIZE];
259 } __attribute__ ((__packed__));
261 /* tag for the radix tree of block groups in ram */
262 #define BTRFS_BLOCK_GROUP_DIRTY 0
263 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
266 #define BTRFS_BLOCK_GROUP_DATA 1
267 struct btrfs_block_group_item {
268 __le64 used;
269 u8 flags;
270 } __attribute__ ((__packed__));
272 struct btrfs_block_group_cache {
273 struct btrfs_key key;
274 struct btrfs_block_group_item item;
277 struct btrfs_fs_info {
278 struct btrfs_root *fs_root;
279 struct btrfs_root *extent_root;
280 struct btrfs_root *tree_root;
281 struct btrfs_key current_insert;
282 struct btrfs_key last_insert;
283 struct radix_tree_root cache_radix;
284 struct radix_tree_root pinned_radix;
285 struct radix_tree_root block_group_radix;
286 struct list_head trans;
287 struct list_head cache;
288 u64 last_inode_alloc;
289 u64 last_inode_alloc_dirid;
290 u64 generation;
291 int cache_size;
292 int fp;
293 struct btrfs_trans_handle *running_transaction;
294 struct btrfs_super_block *disk_super;
298 * in ram representation of the tree. extent_root is used for all allocations
299 * and for the extent tree extent_root root. current_insert is used
300 * only for the extent tree.
302 struct btrfs_root {
303 struct btrfs_buffer *node;
304 struct btrfs_buffer *commit_root;
305 struct btrfs_root_item root_item;
306 struct btrfs_key root_key;
307 struct btrfs_fs_info *fs_info;
308 u32 blocksize;
309 int ref_cows;
310 u32 type;
313 /* the lower bits in the key flags defines the item type */
314 #define BTRFS_KEY_TYPE_MAX 256
315 #define BTRFS_KEY_TYPE_SHIFT 24
316 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
317 BTRFS_KEY_TYPE_SHIFT)
320 * inode items have the data typically returned from stat and store other
321 * info about object characteristics. There is one for every file and dir in
322 * the FS
324 #define BTRFS_INODE_ITEM_KEY 1
326 /* reserve 2-15 close to the inode for later flexibility */
329 * dir items are the name -> inode pointers in a directory. There is one
330 * for every name in a directory.
332 #define BTRFS_DIR_ITEM_KEY 16
333 #define BTRFS_DIR_INDEX_KEY 17
335 * extent data is for file data
337 #define BTRFS_EXTENT_DATA_KEY 18
339 * csum items have the checksums for data in the extents
341 #define BTRFS_CSUM_ITEM_KEY 19
343 /* reserve 20-31 for other file stuff */
346 * root items point to tree roots. There are typically in the root
347 * tree used by the super block to find all the other trees
349 #define BTRFS_ROOT_ITEM_KEY 32
351 * extent items are in the extent map tree. These record which blocks
352 * are used, and how many references there are to each block
354 #define BTRFS_EXTENT_ITEM_KEY 33
357 * block groups give us hints into the extent allocation trees. Which
358 * blocks are free etc etc
360 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
363 * string items are for debugging. They just store a short string of
364 * data in the FS
366 #define BTRFS_STRING_ITEM_KEY 253
369 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
371 return le64_to_cpu(bi->used);
374 static inline void btrfs_set_block_group_used(struct
375 btrfs_block_group_item *bi,
376 u64 val)
378 bi->used = cpu_to_le64(val);
381 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
383 return le64_to_cpu(i->generation);
386 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
387 u64 val)
389 i->generation = cpu_to_le64(val);
392 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
394 return le64_to_cpu(i->size);
397 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
399 i->size = cpu_to_le64(val);
402 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
404 return le64_to_cpu(i->nblocks);
407 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
409 i->nblocks = cpu_to_le64(val);
412 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
414 return le64_to_cpu(i->block_group);
417 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
418 u64 val)
420 i->block_group = cpu_to_le64(val);
423 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
425 return le32_to_cpu(i->nlink);
428 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
430 i->nlink = cpu_to_le32(val);
433 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
435 return le32_to_cpu(i->uid);
438 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
440 i->uid = cpu_to_le32(val);
443 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
445 return le32_to_cpu(i->gid);
448 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
450 i->gid = cpu_to_le32(val);
453 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
455 return le32_to_cpu(i->mode);
458 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
460 i->mode = cpu_to_le32(val);
463 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
465 return le32_to_cpu(i->rdev);
468 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
470 i->rdev = cpu_to_le32(val);
473 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
475 return le16_to_cpu(i->flags);
478 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
480 i->flags = cpu_to_le16(val);
483 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
485 return le16_to_cpu(i->compat_flags);
488 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
489 u16 val)
491 i->compat_flags = cpu_to_le16(val);
494 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
496 return le64_to_cpu(ts->sec);
499 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
500 u64 val)
502 ts->sec = cpu_to_le64(val);
505 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
507 return le32_to_cpu(ts->nsec);
510 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
511 u32 val)
513 ts->nsec = cpu_to_le32(val);
516 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
518 return le32_to_cpu(ei->refs);
521 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
523 ei->refs = cpu_to_le32(val);
526 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
528 return le64_to_cpu(ei->owner);
531 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
533 ei->owner = cpu_to_le64(val);
536 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
538 return le64_to_cpu(n->ptrs[nr].blockptr);
542 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
543 u64 val)
545 n->ptrs[nr].blockptr = cpu_to_le64(val);
548 static inline u32 btrfs_item_offset(struct btrfs_item *item)
550 return le32_to_cpu(item->offset);
553 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
555 item->offset = cpu_to_le32(val);
558 static inline u32 btrfs_item_end(struct btrfs_item *item)
560 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
563 static inline u16 btrfs_item_size(struct btrfs_item *item)
565 return le16_to_cpu(item->size);
568 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
570 item->size = cpu_to_le16(val);
573 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
575 return le16_to_cpu(d->flags);
578 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
580 d->flags = cpu_to_le16(val);
583 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
585 return d->type;
588 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
590 d->type = val;
593 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
595 return le16_to_cpu(d->name_len);
598 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
600 d->name_len = cpu_to_le16(val);
603 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
604 struct btrfs_disk_key *disk)
606 cpu->offset = le64_to_cpu(disk->offset);
607 cpu->flags = le32_to_cpu(disk->flags);
608 cpu->objectid = le64_to_cpu(disk->objectid);
611 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
612 struct btrfs_key *cpu)
614 disk->offset = cpu_to_le64(cpu->offset);
615 disk->flags = cpu_to_le32(cpu->flags);
616 disk->objectid = cpu_to_le64(cpu->objectid);
619 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
621 return le64_to_cpu(disk->objectid);
624 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
625 u64 val)
627 disk->objectid = cpu_to_le64(val);
630 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
632 return le64_to_cpu(disk->offset);
635 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
636 u64 val)
638 disk->offset = cpu_to_le64(val);
641 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
643 return le32_to_cpu(disk->flags);
646 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
647 u32 val)
649 disk->flags = cpu_to_le32(val);
652 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
654 return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
657 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
658 u32 val)
660 u32 flags = btrfs_disk_key_flags(key);
661 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
662 val = val << BTRFS_KEY_TYPE_SHIFT;
663 flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
664 btrfs_set_disk_key_flags(key, flags);
667 static inline u32 btrfs_key_type(struct btrfs_key *key)
669 return key->flags >> BTRFS_KEY_TYPE_SHIFT;
672 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
674 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
675 val = val << BTRFS_KEY_TYPE_SHIFT;
676 key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
679 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
681 return le64_to_cpu(h->blocknr);
684 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
686 h->blocknr = cpu_to_le64(blocknr);
689 static inline u64 btrfs_header_generation(struct btrfs_header *h)
691 return le64_to_cpu(h->generation);
694 static inline void btrfs_set_header_generation(struct btrfs_header *h,
695 u64 val)
697 h->generation = cpu_to_le64(val);
700 static inline u64 btrfs_header_owner(struct btrfs_header *h)
702 return le64_to_cpu(h->owner);
705 static inline void btrfs_set_header_owner(struct btrfs_header *h,
706 u64 val)
708 h->owner = cpu_to_le64(val);
711 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
713 return le16_to_cpu(h->nritems);
716 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
718 h->nritems = cpu_to_le16(val);
721 static inline u16 btrfs_header_flags(struct btrfs_header *h)
723 return le16_to_cpu(h->flags);
726 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
728 h->flags = cpu_to_le16(val);
731 static inline int btrfs_header_level(struct btrfs_header *h)
733 return h->level;
736 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
738 BUG_ON(level > BTRFS_MAX_LEVEL);
739 h->level = level;
742 static inline int btrfs_is_leaf(struct btrfs_node *n)
744 return (btrfs_header_level(&n->header) == 0);
747 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
749 return le64_to_cpu(item->blocknr);
752 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
754 item->blocknr = cpu_to_le64(val);
757 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
759 return le64_to_cpu(item->root_dirid);
762 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
764 item->root_dirid = cpu_to_le64(val);
767 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
769 return le32_to_cpu(item->refs);
772 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
774 item->refs = cpu_to_le32(val);
777 static inline u32 btrfs_root_flags(struct btrfs_root_item *item)
779 return le32_to_cpu(item->flags);
782 static inline void btrfs_set_root_flags(struct btrfs_root_item *item, u32 val)
784 item->flags = cpu_to_le32(val);
787 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
789 return le64_to_cpu(s->blocknr);
792 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
794 s->blocknr = cpu_to_le64(val);
797 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
799 return le64_to_cpu(s->generation);
802 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
803 u64 val)
805 s->generation = cpu_to_le64(val);
808 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
810 return le64_to_cpu(s->root);
813 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
815 s->root = cpu_to_le64(val);
818 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
820 return le64_to_cpu(s->total_blocks);
823 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
824 u64 val)
826 s->total_blocks = cpu_to_le64(val);
829 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
831 return le64_to_cpu(s->blocks_used);
834 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
835 u64 val)
837 s->blocks_used = cpu_to_le64(val);
840 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
842 return le32_to_cpu(s->blocksize);
845 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
846 u32 val)
848 s->blocksize = cpu_to_le32(val);
851 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
853 return le64_to_cpu(s->root_dir_objectid);
856 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
857 val)
859 s->root_dir_objectid = cpu_to_le64(val);
862 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
864 return (u8 *)l->items;
867 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
869 return e->type;
871 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
872 u8 val)
874 e->type = val;
877 static inline char *btrfs_file_extent_inline_start(struct
878 btrfs_file_extent_item *e)
880 return (char *)(&e->disk_blocknr);
883 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
885 return (unsigned long)(&((struct
886 btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
889 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
891 struct btrfs_file_extent_item *fe = NULL;
892 return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
895 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
898 return le64_to_cpu(e->disk_blocknr);
901 static inline void btrfs_set_file_extent_disk_blocknr(struct
902 btrfs_file_extent_item
903 *e, u64 val)
905 e->disk_blocknr = cpu_to_le64(val);
908 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
910 return le64_to_cpu(e->generation);
913 static inline void btrfs_set_file_extent_generation(struct
914 btrfs_file_extent_item *e,
915 u64 val)
917 e->generation = cpu_to_le64(val);
920 static inline u64 btrfs_file_extent_disk_num_blocks(struct
921 btrfs_file_extent_item *e)
923 return le64_to_cpu(e->disk_num_blocks);
926 static inline void btrfs_set_file_extent_disk_num_blocks(struct
927 btrfs_file_extent_item
928 *e, u64 val)
930 e->disk_num_blocks = cpu_to_le64(val);
933 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
935 return le64_to_cpu(e->offset);
938 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
939 *e, u64 val)
941 e->offset = cpu_to_le64(val);
944 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
947 return le64_to_cpu(e->num_blocks);
950 static inline void btrfs_set_file_extent_num_blocks(struct
951 btrfs_file_extent_item *e,
952 u64 val)
954 e->num_blocks = cpu_to_le64(val);
957 /* helper function to cast into the data area of the leaf. */
958 #define btrfs_item_ptr(leaf, slot, type) \
959 ((type *)(btrfs_leaf_data(leaf) + \
960 btrfs_item_offset((leaf)->items + (slot))))
962 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
963 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
964 *root, struct btrfs_path *path, u32 data_size);
965 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
966 struct btrfs_root *root);
967 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
968 struct btrfs_buffer *buf);
969 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
970 *root, u64 blocknr, u64 num_blocks, int pin);
971 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
972 *root, struct btrfs_key *key, struct btrfs_path *p, int
973 ins_len, int cow);
974 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
975 void btrfs_init_path(struct btrfs_path *p);
976 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
977 struct btrfs_path *path);
978 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
979 *root, struct btrfs_key *key, void *data, u32 data_size);
980 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
981 *root, struct btrfs_path *path, struct btrfs_key
982 *cpu_key, u32 data_size);
983 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
984 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
985 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
986 *root, struct btrfs_buffer *snap);
987 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
988 btrfs_root *root);
989 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
990 struct btrfs_key *key);
991 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
992 *root, struct btrfs_key *key, struct btrfs_root_item
993 *item);
994 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
995 *root, struct btrfs_key *key, struct btrfs_root_item
996 *item);
997 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
998 btrfs_root_item *item, struct btrfs_key *key);
999 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1000 *root, char *name, int name_len, u64 dir,
1001 struct btrfs_key *location, u8 type);
1002 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1003 *root, struct btrfs_path *path, u64 dir, char *name,
1004 int name_len, int mod);
1005 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
1006 char *name, int name_len);
1007 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1008 struct btrfs_root *fs_root,
1009 u64 dirid, u64 *objectid);
1010 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1011 *root, u64 objectid, struct btrfs_inode_item
1012 *inode_item);
1013 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1014 *root, struct btrfs_path *path, u64 objectid, int mod);
1015 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1016 struct btrfs_root *root);
1017 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1018 int btrfs_read_block_groups(struct btrfs_root *root);
1019 int btrfs_insert_block_group(struct btrfs_trans_handle *trans,
1020 struct btrfs_root *root,
1021 struct btrfs_key *key,
1022 struct btrfs_block_group_item *bi);
1023 #endif