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.
23 #include "kerncompat.h"
24 #include "radix-tree.h"
25 #include "extent-cache.h"
27 struct btrfs_trans_handle;
28 #define BTRFS_MAGIC "_B2RfS_M"
30 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
31 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
32 #define BTRFS_FS_TREE_OBJECTID 3ULL
33 #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
34 #define BTRFS_FIRST_FREE_OBJECTID 5ULL
37 * we can actually store much bigger names, but lets not confuse the rest
40 #define BTRFS_NAME_LEN 255
42 /* 32 bytes in various csum fields */
43 #define BTRFS_CSUM_SIZE 32
44 /* four bytes for CRC32 */
45 #define BTRFS_CRC32_SIZE 4
47 #define BTRFS_FT_UNKNOWN 0
48 #define BTRFS_FT_REG_FILE 1
49 #define BTRFS_FT_DIR 2
50 #define BTRFS_FT_CHRDEV 3
51 #define BTRFS_FT_BLKDEV 4
52 #define BTRFS_FT_FIFO 5
53 #define BTRFS_FT_SOCK 6
54 #define BTRFS_FT_SYMLINK 7
55 #define BTRFS_FT_XATTR 8
56 #define BTRFS_FT_MAX 9
59 * the key defines the order in the tree, and so it also defines (optimal)
60 * block layout. objectid corresonds to the inode number. The flags
61 * tells us things about the object, and is a kind of stream selector.
62 * so for a given inode, keys with flags of 1 might refer to the inode
63 * data, flags of 2 may point to file data in the btree and flags == 3
64 * may point to extents.
66 * offset is the starting byte offset for this key in the stream.
68 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
69 * in cpu native order. Otherwise they are identical and their sizes
70 * should be the same (ie both packed)
72 struct btrfs_disk_key {
76 } __attribute__ ((__packed__));
82 } __attribute__ ((__packed__));
85 * every tree block (leaf or node) starts with this header.
88 u8 csum[BTRFS_CSUM_SIZE];
89 u8 fsid[16]; /* FS specific uuid */
90 __le64 bytenr; /* which block this node is supposed to live in */
96 } __attribute__ ((__packed__));
98 #define BTRFS_MAX_LEVEL 8
99 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
100 sizeof(struct btrfs_header)) / \
101 sizeof(struct btrfs_key_ptr))
102 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
103 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
104 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
105 sizeof(struct btrfs_item) - \
106 sizeof(struct btrfs_file_extent_item))
109 * the super block basically lists the main trees of the FS
110 * it currently lacks any block count etc etc
112 struct btrfs_super_block {
113 u8 csum[BTRFS_CSUM_SIZE];
114 /* the first 3 fields must match struct btrfs_header */
115 u8 fsid[16]; /* FS specific uuid */
116 __le64 bytenr; /* this block number */
122 __le64 root_dir_objectid;
128 } __attribute__ ((__packed__));
131 * A leaf is full of items. offset and size tell us where to find
132 * the item in the leaf (relative to the start of the data area)
135 struct btrfs_disk_key key;
138 } __attribute__ ((__packed__));
141 * leaves have an item area and a data area:
142 * [item0, item1....itemN] [free space] [dataN...data1, data0]
144 * The data is separate from the items to get the keys closer together
148 struct btrfs_header header;
149 struct btrfs_item items[];
150 } __attribute__ ((__packed__));
153 * all non-leaf blocks are nodes, they hold only keys and pointers to
156 struct btrfs_key_ptr {
157 struct btrfs_disk_key key;
160 } __attribute__ ((__packed__));
163 struct btrfs_header header;
164 struct btrfs_key_ptr ptrs[];
165 } __attribute__ ((__packed__));
168 * btrfs_paths remember the path taken from the root down to the leaf.
169 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
170 * to any other levels that are present.
172 * The slots array records the index of the item or block pointer
173 * used while walking the tree.
176 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
177 int slots[BTRFS_MAX_LEVEL];
181 * items in the extent btree are used to record the objectid of the
182 * owner of the block and the number of references
184 struct btrfs_extent_item {
186 } __attribute__ ((__packed__));
188 struct btrfs_extent_ref {
193 } __attribute__ ((__packed__));
195 struct btrfs_inode_ref {
198 } __attribute__ ((__packed__));
200 struct btrfs_inode_timespec {
203 } __attribute__ ((__packed__));
206 * there is no padding here on purpose. If you want to extent the inode,
207 * make a new item type
209 struct btrfs_inode_item {
221 struct btrfs_inode_timespec atime;
222 struct btrfs_inode_timespec ctime;
223 struct btrfs_inode_timespec mtime;
224 struct btrfs_inode_timespec otime;
225 } __attribute__ ((__packed__));
227 /* inline data is just a blob of bytes */
228 struct btrfs_inline_data_item {
230 } __attribute__ ((__packed__));
232 struct btrfs_dir_item {
233 struct btrfs_disk_key location;
237 } __attribute__ ((__packed__));
239 struct btrfs_root_item {
240 struct btrfs_inode_item inode;
247 struct btrfs_disk_key drop_progress;
250 } __attribute__ ((__packed__));
252 #define BTRFS_FILE_EXTENT_REG 0
253 #define BTRFS_FILE_EXTENT_INLINE 1
255 struct btrfs_file_extent_item {
259 * disk space consumed by the extent, checksum blocks are included
263 __le64 disk_num_bytes;
265 * the logical offset in file blocks (no csums)
266 * this extent record is for. This allows a file extent to point
267 * into the middle of an existing extent on disk, sharing it
268 * between two snapshots (useful if some bytes in the middle of the
269 * extent have changed
273 * the logical number of file blocks (no csums included)
276 } __attribute__ ((__packed__));
278 struct btrfs_csum_item {
279 u8 csum[BTRFS_CSUM_SIZE];
280 } __attribute__ ((__packed__));
282 /* tag for the radix tree of block groups in ram */
283 #define BTRFS_BLOCK_GROUP_DIRTY 0
284 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
287 #define BTRFS_BLOCK_GROUP_DATA 1
288 struct btrfs_block_group_item {
291 } __attribute__ ((__packed__));
293 struct btrfs_block_group_cache {
294 struct cache_extent cache;
295 struct btrfs_key key;
296 struct btrfs_block_group_item item;
300 struct btrfs_fs_info {
301 struct btrfs_root *fs_root;
302 struct btrfs_root *extent_root;
303 struct btrfs_root *tree_root;
304 struct btrfs_key last_insert;
305 struct cache_tree extent_cache;
306 struct cache_tree block_group_cache;
307 struct cache_tree pending_tree;
308 struct cache_tree pinned_tree;
309 struct cache_tree del_pending;
310 struct list_head trans;
311 struct list_head cache;
312 u64 last_inode_alloc;
313 u64 last_inode_alloc_dirid;
317 struct btrfs_trans_handle *running_transaction;
318 struct btrfs_super_block *disk_super;
322 * in ram representation of the tree. extent_root is used for all allocations
323 * and for the extent tree extent_root root.
326 struct btrfs_buffer *node;
327 struct btrfs_buffer *commit_root;
328 struct btrfs_root_item root_item;
329 struct btrfs_key root_key;
330 struct btrfs_fs_info *fs_info;
332 /* data allocations are done in sectorsize units */
335 /* node allocations are done in nodesize units */
338 /* leaf allocations are done in leafsize units */
341 /* leaf allocations are done in leafsize units */
348 /* the lower bits in the key flags defines the item type */
349 #define BTRFS_KEY_TYPE_MAX 256
350 #define BTRFS_KEY_TYPE_SHIFT 24
351 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
352 BTRFS_KEY_TYPE_SHIFT)
355 * inode items have the data typically returned from stat and store other
356 * info about object characteristics. There is one for every file and dir in
359 #define BTRFS_INODE_ITEM_KEY 1
360 #define BTRFS_INODE_REF_KEY 2
361 #define BTRFS_XATTR_ITEM_KEY 8
363 /* reserve 3-15 close to the inode for later flexibility */
366 * dir items are the name -> inode pointers in a directory. There is one
367 * for every name in a directory.
369 #define BTRFS_DIR_ITEM_KEY 16
370 #define BTRFS_DIR_INDEX_KEY 17
372 * extent data is for file data
374 #define BTRFS_EXTENT_DATA_KEY 18
376 * csum items have the checksums for data in the extents
378 #define BTRFS_CSUM_ITEM_KEY 19
380 /* reserve 20-31 for other file stuff */
383 * root items point to tree roots. There are typically in the root
384 * tree used by the super block to find all the other trees
386 #define BTRFS_ROOT_ITEM_KEY 32
388 * extent items are in the extent map tree. These record which blocks
389 * are used, and how many references there are to each block
391 #define BTRFS_EXTENT_ITEM_KEY 33
392 #define BTRFS_EXTENT_REF_KEY 34
395 * block groups give us hints into the extent allocation trees. Which
396 * blocks are free etc etc
398 #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
401 * string items are for debugging. They just store a short string of
404 #define BTRFS_STRING_ITEM_KEY 253
406 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
407 static inline u##bits btrfs_##name(type *s) \
409 return le##bits##_to_cpu(s->member); \
411 static inline void btrfs_set_##name(type *s, u##bits val) \
413 s->member = cpu_to_le##bits(val); \
416 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
418 return le64_to_cpu(bi->used);
421 static inline void btrfs_set_block_group_used(struct
422 btrfs_block_group_item *bi,
425 bi->used = cpu_to_le64(val);
428 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
430 return le64_to_cpu(i->generation);
433 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
436 i->generation = cpu_to_le64(val);
439 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
441 return le64_to_cpu(i->size);
444 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
446 i->size = cpu_to_le64(val);
449 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
451 return le64_to_cpu(i->nblocks);
454 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
456 i->nblocks = cpu_to_le64(val);
459 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
461 return le64_to_cpu(i->block_group);
464 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
467 i->block_group = cpu_to_le64(val);
470 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
472 return le32_to_cpu(i->nlink);
475 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
477 i->nlink = cpu_to_le32(val);
480 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
482 return le32_to_cpu(i->uid);
485 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
487 i->uid = cpu_to_le32(val);
490 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
492 return le32_to_cpu(i->gid);
495 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
497 i->gid = cpu_to_le32(val);
500 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
502 return le32_to_cpu(i->mode);
505 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
507 i->mode = cpu_to_le32(val);
510 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
512 return le32_to_cpu(i->rdev);
515 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
517 i->rdev = cpu_to_le32(val);
520 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
522 return le16_to_cpu(i->flags);
525 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
527 i->flags = cpu_to_le16(val);
530 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
532 return le16_to_cpu(i->compat_flags);
535 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
538 i->compat_flags = cpu_to_le16(val);
541 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
543 return le64_to_cpu(ts->sec);
546 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
549 ts->sec = cpu_to_le64(val);
552 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
554 return le32_to_cpu(ts->nsec);
557 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
560 ts->nsec = cpu_to_le32(val);
563 BTRFS_SETGET_STACK_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
565 BTRFS_SETGET_STACK_FUNCS(inode_ref_name_len, struct btrfs_inode_ref,
569 BTRFS_SETGET_STACK_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
570 BTRFS_SETGET_STACK_FUNCS(ref_generation, struct btrfs_extent_ref,
572 BTRFS_SETGET_STACK_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
573 BTRFS_SETGET_STACK_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
575 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
577 return le64_to_cpu(n->ptrs[nr].blockptr);
580 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
583 n->ptrs[nr].blockptr = cpu_to_le64(val);
586 static inline u64 btrfs_node_ptr_generation(struct btrfs_node *n, int nr)
588 return le64_to_cpu(n->ptrs[nr].generation);
591 static inline void btrfs_set_node_ptr_generation(struct btrfs_node *n, int nr,
594 n->ptrs[nr].generation = cpu_to_le64(val);
597 static inline u32 btrfs_item_offset(struct btrfs_item *item)
599 return le32_to_cpu(item->offset);
602 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
604 item->offset = cpu_to_le32(val);
607 static inline u32 btrfs_item_end(struct btrfs_item *item)
609 return le32_to_cpu(item->offset) + le32_to_cpu(item->size);
612 static inline u32 btrfs_item_size(struct btrfs_item *item)
614 return le32_to_cpu(item->size);
617 static inline void btrfs_set_item_size(struct btrfs_item *item, u32 val)
619 item->size = cpu_to_le32(val);
622 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
627 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
632 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
634 return le16_to_cpu(d->name_len);
637 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
639 d->name_len = cpu_to_le16(val);
642 static inline u16 btrfs_dir_data_len(struct btrfs_dir_item *d)
644 return le16_to_cpu(d->data_len);
647 static inline void btrfs_set_dir_data_len(struct btrfs_dir_item *d, u16 val)
649 d->data_len = cpu_to_le16(val);
652 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
653 struct btrfs_disk_key *disk)
655 cpu->offset = le64_to_cpu(disk->offset);
656 cpu->type = le32_to_cpu(disk->type);
657 cpu->objectid = le64_to_cpu(disk->objectid);
660 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
661 struct btrfs_key *cpu)
663 disk->offset = cpu_to_le64(cpu->offset);
664 disk->type = cpu_to_le32(cpu->type);
665 disk->objectid = cpu_to_le64(cpu->objectid);
668 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
670 return le64_to_cpu(disk->objectid);
673 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
676 disk->objectid = cpu_to_le64(val);
679 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
681 return le64_to_cpu(disk->offset);
684 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
687 disk->offset = cpu_to_le64(val);
690 static inline u8 btrfs_disk_key_type(struct btrfs_disk_key *key)
695 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u8 val)
700 static inline u32 btrfs_key_type(struct btrfs_key *key)
705 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
710 static inline u64 btrfs_header_bytenr(struct btrfs_header *h)
712 return le64_to_cpu(h->bytenr);
715 static inline void btrfs_set_header_bytenr(struct btrfs_header *h, u64 bytenr)
717 h->bytenr = cpu_to_le64(bytenr);
720 static inline u64 btrfs_header_generation(struct btrfs_header *h)
722 return le64_to_cpu(h->generation);
725 static inline void btrfs_set_header_generation(struct btrfs_header *h,
728 h->generation = cpu_to_le64(val);
731 static inline u64 btrfs_header_owner(struct btrfs_header *h)
733 return le64_to_cpu(h->owner);
736 static inline void btrfs_set_header_owner(struct btrfs_header *h,
739 h->owner = cpu_to_le64(val);
742 static inline u32 btrfs_header_nritems(struct btrfs_header *h)
744 return le32_to_cpu(h->nritems);
747 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u32 val)
749 h->nritems = cpu_to_le32(val);
752 static inline u16 btrfs_header_flags(struct btrfs_header *h)
754 return le16_to_cpu(h->flags);
757 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
759 h->flags = cpu_to_le16(val);
762 static inline int btrfs_header_level(struct btrfs_header *h)
767 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
769 BUG_ON(level > BTRFS_MAX_LEVEL);
773 static inline int btrfs_is_leaf(struct btrfs_node *n)
775 return (btrfs_header_level(&n->header) == 0);
778 static inline u64 btrfs_root_bytenr(struct btrfs_root_item *item)
780 return le64_to_cpu(item->bytenr);
783 static inline void btrfs_set_root_bytenr(struct btrfs_root_item *item, u64 val)
785 item->bytenr = cpu_to_le64(val);
788 static inline u64 btrfs_root_byte_limit(struct btrfs_root_item *item)
790 return le64_to_cpu(item->byte_limit);
793 static inline void btrfs_set_root_byte_limit(struct btrfs_root_item *item,
796 item->byte_limit = cpu_to_le64(val);
799 static inline u8 btrfs_root_level(struct btrfs_root_item *item)
804 static inline void btrfs_set_root_level(struct btrfs_root_item *item, u8 val)
809 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
811 return le64_to_cpu(item->root_dirid);
814 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
816 item->root_dirid = cpu_to_le64(val);
819 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
821 return le32_to_cpu(item->refs);
824 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
826 item->refs = cpu_to_le32(val);
829 static inline u32 btrfs_root_flags(struct btrfs_root_item *item)
831 return le32_to_cpu(item->flags);
834 static inline void btrfs_set_root_flags(struct btrfs_root_item *item, u32 val)
836 item->flags = cpu_to_le32(val);
839 static inline void btrfs_set_root_bytes_used(struct btrfs_root_item *item,
842 item->bytes_used = cpu_to_le64(val);
845 static inline u64 btrfs_root_bytes_used(struct btrfs_root_item *item)
847 return le64_to_cpu(item->bytes_used);
850 static inline u64 btrfs_super_bytenr(struct btrfs_super_block *s)
852 return le64_to_cpu(s->bytenr);
855 static inline void btrfs_set_super_bytenr(struct btrfs_super_block *s, u64 val)
857 s->bytenr = cpu_to_le64(val);
860 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
862 return le64_to_cpu(s->generation);
865 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
868 s->generation = cpu_to_le64(val);
871 static inline u8 btrfs_super_root_level(struct btrfs_super_block *s)
873 return s->root_level;
876 static inline void btrfs_set_super_root_level(struct btrfs_super_block *s,
882 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
884 return le64_to_cpu(s->root);
887 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
889 s->root = cpu_to_le64(val);
892 static inline u64 btrfs_super_total_bytes(struct btrfs_super_block *s)
894 return le64_to_cpu(s->total_bytes);
897 static inline void btrfs_set_super_total_bytes(struct btrfs_super_block *s,
900 s->total_bytes = cpu_to_le64(val);
903 static inline u64 btrfs_super_bytes_used(struct btrfs_super_block *s)
905 return le64_to_cpu(s->bytes_used);
908 static inline void btrfs_set_super_bytes_used(struct btrfs_super_block *s,
911 s->bytes_used = cpu_to_le64(val);
914 static inline u32 btrfs_super_sectorsize(struct btrfs_super_block *s)
916 return le32_to_cpu(s->sectorsize);
919 static inline void btrfs_set_super_sectorsize(struct btrfs_super_block *s,
922 s->sectorsize = cpu_to_le32(val);
925 static inline u32 btrfs_super_nodesize(struct btrfs_super_block *s)
927 return le32_to_cpu(s->nodesize);
930 static inline void btrfs_set_super_nodesize(struct btrfs_super_block *s,
933 s->nodesize = cpu_to_le32(val);
936 static inline u32 btrfs_super_leafsize(struct btrfs_super_block *s)
938 return le32_to_cpu(s->leafsize);
941 static inline void btrfs_set_super_leafsize(struct btrfs_super_block *s,
944 s->leafsize = cpu_to_le32(val);
947 static inline u32 btrfs_super_stripesize(struct btrfs_super_block *s)
949 return le32_to_cpu(s->stripesize);
952 static inline void btrfs_set_super_stripesize(struct btrfs_super_block *s,
955 s->stripesize = cpu_to_le32(val);
958 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
960 return le64_to_cpu(s->root_dir_objectid);
963 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
966 s->root_dir_objectid = cpu_to_le64(val);
969 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
971 return (u8 *)l->items;
974 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
978 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
984 static inline char *btrfs_file_extent_inline_start(struct
985 btrfs_file_extent_item *e)
987 return (char *)(&e->disk_bytenr);
990 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
992 return (unsigned long)(&((struct
993 btrfs_file_extent_item *)NULL)->disk_bytenr) + datasize;
996 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
998 struct btrfs_file_extent_item *fe = NULL;
999 return btrfs_item_size(e) - (unsigned long)(&fe->disk_bytenr);
1002 static inline u64 btrfs_file_extent_disk_bytenr(struct btrfs_file_extent_item
1005 return le64_to_cpu(e->disk_bytenr);
1008 static inline void btrfs_set_file_extent_disk_bytenr(struct
1009 btrfs_file_extent_item
1012 e->disk_bytenr = cpu_to_le64(val);
1015 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
1017 return le64_to_cpu(e->generation);
1020 static inline void btrfs_set_file_extent_generation(struct
1021 btrfs_file_extent_item *e,
1024 e->generation = cpu_to_le64(val);
1027 static inline u64 btrfs_file_extent_disk_num_bytes(struct
1028 btrfs_file_extent_item *e)
1030 return le64_to_cpu(e->disk_num_bytes);
1033 static inline void btrfs_set_file_extent_disk_num_bytes(struct
1034 btrfs_file_extent_item
1037 e->disk_num_bytes = cpu_to_le64(val);
1040 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
1042 return le64_to_cpu(e->offset);
1045 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
1048 e->offset = cpu_to_le64(val);
1051 static inline u64 btrfs_file_extent_num_bytes(struct btrfs_file_extent_item
1054 return le64_to_cpu(e->num_bytes);
1057 static inline void btrfs_set_file_extent_num_bytes(struct
1058 btrfs_file_extent_item *e,
1061 e->num_bytes = cpu_to_le64(val);
1064 /* helper function to cast into the data area of the leaf. */
1065 #define btrfs_item_ptr(leaf, slot, type) \
1066 ((type *)(btrfs_leaf_data(leaf) + \
1067 btrfs_item_offset((leaf)->items + (slot))))
1068 #define btrfs_item_ptr_offset(leaf, slot) \
1069 ((unsigned long)(btrfs_leaf_data(leaf) + \
1070 btrfs_item_offset_nr(leaf, slot)))
1072 static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
1075 return root->leafsize;
1076 return root->nodesize;
1078 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1079 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1080 struct btrfs_root *root,
1082 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1083 struct btrfs_buffer *buf);
1084 int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1085 struct btrfs_root *root, u64 owner_objectid);
1086 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1087 *root, u64 bytenr, u64 num_bytes,
1088 u64 root_objectid, u64 root_generation,
1089 u64 owner, u64 owner_offset, int pin);
1090 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1091 struct btrfs_root *root, struct btrfs_buffer *buf,
1092 struct btrfs_buffer *parent, int parent_slot,
1093 struct btrfs_buffer **cow_ret);
1094 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1095 *root, struct btrfs_path *path, u32 data_size);
1096 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1097 struct btrfs_root *root,
1098 struct btrfs_path *path,
1099 u32 new_size, int from_end);
1100 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1101 *root, struct btrfs_key *key, struct btrfs_path *p, int
1103 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1104 void btrfs_init_path(struct btrfs_path *p);
1105 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1106 struct btrfs_path *path);
1107 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1108 *root, struct btrfs_key *key, void *data, u32 data_size);
1109 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1110 *root, struct btrfs_path *path, struct btrfs_key
1111 *cpu_key, u32 data_size);
1112 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1113 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
1114 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1115 *root, struct btrfs_buffer *snap);
1116 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1118 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1119 struct btrfs_key *key);
1120 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1121 *root, struct btrfs_key *key, struct btrfs_root_item
1123 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1124 *root, struct btrfs_key *key, struct btrfs_root_item
1126 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1127 btrfs_root_item *item, struct btrfs_key *key);
1128 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1129 *root, char *name, int name_len, u64 dir,
1130 struct btrfs_key *location, u8 type);
1131 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1132 struct btrfs_root *root, struct btrfs_path *path,
1133 u64 dir, char *name, int name_len, int mod);
1134 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1135 struct btrfs_path *path,
1136 const char *name, int name_len);
1137 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1138 struct btrfs_root *root,
1139 struct btrfs_path *path,
1140 struct btrfs_dir_item *di);
1141 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1142 struct btrfs_root *fs_root,
1143 u64 dirid, u64 *objectid);
1144 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1145 *root, u64 objectid, struct btrfs_inode_item
1147 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1148 *root, struct btrfs_path *path, u64 objectid, int mod);
1149 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1150 struct btrfs_root *root);
1151 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1152 int btrfs_read_block_groups(struct btrfs_root *root);
1153 int btrfs_insert_block_group(struct btrfs_trans_handle *trans,
1154 struct btrfs_root *root,
1155 struct btrfs_key *key,
1156 struct btrfs_block_group_item *bi);
1158 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1159 struct btrfs_root *root,
1160 u64 objectid, u64 pos, u64 offset,
1161 u64 disk_num_bytes, u64 num_bytes);
1162 int btrfs_insert_inline_file_extent(struct btrfs_trans_handle *trans,
1163 struct btrfs_root *root, u64 objectid,
1164 u64 offset, char *buffer, size_t size);
1165 int btrfs_lookup_csum(struct btrfs_trans_handle *trans, struct btrfs_root
1166 *root, struct btrfs_path *path, u64 objectid,
1167 u64 offset, int cow, struct btrfs_csum_item **item_ret);
1168 int btrfs_csum_file_block(struct btrfs_trans_handle *trans, struct btrfs_root
1169 *root, struct btrfs_inode_item *inode,
1170 u64 objectid, u64 offset, char *data, size_t len);