Added tag v0.9 for changeset 99eb8cf2ca51
[btrfs-progs-unstable.git] / ctree.h
blobfb972c1d185d385ae4d3476b454760001819cb60
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"
24 #include "radix-tree.h"
25 #include "extent-cache.h"
27 struct btrfs_trans_handle;
29 #define BTRFS_MAGIC "_B2RfS_M"
31 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
32 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
33 #define BTRFS_FS_TREE_OBJECTID 3ULL
34 #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
35 #define BTRFS_FIRST_FREE_OBJECTID 5ULL
38 * we can actually store much bigger names, but lets not confuse the rest
39 * of linux
41 #define BTRFS_NAME_LEN 255
43 /* 32 bytes in various csum fields */
44 #define BTRFS_CSUM_SIZE 32
45 /* four bytes for CRC32 */
46 #define BTRFS_CRC32_SIZE 4
48 #define BTRFS_FT_UNKNOWN 0
49 #define BTRFS_FT_REG_FILE 1
50 #define BTRFS_FT_DIR 2
51 #define BTRFS_FT_CHRDEV 3
52 #define BTRFS_FT_BLKDEV 4
53 #define BTRFS_FT_FIFO 5
54 #define BTRFS_FT_SOCK 6
55 #define BTRFS_FT_SYMLINK 7
56 #define BTRFS_FT_XATTR 8
57 #define BTRFS_FT_MAX 9
60 * the key defines the order in the tree, and so it also defines (optimal)
61 * block layout. objectid corresonds to the inode number. The flags
62 * tells us things about the object, and is a kind of stream selector.
63 * so for a given inode, keys with flags of 1 might refer to the inode
64 * data, flags of 2 may point to file data in the btree and flags == 3
65 * may point to extents.
67 * offset is the starting byte offset for this key in the stream.
69 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
70 * in cpu native order. Otherwise they are identical and their sizes
71 * should be the same (ie both packed)
73 struct btrfs_disk_key {
74 __le64 objectid;
75 u8 type;
76 __le64 offset;
77 } __attribute__ ((__packed__));
79 struct btrfs_key {
80 u64 objectid;
81 u8 type;
82 u64 offset;
83 } __attribute__ ((__packed__));
86 * every tree block (leaf or node) starts with this header.
88 struct btrfs_header {
89 u8 csum[BTRFS_CSUM_SIZE];
90 u8 fsid[16]; /* FS specific uuid */
91 __le64 bytenr; /* which block this node is supposed to live in */
92 __le64 generation;
93 __le64 owner;
94 __le32 nritems;
95 __le16 flags;
96 u8 level;
97 } __attribute__ ((__packed__));
99 #define BTRFS_MAX_LEVEL 8
100 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
101 sizeof(struct btrfs_header)) / \
102 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
103 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
104 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
106 struct btrfs_buffer;
108 * the super block basically lists the main trees of the FS
109 * it currently lacks any block count etc etc
111 struct btrfs_super_block {
112 u8 csum[BTRFS_CSUM_SIZE];
113 /* the first 3 fields must match struct btrfs_header */
114 u8 fsid[16]; /* FS specific uuid */
115 __le64 bytenr; /* this block number */
116 __le64 magic;
117 __le64 generation;
118 __le64 root;
119 __le64 total_bytes;
120 __le64 bytes_used;
121 __le64 root_dir_objectid;
122 __le32 sectorsize;
123 __le32 nodesize;
124 __le32 leafsize;
125 __le32 stripesize;
126 u8 root_level;
127 } __attribute__ ((__packed__));
130 * A leaf is full of items. offset and size tell us where to find
131 * the item in the leaf (relative to the start of the data area)
133 struct btrfs_item {
134 struct btrfs_disk_key key;
135 __le32 offset;
136 __le32 size;
137 } __attribute__ ((__packed__));
140 * leaves have an item area and a data area:
141 * [item0, item1....itemN] [free space] [dataN...data1, data0]
143 * The data is separate from the items to get the keys closer together
144 * during searches.
146 struct btrfs_leaf {
147 struct btrfs_header header;
148 struct btrfs_item items[];
149 } __attribute__ ((__packed__));
152 * all non-leaf blocks are nodes, they hold only keys and pointers to
153 * other blocks
155 struct btrfs_key_ptr {
156 struct btrfs_disk_key key;
157 __le64 blockptr;
158 } __attribute__ ((__packed__));
160 struct btrfs_node {
161 struct btrfs_header header;
162 struct btrfs_key_ptr ptrs[];
163 } __attribute__ ((__packed__));
166 * btrfs_paths remember the path taken from the root down to the leaf.
167 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
168 * to any other levels that are present.
170 * The slots array records the index of the item or block pointer
171 * used while walking the tree.
173 struct btrfs_path {
174 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
175 int slots[BTRFS_MAX_LEVEL];
179 * items in the extent btree are used to record the objectid of the
180 * owner of the block and the number of references
182 struct btrfs_extent_item {
183 __le32 refs;
184 __le64 owner;
185 } __attribute__ ((__packed__));
187 struct btrfs_inode_timespec {
188 __le64 sec;
189 __le32 nsec;
190 } __attribute__ ((__packed__));
193 * there is no padding here on purpose. If you want to extent the inode,
194 * make a new item type
196 struct btrfs_inode_item {
197 __le64 generation;
198 __le64 size;
199 __le64 nblocks;
200 __le64 block_group;
201 __le32 nlink;
202 __le32 uid;
203 __le32 gid;
204 __le32 mode;
205 __le32 rdev;
206 __le16 flags;
207 __le16 compat_flags;
208 struct btrfs_inode_timespec atime;
209 struct btrfs_inode_timespec ctime;
210 struct btrfs_inode_timespec mtime;
211 struct btrfs_inode_timespec otime;
212 } __attribute__ ((__packed__));
214 /* inline data is just a blob of bytes */
215 struct btrfs_inline_data_item {
216 u8 data;
217 } __attribute__ ((__packed__));
219 struct btrfs_dir_item {
220 struct btrfs_disk_key location;
221 __le16 data_len;
222 __le16 name_len;
223 u8 type;
224 } __attribute__ ((__packed__));
226 struct btrfs_root_item {
227 struct btrfs_inode_item inode;
228 __le64 root_dirid;
229 __le64 bytenr;
230 __le64 byte_limit;
231 __le64 bytes_used;
232 __le32 flags;
233 __le32 refs;
234 struct btrfs_disk_key drop_progress;
235 u8 drop_level;
236 u8 level;
237 } __attribute__ ((__packed__));
239 #define BTRFS_FILE_EXTENT_REG 0
240 #define BTRFS_FILE_EXTENT_INLINE 1
242 struct btrfs_file_extent_item {
243 __le64 generation;
244 u8 type;
246 * disk space consumed by the extent, checksum blocks are included
247 * in these numbers
249 __le64 disk_bytenr;
250 __le64 disk_num_bytes;
252 * the logical offset in file blocks (no csums)
253 * this extent record is for. This allows a file extent to point
254 * into the middle of an existing extent on disk, sharing it
255 * between two snapshots (useful if some bytes in the middle of the
256 * extent have changed
258 __le64 offset;
260 * the logical number of file blocks (no csums included)
262 __le64 num_bytes;
263 } __attribute__ ((__packed__));
265 struct btrfs_csum_item {
266 u8 csum[BTRFS_CSUM_SIZE];
267 } __attribute__ ((__packed__));
269 /* tag for the radix tree of block groups in ram */
270 #define BTRFS_BLOCK_GROUP_DIRTY 0
271 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
274 #define BTRFS_BLOCK_GROUP_DATA 1
275 struct btrfs_block_group_item {
276 __le64 used;
277 u8 flags;
278 } __attribute__ ((__packed__));
280 struct btrfs_block_group_cache {
281 struct cache_extent cache;
282 struct btrfs_key key;
283 struct btrfs_block_group_item item;
284 int dirty;
287 struct btrfs_fs_info {
288 struct btrfs_root *fs_root;
289 struct btrfs_root *extent_root;
290 struct btrfs_root *tree_root;
291 struct btrfs_key last_insert;
292 struct cache_tree extent_cache;
293 struct cache_tree block_group_cache;
294 struct cache_tree pending_tree;
295 struct cache_tree pinned_tree;
296 struct cache_tree del_pending;
297 struct list_head trans;
298 struct list_head cache;
299 u64 last_inode_alloc;
300 u64 last_inode_alloc_dirid;
301 u64 generation;
302 int cache_size;
303 int fp;
304 struct btrfs_trans_handle *running_transaction;
305 struct btrfs_super_block *disk_super;
309 * in ram representation of the tree. extent_root is used for all allocations
310 * and for the extent tree extent_root root.
312 struct btrfs_root {
313 struct btrfs_buffer *node;
314 struct btrfs_buffer *commit_root;
315 struct btrfs_root_item root_item;
316 struct btrfs_key root_key;
317 struct btrfs_fs_info *fs_info;
319 /* data allocations are done in sectorsize units */
320 u32 sectorsize;
322 /* node allocations are done in nodesize units */
323 u32 nodesize;
325 /* leaf allocations are done in leafsize units */
326 u32 leafsize;
328 /* leaf allocations are done in leafsize units */
329 u32 stripesize;
331 int ref_cows;
332 u32 type;
335 /* the lower bits in the key flags defines the item type */
336 #define BTRFS_KEY_TYPE_MAX 256
337 #define BTRFS_KEY_TYPE_SHIFT 24
338 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
339 BTRFS_KEY_TYPE_SHIFT)
342 * inode items have the data typically returned from stat and store other
343 * info about object characteristics. There is one for every file and dir in
344 * the FS
346 #define BTRFS_INODE_ITEM_KEY 1
347 #define BTRFS_XATTR_ITEM_KEY 2
349 /* reserve 3-15 close to the inode for later flexibility */
352 * dir items are the name -> inode pointers in a directory. There is one
353 * for every name in a directory.
355 #define BTRFS_DIR_ITEM_KEY 16
356 #define BTRFS_DIR_INDEX_KEY 17
358 * extent data is for file data
360 #define BTRFS_EXTENT_DATA_KEY 18
362 * csum items have the checksums for data in the extents
364 #define BTRFS_CSUM_ITEM_KEY 19
366 /* reserve 20-31 for other file stuff */
369 * root items point to tree roots. There are typically in the root
370 * tree used by the super block to find all the other trees
372 #define BTRFS_ROOT_ITEM_KEY 32
374 * extent items are in the extent map tree. These record which blocks
375 * are used, and how many references there are to each block
377 #define BTRFS_EXTENT_ITEM_KEY 33
380 * block groups give us hints into the extent allocation trees. Which
381 * blocks are free etc etc
383 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
386 * string items are for debugging. They just store a short string of
387 * data in the FS
389 #define BTRFS_STRING_ITEM_KEY 253
392 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
394 return le64_to_cpu(bi->used);
397 static inline void btrfs_set_block_group_used(struct
398 btrfs_block_group_item *bi,
399 u64 val)
401 bi->used = cpu_to_le64(val);
404 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
406 return le64_to_cpu(i->generation);
409 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
410 u64 val)
412 i->generation = cpu_to_le64(val);
415 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
417 return le64_to_cpu(i->size);
420 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
422 i->size = cpu_to_le64(val);
425 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
427 return le64_to_cpu(i->nblocks);
430 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
432 i->nblocks = cpu_to_le64(val);
435 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
437 return le64_to_cpu(i->block_group);
440 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
441 u64 val)
443 i->block_group = cpu_to_le64(val);
446 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
448 return le32_to_cpu(i->nlink);
451 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
453 i->nlink = cpu_to_le32(val);
456 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
458 return le32_to_cpu(i->uid);
461 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
463 i->uid = cpu_to_le32(val);
466 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
468 return le32_to_cpu(i->gid);
471 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
473 i->gid = cpu_to_le32(val);
476 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
478 return le32_to_cpu(i->mode);
481 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
483 i->mode = cpu_to_le32(val);
486 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
488 return le32_to_cpu(i->rdev);
491 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
493 i->rdev = cpu_to_le32(val);
496 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
498 return le16_to_cpu(i->flags);
501 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
503 i->flags = cpu_to_le16(val);
506 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
508 return le16_to_cpu(i->compat_flags);
511 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
512 u16 val)
514 i->compat_flags = cpu_to_le16(val);
517 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
519 return le64_to_cpu(ts->sec);
522 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
523 u64 val)
525 ts->sec = cpu_to_le64(val);
528 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
530 return le32_to_cpu(ts->nsec);
533 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
534 u32 val)
536 ts->nsec = cpu_to_le32(val);
539 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
541 return le32_to_cpu(ei->refs);
544 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
546 ei->refs = cpu_to_le32(val);
549 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
551 return le64_to_cpu(ei->owner);
554 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
556 ei->owner = cpu_to_le64(val);
559 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
561 return le64_to_cpu(n->ptrs[nr].blockptr);
565 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
566 u64 val)
568 n->ptrs[nr].blockptr = cpu_to_le64(val);
571 static inline u32 btrfs_item_offset(struct btrfs_item *item)
573 return le32_to_cpu(item->offset);
576 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
578 item->offset = cpu_to_le32(val);
581 static inline u32 btrfs_item_end(struct btrfs_item *item)
583 return le32_to_cpu(item->offset) + le32_to_cpu(item->size);
586 static inline u32 btrfs_item_size(struct btrfs_item *item)
588 return le32_to_cpu(item->size);
591 static inline void btrfs_set_item_size(struct btrfs_item *item, u32 val)
593 item->size = cpu_to_le32(val);
596 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
598 return d->type;
601 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
603 d->type = val;
606 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
608 return le16_to_cpu(d->name_len);
611 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
613 d->name_len = cpu_to_le16(val);
616 static inline u16 btrfs_dir_data_len(struct btrfs_dir_item *d)
618 return le16_to_cpu(d->data_len);
621 static inline void btrfs_set_dir_data_len(struct btrfs_dir_item *d, u16 val)
623 d->data_len = cpu_to_le16(val);
626 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
627 struct btrfs_disk_key *disk)
629 cpu->offset = le64_to_cpu(disk->offset);
630 cpu->type = le32_to_cpu(disk->type);
631 cpu->objectid = le64_to_cpu(disk->objectid);
634 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
635 struct btrfs_key *cpu)
637 disk->offset = cpu_to_le64(cpu->offset);
638 disk->type = cpu_to_le32(cpu->type);
639 disk->objectid = cpu_to_le64(cpu->objectid);
642 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
644 return le64_to_cpu(disk->objectid);
647 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
648 u64 val)
650 disk->objectid = cpu_to_le64(val);
653 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
655 return le64_to_cpu(disk->offset);
658 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
659 u64 val)
661 disk->offset = cpu_to_le64(val);
664 static inline u8 btrfs_disk_key_type(struct btrfs_disk_key *key)
666 return key->type;
669 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u8 val)
671 key->type = val;
674 static inline u32 btrfs_key_type(struct btrfs_key *key)
676 return key->type;
679 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
681 key->type = val;
684 static inline u64 btrfs_header_bytenr(struct btrfs_header *h)
686 return le64_to_cpu(h->bytenr);
689 static inline void btrfs_set_header_bytenr(struct btrfs_header *h, u64 bytenr)
691 h->bytenr = cpu_to_le64(bytenr);
694 static inline u64 btrfs_header_generation(struct btrfs_header *h)
696 return le64_to_cpu(h->generation);
699 static inline void btrfs_set_header_generation(struct btrfs_header *h,
700 u64 val)
702 h->generation = cpu_to_le64(val);
705 static inline u64 btrfs_header_owner(struct btrfs_header *h)
707 return le64_to_cpu(h->owner);
710 static inline void btrfs_set_header_owner(struct btrfs_header *h,
711 u64 val)
713 h->owner = cpu_to_le64(val);
716 static inline u32 btrfs_header_nritems(struct btrfs_header *h)
718 return le32_to_cpu(h->nritems);
721 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u32 val)
723 h->nritems = cpu_to_le32(val);
726 static inline u16 btrfs_header_flags(struct btrfs_header *h)
728 return le16_to_cpu(h->flags);
731 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
733 h->flags = cpu_to_le16(val);
736 static inline int btrfs_header_level(struct btrfs_header *h)
738 return h->level;
741 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
743 BUG_ON(level > BTRFS_MAX_LEVEL);
744 h->level = level;
747 static inline int btrfs_is_leaf(struct btrfs_node *n)
749 return (btrfs_header_level(&n->header) == 0);
752 static inline u64 btrfs_root_bytenr(struct btrfs_root_item *item)
754 return le64_to_cpu(item->bytenr);
757 static inline void btrfs_set_root_bytenr(struct btrfs_root_item *item, u64 val)
759 item->bytenr = cpu_to_le64(val);
762 static inline u8 btrfs_root_level(struct btrfs_root_item *item)
764 return item->level;
767 static inline void btrfs_set_root_level(struct btrfs_root_item *item, u8 val)
769 item->level = val;
772 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
774 return le64_to_cpu(item->root_dirid);
777 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
779 item->root_dirid = cpu_to_le64(val);
782 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
784 return le32_to_cpu(item->refs);
787 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
789 item->refs = cpu_to_le32(val);
792 static inline u32 btrfs_root_flags(struct btrfs_root_item *item)
794 return le32_to_cpu(item->flags);
797 static inline void btrfs_set_root_flags(struct btrfs_root_item *item, u32 val)
799 item->flags = cpu_to_le32(val);
802 static inline void btrfs_set_root_bytes_used(struct btrfs_root_item *item,
803 u64 val)
805 item->bytes_used = cpu_to_le64(val);
808 static inline u64 btrfs_root_bytes_used(struct btrfs_root_item *item)
810 return le64_to_cpu(item->bytes_used);
813 static inline u64 btrfs_super_bytenr(struct btrfs_super_block *s)
815 return le64_to_cpu(s->bytenr);
818 static inline void btrfs_set_super_bytenr(struct btrfs_super_block *s, u64 val)
820 s->bytenr = cpu_to_le64(val);
823 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
825 return le64_to_cpu(s->generation);
828 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
829 u64 val)
831 s->generation = cpu_to_le64(val);
834 static inline u8 btrfs_super_root_level(struct btrfs_super_block *s)
836 return s->root_level;
839 static inline void btrfs_set_super_root_level(struct btrfs_super_block *s,
840 u8 val)
842 s->root_level = val;
845 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
847 return le64_to_cpu(s->root);
850 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
852 s->root = cpu_to_le64(val);
855 static inline u64 btrfs_super_total_bytes(struct btrfs_super_block *s)
857 return le64_to_cpu(s->total_bytes);
860 static inline void btrfs_set_super_total_bytes(struct btrfs_super_block *s,
861 u64 val)
863 s->total_bytes = cpu_to_le64(val);
866 static inline u64 btrfs_super_bytes_used(struct btrfs_super_block *s)
868 return le64_to_cpu(s->bytes_used);
871 static inline void btrfs_set_super_bytes_used(struct btrfs_super_block *s,
872 u64 val)
874 s->bytes_used = cpu_to_le64(val);
877 static inline u32 btrfs_super_sectorsize(struct btrfs_super_block *s)
879 return le32_to_cpu(s->sectorsize);
882 static inline void btrfs_set_super_sectorsize(struct btrfs_super_block *s,
883 u32 val)
885 s->sectorsize = cpu_to_le32(val);
888 static inline u32 btrfs_super_nodesize(struct btrfs_super_block *s)
890 return le32_to_cpu(s->nodesize);
893 static inline void btrfs_set_super_nodesize(struct btrfs_super_block *s,
894 u32 val)
896 s->nodesize = cpu_to_le32(val);
899 static inline u32 btrfs_super_leafsize(struct btrfs_super_block *s)
901 return le32_to_cpu(s->leafsize);
904 static inline void btrfs_set_super_leafsize(struct btrfs_super_block *s,
905 u32 val)
907 s->leafsize = cpu_to_le32(val);
910 static inline u32 btrfs_super_stripesize(struct btrfs_super_block *s)
912 return le32_to_cpu(s->stripesize);
915 static inline void btrfs_set_super_stripesize(struct btrfs_super_block *s,
916 u32 val)
918 s->stripesize = cpu_to_le32(val);
921 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
923 return le64_to_cpu(s->root_dir_objectid);
926 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
927 val)
929 s->root_dir_objectid = cpu_to_le64(val);
932 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
934 return (u8 *)l->items;
937 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
939 return e->type;
941 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
942 u8 val)
944 e->type = val;
947 static inline char *btrfs_file_extent_inline_start(struct
948 btrfs_file_extent_item *e)
950 return (char *)(&e->disk_bytenr);
953 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
955 return (unsigned long)(&((struct
956 btrfs_file_extent_item *)NULL)->disk_bytenr) + datasize;
959 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
961 struct btrfs_file_extent_item *fe = NULL;
962 return btrfs_item_size(e) - (unsigned long)(&fe->disk_bytenr);
965 static inline u64 btrfs_file_extent_disk_bytenr(struct btrfs_file_extent_item
968 return le64_to_cpu(e->disk_bytenr);
971 static inline void btrfs_set_file_extent_disk_bytenr(struct
972 btrfs_file_extent_item
973 *e, u64 val)
975 e->disk_bytenr = cpu_to_le64(val);
978 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
980 return le64_to_cpu(e->generation);
983 static inline void btrfs_set_file_extent_generation(struct
984 btrfs_file_extent_item *e,
985 u64 val)
987 e->generation = cpu_to_le64(val);
990 static inline u64 btrfs_file_extent_disk_num_bytes(struct
991 btrfs_file_extent_item *e)
993 return le64_to_cpu(e->disk_num_bytes);
996 static inline void btrfs_set_file_extent_disk_num_bytes(struct
997 btrfs_file_extent_item
998 *e, u64 val)
1000 e->disk_num_bytes = cpu_to_le64(val);
1003 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
1005 return le64_to_cpu(e->offset);
1008 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
1009 *e, u64 val)
1011 e->offset = cpu_to_le64(val);
1014 static inline u64 btrfs_file_extent_num_bytes(struct btrfs_file_extent_item
1017 return le64_to_cpu(e->num_bytes);
1020 static inline void btrfs_set_file_extent_num_bytes(struct
1021 btrfs_file_extent_item *e,
1022 u64 val)
1024 e->num_bytes = cpu_to_le64(val);
1027 /* helper function to cast into the data area of the leaf. */
1028 #define btrfs_item_ptr(leaf, slot, type) \
1029 ((type *)(btrfs_leaf_data(leaf) + \
1030 btrfs_item_offset((leaf)->items + (slot))))
1032 static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
1034 if (level == 0)
1035 return root->leafsize;
1036 return root->nodesize;
1038 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1039 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1040 *root, struct btrfs_path *path, u32 data_size);
1041 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1042 struct btrfs_root *root,
1043 u32 blocksize);
1044 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1045 struct btrfs_buffer *buf);
1046 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1047 *root, u64 bytenr, u64 num_bytes, int pin);
1048 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1049 *root, struct btrfs_key *key, struct btrfs_path *p, int
1050 ins_len, int cow);
1051 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1052 void btrfs_init_path(struct btrfs_path *p);
1053 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1054 struct btrfs_path *path);
1055 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1056 *root, struct btrfs_key *key, void *data, u32 data_size);
1057 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1058 *root, struct btrfs_path *path, struct btrfs_key
1059 *cpu_key, u32 data_size);
1060 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1061 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
1062 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1063 *root, struct btrfs_buffer *snap);
1064 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1065 btrfs_root *root);
1066 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1067 struct btrfs_key *key);
1068 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1069 *root, struct btrfs_key *key, struct btrfs_root_item
1070 *item);
1071 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1072 *root, struct btrfs_key *key, struct btrfs_root_item
1073 *item);
1074 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1075 btrfs_root_item *item, struct btrfs_key *key);
1076 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1077 *root, char *name, int name_len, u64 dir,
1078 struct btrfs_key *location, u8 type);
1079 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1080 *root, struct btrfs_path *path, u64 dir, char *name,
1081 int name_len, int mod);
1082 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
1083 char *name, int name_len);
1084 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1085 struct btrfs_root *fs_root,
1086 u64 dirid, u64 *objectid);
1087 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1088 *root, u64 objectid, struct btrfs_inode_item
1089 *inode_item);
1090 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1091 *root, struct btrfs_path *path, u64 objectid, int mod);
1092 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1093 struct btrfs_root *root);
1094 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1095 int btrfs_read_block_groups(struct btrfs_root *root);
1096 int btrfs_insert_block_group(struct btrfs_trans_handle *trans,
1097 struct btrfs_root *root,
1098 struct btrfs_key *key,
1099 struct btrfs_block_group_item *bi);
1100 #endif