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 {
187 } __attribute__ ((__packed__));
189 struct btrfs_inode_timespec {
192 } __attribute__ ((__packed__));
195 * there is no padding here on purpose. If you want to extent the inode,
196 * make a new item type
198 struct btrfs_inode_item {
210 struct btrfs_inode_timespec atime;
211 struct btrfs_inode_timespec ctime;
212 struct btrfs_inode_timespec mtime;
213 struct btrfs_inode_timespec otime;
214 } __attribute__ ((__packed__));
216 /* inline data is just a blob of bytes */
217 struct btrfs_inline_data_item {
219 } __attribute__ ((__packed__));
221 struct btrfs_dir_item {
222 struct btrfs_disk_key location;
226 } __attribute__ ((__packed__));
228 struct btrfs_root_item {
229 struct btrfs_inode_item inode;
236 struct btrfs_disk_key drop_progress;
239 } __attribute__ ((__packed__));
241 #define BTRFS_FILE_EXTENT_REG 0
242 #define BTRFS_FILE_EXTENT_INLINE 1
244 struct btrfs_file_extent_item {
248 * disk space consumed by the extent, checksum blocks are included
252 __le64 disk_num_bytes;
254 * the logical offset in file blocks (no csums)
255 * this extent record is for. This allows a file extent to point
256 * into the middle of an existing extent on disk, sharing it
257 * between two snapshots (useful if some bytes in the middle of the
258 * extent have changed
262 * the logical number of file blocks (no csums included)
265 } __attribute__ ((__packed__));
267 struct btrfs_csum_item {
268 u8 csum[BTRFS_CSUM_SIZE];
269 } __attribute__ ((__packed__));
271 /* tag for the radix tree of block groups in ram */
272 #define BTRFS_BLOCK_GROUP_DIRTY 0
273 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
276 #define BTRFS_BLOCK_GROUP_DATA 1
277 struct btrfs_block_group_item {
280 } __attribute__ ((__packed__));
282 struct btrfs_block_group_cache {
283 struct cache_extent cache;
284 struct btrfs_key key;
285 struct btrfs_block_group_item item;
289 struct btrfs_fs_info {
290 struct btrfs_root *fs_root;
291 struct btrfs_root *extent_root;
292 struct btrfs_root *tree_root;
293 struct btrfs_key last_insert;
294 struct cache_tree extent_cache;
295 struct cache_tree block_group_cache;
296 struct cache_tree pending_tree;
297 struct cache_tree pinned_tree;
298 struct cache_tree del_pending;
299 struct list_head trans;
300 struct list_head cache;
301 u64 last_inode_alloc;
302 u64 last_inode_alloc_dirid;
306 struct btrfs_trans_handle *running_transaction;
307 struct btrfs_super_block *disk_super;
311 * in ram representation of the tree. extent_root is used for all allocations
312 * and for the extent tree extent_root root.
315 struct btrfs_buffer *node;
316 struct btrfs_buffer *commit_root;
317 struct btrfs_root_item root_item;
318 struct btrfs_key root_key;
319 struct btrfs_fs_info *fs_info;
321 /* data allocations are done in sectorsize units */
324 /* node allocations are done in nodesize units */
327 /* leaf allocations are done in leafsize units */
330 /* leaf allocations are done in leafsize units */
337 /* the lower bits in the key flags defines the item type */
338 #define BTRFS_KEY_TYPE_MAX 256
339 #define BTRFS_KEY_TYPE_SHIFT 24
340 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
341 BTRFS_KEY_TYPE_SHIFT)
344 * inode items have the data typically returned from stat and store other
345 * info about object characteristics. There is one for every file and dir in
348 #define BTRFS_INODE_ITEM_KEY 1
349 #define BTRFS_XATTR_ITEM_KEY 2
351 /* reserve 3-15 close to the inode for later flexibility */
354 * dir items are the name -> inode pointers in a directory. There is one
355 * for every name in a directory.
357 #define BTRFS_DIR_ITEM_KEY 16
358 #define BTRFS_DIR_INDEX_KEY 17
360 * extent data is for file data
362 #define BTRFS_EXTENT_DATA_KEY 18
364 * csum items have the checksums for data in the extents
366 #define BTRFS_CSUM_ITEM_KEY 19
368 /* reserve 20-31 for other file stuff */
371 * root items point to tree roots. There are typically in the root
372 * tree used by the super block to find all the other trees
374 #define BTRFS_ROOT_ITEM_KEY 32
376 * extent items are in the extent map tree. These record which blocks
377 * are used, and how many references there are to each block
379 #define BTRFS_EXTENT_ITEM_KEY 33
382 * block groups give us hints into the extent allocation trees. Which
383 * blocks are free etc etc
385 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
388 * string items are for debugging. They just store a short string of
391 #define BTRFS_STRING_ITEM_KEY 253
394 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
396 return le64_to_cpu(bi->used);
399 static inline void btrfs_set_block_group_used(struct
400 btrfs_block_group_item *bi,
403 bi->used = cpu_to_le64(val);
406 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
408 return le64_to_cpu(i->generation);
411 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
414 i->generation = cpu_to_le64(val);
417 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
419 return le64_to_cpu(i->size);
422 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
424 i->size = cpu_to_le64(val);
427 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
429 return le64_to_cpu(i->nblocks);
432 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
434 i->nblocks = cpu_to_le64(val);
437 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
439 return le64_to_cpu(i->block_group);
442 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
445 i->block_group = cpu_to_le64(val);
448 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
450 return le32_to_cpu(i->nlink);
453 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
455 i->nlink = cpu_to_le32(val);
458 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
460 return le32_to_cpu(i->uid);
463 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
465 i->uid = cpu_to_le32(val);
468 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
470 return le32_to_cpu(i->gid);
473 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
475 i->gid = cpu_to_le32(val);
478 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
480 return le32_to_cpu(i->mode);
483 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
485 i->mode = cpu_to_le32(val);
488 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
490 return le32_to_cpu(i->rdev);
493 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
495 i->rdev = cpu_to_le32(val);
498 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
500 return le16_to_cpu(i->flags);
503 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
505 i->flags = cpu_to_le16(val);
508 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
510 return le16_to_cpu(i->compat_flags);
513 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
516 i->compat_flags = cpu_to_le16(val);
519 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
521 return le64_to_cpu(ts->sec);
524 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
527 ts->sec = cpu_to_le64(val);
530 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
532 return le32_to_cpu(ts->nsec);
535 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
538 ts->nsec = cpu_to_le32(val);
541 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
543 return le32_to_cpu(ei->refs);
546 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
548 ei->refs = cpu_to_le32(val);
551 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
553 return le64_to_cpu(ei->owner);
556 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
558 ei->owner = cpu_to_le64(val);
561 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
563 return le64_to_cpu(n->ptrs[nr].blockptr);
566 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
569 n->ptrs[nr].blockptr = cpu_to_le64(val);
572 static inline u64 btrfs_node_ptr_generation(struct btrfs_node *n, int nr)
574 return le64_to_cpu(n->ptrs[nr].generation);
577 static inline void btrfs_set_node_ptr_generation(struct btrfs_node *n, int nr,
580 n->ptrs[nr].generation = cpu_to_le64(val);
583 static inline u32 btrfs_item_offset(struct btrfs_item *item)
585 return le32_to_cpu(item->offset);
588 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
590 item->offset = cpu_to_le32(val);
593 static inline u32 btrfs_item_end(struct btrfs_item *item)
595 return le32_to_cpu(item->offset) + le32_to_cpu(item->size);
598 static inline u32 btrfs_item_size(struct btrfs_item *item)
600 return le32_to_cpu(item->size);
603 static inline void btrfs_set_item_size(struct btrfs_item *item, u32 val)
605 item->size = cpu_to_le32(val);
608 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
613 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
618 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
620 return le16_to_cpu(d->name_len);
623 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
625 d->name_len = cpu_to_le16(val);
628 static inline u16 btrfs_dir_data_len(struct btrfs_dir_item *d)
630 return le16_to_cpu(d->data_len);
633 static inline void btrfs_set_dir_data_len(struct btrfs_dir_item *d, u16 val)
635 d->data_len = cpu_to_le16(val);
638 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
639 struct btrfs_disk_key *disk)
641 cpu->offset = le64_to_cpu(disk->offset);
642 cpu->type = le32_to_cpu(disk->type);
643 cpu->objectid = le64_to_cpu(disk->objectid);
646 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
647 struct btrfs_key *cpu)
649 disk->offset = cpu_to_le64(cpu->offset);
650 disk->type = cpu_to_le32(cpu->type);
651 disk->objectid = cpu_to_le64(cpu->objectid);
654 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
656 return le64_to_cpu(disk->objectid);
659 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
662 disk->objectid = cpu_to_le64(val);
665 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
667 return le64_to_cpu(disk->offset);
670 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
673 disk->offset = cpu_to_le64(val);
676 static inline u8 btrfs_disk_key_type(struct btrfs_disk_key *key)
681 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u8 val)
686 static inline u32 btrfs_key_type(struct btrfs_key *key)
691 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
696 static inline u64 btrfs_header_bytenr(struct btrfs_header *h)
698 return le64_to_cpu(h->bytenr);
701 static inline void btrfs_set_header_bytenr(struct btrfs_header *h, u64 bytenr)
703 h->bytenr = cpu_to_le64(bytenr);
706 static inline u64 btrfs_header_generation(struct btrfs_header *h)
708 return le64_to_cpu(h->generation);
711 static inline void btrfs_set_header_generation(struct btrfs_header *h,
714 h->generation = cpu_to_le64(val);
717 static inline u64 btrfs_header_owner(struct btrfs_header *h)
719 return le64_to_cpu(h->owner);
722 static inline void btrfs_set_header_owner(struct btrfs_header *h,
725 h->owner = cpu_to_le64(val);
728 static inline u32 btrfs_header_nritems(struct btrfs_header *h)
730 return le32_to_cpu(h->nritems);
733 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u32 val)
735 h->nritems = cpu_to_le32(val);
738 static inline u16 btrfs_header_flags(struct btrfs_header *h)
740 return le16_to_cpu(h->flags);
743 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
745 h->flags = cpu_to_le16(val);
748 static inline int btrfs_header_level(struct btrfs_header *h)
753 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
755 BUG_ON(level > BTRFS_MAX_LEVEL);
759 static inline int btrfs_is_leaf(struct btrfs_node *n)
761 return (btrfs_header_level(&n->header) == 0);
764 static inline u64 btrfs_root_bytenr(struct btrfs_root_item *item)
766 return le64_to_cpu(item->bytenr);
769 static inline void btrfs_set_root_bytenr(struct btrfs_root_item *item, u64 val)
771 item->bytenr = cpu_to_le64(val);
774 static inline u64 btrfs_root_byte_limit(struct btrfs_root_item *item)
776 return le64_to_cpu(item->byte_limit);
779 static inline void btrfs_set_root_byte_limit(struct btrfs_root_item *item,
782 item->byte_limit = cpu_to_le64(val);
785 static inline u8 btrfs_root_level(struct btrfs_root_item *item)
790 static inline void btrfs_set_root_level(struct btrfs_root_item *item, u8 val)
795 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
797 return le64_to_cpu(item->root_dirid);
800 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
802 item->root_dirid = cpu_to_le64(val);
805 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
807 return le32_to_cpu(item->refs);
810 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
812 item->refs = cpu_to_le32(val);
815 static inline u32 btrfs_root_flags(struct btrfs_root_item *item)
817 return le32_to_cpu(item->flags);
820 static inline void btrfs_set_root_flags(struct btrfs_root_item *item, u32 val)
822 item->flags = cpu_to_le32(val);
825 static inline void btrfs_set_root_bytes_used(struct btrfs_root_item *item,
828 item->bytes_used = cpu_to_le64(val);
831 static inline u64 btrfs_root_bytes_used(struct btrfs_root_item *item)
833 return le64_to_cpu(item->bytes_used);
836 static inline u64 btrfs_super_bytenr(struct btrfs_super_block *s)
838 return le64_to_cpu(s->bytenr);
841 static inline void btrfs_set_super_bytenr(struct btrfs_super_block *s, u64 val)
843 s->bytenr = cpu_to_le64(val);
846 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
848 return le64_to_cpu(s->generation);
851 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
854 s->generation = cpu_to_le64(val);
857 static inline u8 btrfs_super_root_level(struct btrfs_super_block *s)
859 return s->root_level;
862 static inline void btrfs_set_super_root_level(struct btrfs_super_block *s,
868 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
870 return le64_to_cpu(s->root);
873 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
875 s->root = cpu_to_le64(val);
878 static inline u64 btrfs_super_total_bytes(struct btrfs_super_block *s)
880 return le64_to_cpu(s->total_bytes);
883 static inline void btrfs_set_super_total_bytes(struct btrfs_super_block *s,
886 s->total_bytes = cpu_to_le64(val);
889 static inline u64 btrfs_super_bytes_used(struct btrfs_super_block *s)
891 return le64_to_cpu(s->bytes_used);
894 static inline void btrfs_set_super_bytes_used(struct btrfs_super_block *s,
897 s->bytes_used = cpu_to_le64(val);
900 static inline u32 btrfs_super_sectorsize(struct btrfs_super_block *s)
902 return le32_to_cpu(s->sectorsize);
905 static inline void btrfs_set_super_sectorsize(struct btrfs_super_block *s,
908 s->sectorsize = cpu_to_le32(val);
911 static inline u32 btrfs_super_nodesize(struct btrfs_super_block *s)
913 return le32_to_cpu(s->nodesize);
916 static inline void btrfs_set_super_nodesize(struct btrfs_super_block *s,
919 s->nodesize = cpu_to_le32(val);
922 static inline u32 btrfs_super_leafsize(struct btrfs_super_block *s)
924 return le32_to_cpu(s->leafsize);
927 static inline void btrfs_set_super_leafsize(struct btrfs_super_block *s,
930 s->leafsize = cpu_to_le32(val);
933 static inline u32 btrfs_super_stripesize(struct btrfs_super_block *s)
935 return le32_to_cpu(s->stripesize);
938 static inline void btrfs_set_super_stripesize(struct btrfs_super_block *s,
941 s->stripesize = cpu_to_le32(val);
944 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
946 return le64_to_cpu(s->root_dir_objectid);
949 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
952 s->root_dir_objectid = cpu_to_le64(val);
955 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
957 return (u8 *)l->items;
960 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
964 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
970 static inline char *btrfs_file_extent_inline_start(struct
971 btrfs_file_extent_item *e)
973 return (char *)(&e->disk_bytenr);
976 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
978 return (unsigned long)(&((struct
979 btrfs_file_extent_item *)NULL)->disk_bytenr) + datasize;
982 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
984 struct btrfs_file_extent_item *fe = NULL;
985 return btrfs_item_size(e) - (unsigned long)(&fe->disk_bytenr);
988 static inline u64 btrfs_file_extent_disk_bytenr(struct btrfs_file_extent_item
991 return le64_to_cpu(e->disk_bytenr);
994 static inline void btrfs_set_file_extent_disk_bytenr(struct
995 btrfs_file_extent_item
998 e->disk_bytenr = cpu_to_le64(val);
1001 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
1003 return le64_to_cpu(e->generation);
1006 static inline void btrfs_set_file_extent_generation(struct
1007 btrfs_file_extent_item *e,
1010 e->generation = cpu_to_le64(val);
1013 static inline u64 btrfs_file_extent_disk_num_bytes(struct
1014 btrfs_file_extent_item *e)
1016 return le64_to_cpu(e->disk_num_bytes);
1019 static inline void btrfs_set_file_extent_disk_num_bytes(struct
1020 btrfs_file_extent_item
1023 e->disk_num_bytes = cpu_to_le64(val);
1026 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
1028 return le64_to_cpu(e->offset);
1031 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
1034 e->offset = cpu_to_le64(val);
1037 static inline u64 btrfs_file_extent_num_bytes(struct btrfs_file_extent_item
1040 return le64_to_cpu(e->num_bytes);
1043 static inline void btrfs_set_file_extent_num_bytes(struct
1044 btrfs_file_extent_item *e,
1047 e->num_bytes = cpu_to_le64(val);
1050 /* helper function to cast into the data area of the leaf. */
1051 #define btrfs_item_ptr(leaf, slot, type) \
1052 ((type *)(btrfs_leaf_data(leaf) + \
1053 btrfs_item_offset((leaf)->items + (slot))))
1054 #define btrfs_item_ptr_offset(leaf, slot) \
1055 ((unsigned long)(btrfs_leaf_data(leaf) + \
1056 btrfs_item_offset_nr(leaf, slot)))
1058 static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
1061 return root->leafsize;
1062 return root->nodesize;
1064 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1065 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1066 struct btrfs_root *root,
1068 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1069 struct btrfs_buffer *buf);
1070 int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1071 struct btrfs_root *root);
1072 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1073 *root, u64 bytenr, u64 num_bytes, int pin);
1074 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1075 struct btrfs_root *root, struct btrfs_buffer *buf,
1076 struct btrfs_buffer *parent, int parent_slot,
1077 struct btrfs_buffer **cow_ret);
1078 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1079 *root, struct btrfs_path *path, u32 data_size);
1080 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1081 struct btrfs_root *root,
1082 struct btrfs_path *path,
1083 u32 new_size, int from_end);
1084 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1085 *root, struct btrfs_key *key, struct btrfs_path *p, int
1087 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1088 void btrfs_init_path(struct btrfs_path *p);
1089 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1090 struct btrfs_path *path);
1091 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1092 *root, struct btrfs_key *key, void *data, u32 data_size);
1093 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1094 *root, struct btrfs_path *path, struct btrfs_key
1095 *cpu_key, u32 data_size);
1096 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1097 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
1098 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1099 *root, struct btrfs_buffer *snap);
1100 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1102 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1103 struct btrfs_key *key);
1104 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1105 *root, struct btrfs_key *key, struct btrfs_root_item
1107 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1108 *root, struct btrfs_key *key, struct btrfs_root_item
1110 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1111 btrfs_root_item *item, struct btrfs_key *key);
1112 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1113 *root, char *name, int name_len, u64 dir,
1114 struct btrfs_key *location, u8 type);
1115 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1116 struct btrfs_root *root, struct btrfs_path *path,
1117 u64 dir, char *name, int name_len, int mod);
1118 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1119 struct btrfs_path *path,
1120 const char *name, int name_len);
1121 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1122 struct btrfs_root *root,
1123 struct btrfs_path *path,
1124 struct btrfs_dir_item *di);
1125 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1126 struct btrfs_root *fs_root,
1127 u64 dirid, u64 *objectid);
1128 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1129 *root, u64 objectid, struct btrfs_inode_item
1131 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1132 *root, struct btrfs_path *path, u64 objectid, int mod);
1133 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1134 struct btrfs_root *root);
1135 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1136 int btrfs_read_block_groups(struct btrfs_root *root);
1137 int btrfs_insert_block_group(struct btrfs_trans_handle *trans,
1138 struct btrfs_root *root,
1139 struct btrfs_key *key,
1140 struct btrfs_block_group_item *bi);
1142 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1143 struct btrfs_root *root,
1144 u64 objectid, u64 pos, u64 offset,
1145 u64 disk_num_bytes, u64 num_bytes);
1146 int btrfs_insert_inline_file_extent(struct btrfs_trans_handle *trans,
1147 struct btrfs_root *root, u64 objectid,
1148 u64 offset, char *buffer, size_t size);
1149 int btrfs_lookup_csum(struct btrfs_trans_handle *trans, struct btrfs_root
1150 *root, struct btrfs_path *path, u64 objectid,
1151 u64 offset, int cow, struct btrfs_csum_item **item_ret);
1152 int btrfs_csum_file_block(struct btrfs_trans_handle *trans, struct btrfs_root
1153 *root, struct btrfs_inode_item *inode,
1154 u64 objectid, u64 offset, char *data, size_t len);