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;
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
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_MAX 8
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_disk_key) + sizeof(u64)))
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))
107 * the super block basically lists the main trees of the FS
108 * it currently lacks any block count etc etc
110 struct btrfs_super_block {
111 u8 csum[BTRFS_CSUM_SIZE];
112 /* the first 3 fields must match struct btrfs_header */
113 u8 fsid[16]; /* FS specific uuid */
114 __le64 bytenr; /* this block number */
120 __le64 root_dir_objectid;
125 } __attribute__ ((__packed__));
128 * A leaf is full of items. offset and size tell us where to find
129 * the item in the leaf (relative to the start of the data area)
132 struct btrfs_disk_key key;
135 } __attribute__ ((__packed__));
138 * leaves have an item area and a data area:
139 * [item0, item1....itemN] [free space] [dataN...data1, data0]
141 * The data is separate from the items to get the keys closer together
145 struct btrfs_header header;
146 struct btrfs_item items[];
147 } __attribute__ ((__packed__));
150 * all non-leaf blocks are nodes, they hold only keys and pointers to
153 struct btrfs_key_ptr {
154 struct btrfs_disk_key key;
156 } __attribute__ ((__packed__));
159 struct btrfs_header header;
160 struct btrfs_key_ptr ptrs[];
161 } __attribute__ ((__packed__));
164 * btrfs_paths remember the path taken from the root down to the leaf.
165 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
166 * to any other levels that are present.
168 * The slots array records the index of the item or block pointer
169 * used while walking the tree.
172 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
173 int slots[BTRFS_MAX_LEVEL];
177 * items in the extent btree are used to record the objectid of the
178 * owner of the block and the number of references
180 struct btrfs_extent_item {
183 } __attribute__ ((__packed__));
185 struct btrfs_inode_timespec {
188 } __attribute__ ((__packed__));
191 * there is no padding here on purpose. If you want to extent the inode,
192 * make a new item type
194 struct btrfs_inode_item {
206 struct btrfs_inode_timespec atime;
207 struct btrfs_inode_timespec ctime;
208 struct btrfs_inode_timespec mtime;
209 struct btrfs_inode_timespec otime;
210 } __attribute__ ((__packed__));
212 /* inline data is just a blob of bytes */
213 struct btrfs_inline_data_item {
215 } __attribute__ ((__packed__));
217 struct btrfs_dir_item {
218 struct btrfs_disk_key location;
222 } __attribute__ ((__packed__));
224 struct btrfs_root_item {
225 struct btrfs_inode_item inode;
232 struct btrfs_disk_key drop_progress;
235 } __attribute__ ((__packed__));
237 #define BTRFS_FILE_EXTENT_REG 0
238 #define BTRFS_FILE_EXTENT_INLINE 1
240 struct btrfs_file_extent_item {
244 * disk space consumed by the extent, checksum blocks are included
248 __le64 disk_num_bytes;
250 * the logical offset in file blocks (no csums)
251 * this extent record is for. This allows a file extent to point
252 * into the middle of an existing extent on disk, sharing it
253 * between two snapshots (useful if some bytes in the middle of the
254 * extent have changed
258 * the logical number of file blocks (no csums included)
261 } __attribute__ ((__packed__));
263 struct btrfs_csum_item {
264 u8 csum[BTRFS_CSUM_SIZE];
265 } __attribute__ ((__packed__));
267 /* tag for the radix tree of block groups in ram */
268 #define BTRFS_BLOCK_GROUP_DIRTY 0
269 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
272 #define BTRFS_BLOCK_GROUP_DATA 1
273 struct btrfs_block_group_item {
276 } __attribute__ ((__packed__));
278 struct btrfs_block_group_cache {
279 struct cache_extent cache;
280 struct btrfs_key key;
281 struct btrfs_block_group_item item;
285 struct btrfs_fs_info {
286 struct btrfs_root *fs_root;
287 struct btrfs_root *extent_root;
288 struct btrfs_root *tree_root;
289 struct btrfs_key last_insert;
290 struct cache_tree extent_cache;
291 struct cache_tree block_group_cache;
292 struct cache_tree pending_tree;
293 struct cache_tree pinned_tree;
294 struct cache_tree del_pending;
295 struct list_head trans;
296 struct list_head cache;
297 u64 last_inode_alloc;
298 u64 last_inode_alloc_dirid;
302 struct btrfs_trans_handle *running_transaction;
303 struct btrfs_super_block *disk_super;
307 * in ram representation of the tree. extent_root is used for all allocations
308 * and for the extent tree extent_root root.
311 struct btrfs_buffer *node;
312 struct btrfs_buffer *commit_root;
313 struct btrfs_root_item root_item;
314 struct btrfs_key root_key;
315 struct btrfs_fs_info *fs_info;
317 /* data allocations are done in sectorsize units */
320 /* node allocations are done in nodesize units */
323 /* leaf allocations are done in leafsize units */
330 /* the lower bits in the key flags defines the item type */
331 #define BTRFS_KEY_TYPE_MAX 256
332 #define BTRFS_KEY_TYPE_SHIFT 24
333 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
334 BTRFS_KEY_TYPE_SHIFT)
337 * inode items have the data typically returned from stat and store other
338 * info about object characteristics. There is one for every file and dir in
341 #define BTRFS_INODE_ITEM_KEY 1
343 /* reserve 2-15 close to the inode for later flexibility */
346 * dir items are the name -> inode pointers in a directory. There is one
347 * for every name in a directory.
349 #define BTRFS_DIR_ITEM_KEY 16
350 #define BTRFS_DIR_INDEX_KEY 17
352 * extent data is for file data
354 #define BTRFS_EXTENT_DATA_KEY 18
356 * csum items have the checksums for data in the extents
358 #define BTRFS_CSUM_ITEM_KEY 19
360 /* reserve 20-31 for other file stuff */
363 * root items point to tree roots. There are typically in the root
364 * tree used by the super block to find all the other trees
366 #define BTRFS_ROOT_ITEM_KEY 32
368 * extent items are in the extent map tree. These record which blocks
369 * are used, and how many references there are to each block
371 #define BTRFS_EXTENT_ITEM_KEY 33
374 * block groups give us hints into the extent allocation trees. Which
375 * blocks are free etc etc
377 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
380 * string items are for debugging. They just store a short string of
383 #define BTRFS_STRING_ITEM_KEY 253
386 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
388 return le64_to_cpu(bi->used);
391 static inline void btrfs_set_block_group_used(struct
392 btrfs_block_group_item *bi,
395 bi->used = cpu_to_le64(val);
398 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
400 return le64_to_cpu(i->generation);
403 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
406 i->generation = cpu_to_le64(val);
409 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
411 return le64_to_cpu(i->size);
414 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
416 i->size = cpu_to_le64(val);
419 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
421 return le64_to_cpu(i->nblocks);
424 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
426 i->nblocks = cpu_to_le64(val);
429 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
431 return le64_to_cpu(i->block_group);
434 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
437 i->block_group = cpu_to_le64(val);
440 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
442 return le32_to_cpu(i->nlink);
445 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
447 i->nlink = cpu_to_le32(val);
450 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
452 return le32_to_cpu(i->uid);
455 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
457 i->uid = cpu_to_le32(val);
460 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
462 return le32_to_cpu(i->gid);
465 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
467 i->gid = cpu_to_le32(val);
470 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
472 return le32_to_cpu(i->mode);
475 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
477 i->mode = cpu_to_le32(val);
480 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
482 return le32_to_cpu(i->rdev);
485 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
487 i->rdev = cpu_to_le32(val);
490 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
492 return le16_to_cpu(i->flags);
495 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
497 i->flags = cpu_to_le16(val);
500 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
502 return le16_to_cpu(i->compat_flags);
505 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
508 i->compat_flags = cpu_to_le16(val);
511 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
513 return le64_to_cpu(ts->sec);
516 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
519 ts->sec = cpu_to_le64(val);
522 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
524 return le32_to_cpu(ts->nsec);
527 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
530 ts->nsec = cpu_to_le32(val);
533 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
535 return le32_to_cpu(ei->refs);
538 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
540 ei->refs = cpu_to_le32(val);
543 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
545 return le64_to_cpu(ei->owner);
548 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
550 ei->owner = cpu_to_le64(val);
553 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
555 return le64_to_cpu(n->ptrs[nr].blockptr);
559 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
562 n->ptrs[nr].blockptr = cpu_to_le64(val);
565 static inline u32 btrfs_item_offset(struct btrfs_item *item)
567 return le32_to_cpu(item->offset);
570 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
572 item->offset = cpu_to_le32(val);
575 static inline u32 btrfs_item_end(struct btrfs_item *item)
577 return le32_to_cpu(item->offset) + le32_to_cpu(item->size);
580 static inline u32 btrfs_item_size(struct btrfs_item *item)
582 return le32_to_cpu(item->size);
585 static inline void btrfs_set_item_size(struct btrfs_item *item, u32 val)
587 item->size = cpu_to_le32(val);
590 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
592 return le16_to_cpu(d->flags);
595 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
597 d->flags = cpu_to_le16(val);
600 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
605 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
610 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
612 return le16_to_cpu(d->name_len);
615 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
617 d->name_len = cpu_to_le16(val);
620 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
621 struct btrfs_disk_key *disk)
623 cpu->offset = le64_to_cpu(disk->offset);
624 cpu->type = le32_to_cpu(disk->type);
625 cpu->objectid = le64_to_cpu(disk->objectid);
628 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
629 struct btrfs_key *cpu)
631 disk->offset = cpu_to_le64(cpu->offset);
632 disk->type = cpu_to_le32(cpu->type);
633 disk->objectid = cpu_to_le64(cpu->objectid);
636 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
638 return le64_to_cpu(disk->objectid);
641 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
644 disk->objectid = cpu_to_le64(val);
647 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
649 return le64_to_cpu(disk->offset);
652 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
655 disk->offset = cpu_to_le64(val);
658 static inline u8 btrfs_disk_key_type(struct btrfs_disk_key *key)
663 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u8 val)
668 static inline u32 btrfs_key_type(struct btrfs_key *key)
673 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
678 static inline u64 btrfs_header_bytenr(struct btrfs_header *h)
680 return le64_to_cpu(h->bytenr);
683 static inline void btrfs_set_header_bytenr(struct btrfs_header *h, u64 bytenr)
685 h->bytenr = cpu_to_le64(bytenr);
688 static inline u64 btrfs_header_generation(struct btrfs_header *h)
690 return le64_to_cpu(h->generation);
693 static inline void btrfs_set_header_generation(struct btrfs_header *h,
696 h->generation = cpu_to_le64(val);
699 static inline u64 btrfs_header_owner(struct btrfs_header *h)
701 return le64_to_cpu(h->owner);
704 static inline void btrfs_set_header_owner(struct btrfs_header *h,
707 h->owner = cpu_to_le64(val);
710 static inline u32 btrfs_header_nritems(struct btrfs_header *h)
712 return le32_to_cpu(h->nritems);
715 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u32 val)
717 h->nritems = cpu_to_le32(val);
720 static inline u16 btrfs_header_flags(struct btrfs_header *h)
722 return le16_to_cpu(h->flags);
725 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
727 h->flags = cpu_to_le16(val);
730 static inline int btrfs_header_level(struct btrfs_header *h)
735 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
737 BUG_ON(level > BTRFS_MAX_LEVEL);
741 static inline int btrfs_is_leaf(struct btrfs_node *n)
743 return (btrfs_header_level(&n->header) == 0);
746 static inline u64 btrfs_root_bytenr(struct btrfs_root_item *item)
748 return le64_to_cpu(item->bytenr);
751 static inline void btrfs_set_root_bytenr(struct btrfs_root_item *item, u64 val)
753 item->bytenr = cpu_to_le64(val);
756 static inline u8 btrfs_root_level(struct btrfs_root_item *item)
761 static inline void btrfs_set_root_level(struct btrfs_root_item *item, u8 val)
766 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
768 return le64_to_cpu(item->root_dirid);
771 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
773 item->root_dirid = cpu_to_le64(val);
776 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
778 return le32_to_cpu(item->refs);
781 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
783 item->refs = cpu_to_le32(val);
786 static inline u32 btrfs_root_flags(struct btrfs_root_item *item)
788 return le32_to_cpu(item->flags);
791 static inline void btrfs_set_root_flags(struct btrfs_root_item *item, u32 val)
793 item->flags = cpu_to_le32(val);
796 static inline void btrfs_set_root_bytes_used(struct btrfs_root_item *item,
799 item->bytes_used = cpu_to_le64(val);
802 static inline u64 btrfs_root_bytes_used(struct btrfs_root_item *item)
804 return le64_to_cpu(item->bytes_used);
807 static inline u64 btrfs_super_bytenr(struct btrfs_super_block *s)
809 return le64_to_cpu(s->bytenr);
812 static inline void btrfs_set_super_bytenr(struct btrfs_super_block *s, u64 val)
814 s->bytenr = cpu_to_le64(val);
817 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
819 return le64_to_cpu(s->generation);
822 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
825 s->generation = cpu_to_le64(val);
828 static inline u8 btrfs_super_root_level(struct btrfs_super_block *s)
830 return s->root_level;
833 static inline void btrfs_set_super_root_level(struct btrfs_super_block *s,
839 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
841 return le64_to_cpu(s->root);
844 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
846 s->root = cpu_to_le64(val);
849 static inline u64 btrfs_super_total_bytes(struct btrfs_super_block *s)
851 return le64_to_cpu(s->total_bytes);
854 static inline void btrfs_set_super_total_bytes(struct btrfs_super_block *s,
857 s->total_bytes = cpu_to_le64(val);
860 static inline u64 btrfs_super_bytes_used(struct btrfs_super_block *s)
862 return le64_to_cpu(s->bytes_used);
865 static inline void btrfs_set_super_bytes_used(struct btrfs_super_block *s,
868 s->bytes_used = cpu_to_le64(val);
871 static inline u32 btrfs_super_sectorsize(struct btrfs_super_block *s)
873 return le32_to_cpu(s->sectorsize);
876 static inline void btrfs_set_super_sectorsize(struct btrfs_super_block *s,
879 s->sectorsize = cpu_to_le32(val);
882 static inline u32 btrfs_super_nodesize(struct btrfs_super_block *s)
884 return le32_to_cpu(s->nodesize);
887 static inline void btrfs_set_super_nodesize(struct btrfs_super_block *s,
890 s->nodesize = cpu_to_le32(val);
893 static inline u32 btrfs_super_leafsize(struct btrfs_super_block *s)
895 return le32_to_cpu(s->leafsize);
898 static inline void btrfs_set_super_leafsize(struct btrfs_super_block *s,
901 s->leafsize = cpu_to_le32(val);
904 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
906 return le64_to_cpu(s->root_dir_objectid);
909 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
912 s->root_dir_objectid = cpu_to_le64(val);
915 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
917 return (u8 *)l->items;
920 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
924 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
930 static inline char *btrfs_file_extent_inline_start(struct
931 btrfs_file_extent_item *e)
933 return (char *)(&e->disk_bytenr);
936 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
938 return (unsigned long)(&((struct
939 btrfs_file_extent_item *)NULL)->disk_bytenr) + datasize;
942 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
944 struct btrfs_file_extent_item *fe = NULL;
945 return btrfs_item_size(e) - (unsigned long)(&fe->disk_bytenr);
948 static inline u64 btrfs_file_extent_disk_bytenr(struct btrfs_file_extent_item
951 return le64_to_cpu(e->disk_bytenr);
954 static inline void btrfs_set_file_extent_disk_bytenr(struct
955 btrfs_file_extent_item
958 e->disk_bytenr = cpu_to_le64(val);
961 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
963 return le64_to_cpu(e->generation);
966 static inline void btrfs_set_file_extent_generation(struct
967 btrfs_file_extent_item *e,
970 e->generation = cpu_to_le64(val);
973 static inline u64 btrfs_file_extent_disk_num_bytes(struct
974 btrfs_file_extent_item *e)
976 return le64_to_cpu(e->disk_num_bytes);
979 static inline void btrfs_set_file_extent_disk_num_bytes(struct
980 btrfs_file_extent_item
983 e->disk_num_bytes = cpu_to_le64(val);
986 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
988 return le64_to_cpu(e->offset);
991 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
994 e->offset = cpu_to_le64(val);
997 static inline u64 btrfs_file_extent_num_bytes(struct btrfs_file_extent_item
1000 return le64_to_cpu(e->num_bytes);
1003 static inline void btrfs_set_file_extent_num_bytes(struct
1004 btrfs_file_extent_item *e,
1007 e->num_bytes = cpu_to_le64(val);
1010 /* helper function to cast into the data area of the leaf. */
1011 #define btrfs_item_ptr(leaf, slot, type) \
1012 ((type *)(btrfs_leaf_data(leaf) + \
1013 btrfs_item_offset((leaf)->items + (slot))))
1015 static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
1018 return root->leafsize;
1019 return root->nodesize;
1021 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1022 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1023 *root, struct btrfs_path *path, u32 data_size);
1024 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1025 struct btrfs_root *root,
1027 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1028 struct btrfs_buffer *buf);
1029 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1030 *root, u64 bytenr, u64 num_bytes, int pin);
1031 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1032 *root, struct btrfs_key *key, struct btrfs_path *p, int
1034 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1035 void btrfs_init_path(struct btrfs_path *p);
1036 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1037 struct btrfs_path *path);
1038 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1039 *root, struct btrfs_key *key, void *data, u32 data_size);
1040 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1041 *root, struct btrfs_path *path, struct btrfs_key
1042 *cpu_key, u32 data_size);
1043 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1044 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
1045 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1046 *root, struct btrfs_buffer *snap);
1047 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1049 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1050 struct btrfs_key *key);
1051 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1052 *root, struct btrfs_key *key, struct btrfs_root_item
1054 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1055 *root, struct btrfs_key *key, struct btrfs_root_item
1057 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1058 btrfs_root_item *item, struct btrfs_key *key);
1059 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1060 *root, char *name, int name_len, u64 dir,
1061 struct btrfs_key *location, u8 type);
1062 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1063 *root, struct btrfs_path *path, u64 dir, char *name,
1064 int name_len, int mod);
1065 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
1066 char *name, int name_len);
1067 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1068 struct btrfs_root *fs_root,
1069 u64 dirid, u64 *objectid);
1070 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1071 *root, u64 objectid, struct btrfs_inode_item
1073 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1074 *root, struct btrfs_path *path, u64 objectid, int mod);
1075 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1076 struct btrfs_root *root);
1077 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1078 int btrfs_read_block_groups(struct btrfs_root *root);
1079 int btrfs_insert_block_group(struct btrfs_trans_handle *trans,
1080 struct btrfs_root *root,
1081 struct btrfs_key *key,
1082 struct btrfs_block_group_item *bi);