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 btrfs_key key
;
280 struct btrfs_block_group_item item
;
283 struct btrfs_fs_info
{
284 struct btrfs_root
*fs_root
;
285 struct btrfs_root
*extent_root
;
286 struct btrfs_root
*tree_root
;
287 struct btrfs_key last_insert
;
288 struct cache_tree extent_cache
;
289 struct radix_tree_root block_group_radix
;
290 struct cache_tree pending_tree
;
291 struct cache_tree pinned_tree
;
292 struct cache_tree del_pending
;
293 struct list_head trans
;
294 struct list_head cache
;
295 u64 last_inode_alloc
;
296 u64 last_inode_alloc_dirid
;
300 struct btrfs_trans_handle
*running_transaction
;
301 struct btrfs_super_block
*disk_super
;
305 * in ram representation of the tree. extent_root is used for all allocations
306 * and for the extent tree extent_root root.
309 struct btrfs_buffer
*node
;
310 struct btrfs_buffer
*commit_root
;
311 struct btrfs_root_item root_item
;
312 struct btrfs_key root_key
;
313 struct btrfs_fs_info
*fs_info
;
315 /* data allocations are done in sectorsize units */
318 /* node allocations are done in nodesize units */
321 /* leaf allocations are done in leafsize units */
328 /* the lower bits in the key flags defines the item type */
329 #define BTRFS_KEY_TYPE_MAX 256
330 #define BTRFS_KEY_TYPE_SHIFT 24
331 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
332 BTRFS_KEY_TYPE_SHIFT)
335 * inode items have the data typically returned from stat and store other
336 * info about object characteristics. There is one for every file and dir in
339 #define BTRFS_INODE_ITEM_KEY 1
341 /* reserve 2-15 close to the inode for later flexibility */
344 * dir items are the name -> inode pointers in a directory. There is one
345 * for every name in a directory.
347 #define BTRFS_DIR_ITEM_KEY 16
348 #define BTRFS_DIR_INDEX_KEY 17
350 * extent data is for file data
352 #define BTRFS_EXTENT_DATA_KEY 18
354 * csum items have the checksums for data in the extents
356 #define BTRFS_CSUM_ITEM_KEY 19
358 /* reserve 20-31 for other file stuff */
361 * root items point to tree roots. There are typically in the root
362 * tree used by the super block to find all the other trees
364 #define BTRFS_ROOT_ITEM_KEY 32
366 * extent items are in the extent map tree. These record which blocks
367 * are used, and how many references there are to each block
369 #define BTRFS_EXTENT_ITEM_KEY 33
372 * block groups give us hints into the extent allocation trees. Which
373 * blocks are free etc etc
375 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
378 * string items are for debugging. They just store a short string of
381 #define BTRFS_STRING_ITEM_KEY 253
384 static inline u64
btrfs_block_group_used(struct btrfs_block_group_item
*bi
)
386 return le64_to_cpu(bi
->used
);
389 static inline void btrfs_set_block_group_used(struct
390 btrfs_block_group_item
*bi
,
393 bi
->used
= cpu_to_le64(val
);
396 static inline u64
btrfs_inode_generation(struct btrfs_inode_item
*i
)
398 return le64_to_cpu(i
->generation
);
401 static inline void btrfs_set_inode_generation(struct btrfs_inode_item
*i
,
404 i
->generation
= cpu_to_le64(val
);
407 static inline u64
btrfs_inode_size(struct btrfs_inode_item
*i
)
409 return le64_to_cpu(i
->size
);
412 static inline void btrfs_set_inode_size(struct btrfs_inode_item
*i
, u64 val
)
414 i
->size
= cpu_to_le64(val
);
417 static inline u64
btrfs_inode_nblocks(struct btrfs_inode_item
*i
)
419 return le64_to_cpu(i
->nblocks
);
422 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item
*i
, u64 val
)
424 i
->nblocks
= cpu_to_le64(val
);
427 static inline u64
btrfs_inode_block_group(struct btrfs_inode_item
*i
)
429 return le64_to_cpu(i
->block_group
);
432 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item
*i
,
435 i
->block_group
= cpu_to_le64(val
);
438 static inline u32
btrfs_inode_nlink(struct btrfs_inode_item
*i
)
440 return le32_to_cpu(i
->nlink
);
443 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item
*i
, u32 val
)
445 i
->nlink
= cpu_to_le32(val
);
448 static inline u32
btrfs_inode_uid(struct btrfs_inode_item
*i
)
450 return le32_to_cpu(i
->uid
);
453 static inline void btrfs_set_inode_uid(struct btrfs_inode_item
*i
, u32 val
)
455 i
->uid
= cpu_to_le32(val
);
458 static inline u32
btrfs_inode_gid(struct btrfs_inode_item
*i
)
460 return le32_to_cpu(i
->gid
);
463 static inline void btrfs_set_inode_gid(struct btrfs_inode_item
*i
, u32 val
)
465 i
->gid
= cpu_to_le32(val
);
468 static inline u32
btrfs_inode_mode(struct btrfs_inode_item
*i
)
470 return le32_to_cpu(i
->mode
);
473 static inline void btrfs_set_inode_mode(struct btrfs_inode_item
*i
, u32 val
)
475 i
->mode
= cpu_to_le32(val
);
478 static inline u32
btrfs_inode_rdev(struct btrfs_inode_item
*i
)
480 return le32_to_cpu(i
->rdev
);
483 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item
*i
, u32 val
)
485 i
->rdev
= cpu_to_le32(val
);
488 static inline u16
btrfs_inode_flags(struct btrfs_inode_item
*i
)
490 return le16_to_cpu(i
->flags
);
493 static inline void btrfs_set_inode_flags(struct btrfs_inode_item
*i
, u16 val
)
495 i
->flags
= cpu_to_le16(val
);
498 static inline u16
btrfs_inode_compat_flags(struct btrfs_inode_item
*i
)
500 return le16_to_cpu(i
->compat_flags
);
503 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item
*i
,
506 i
->compat_flags
= cpu_to_le16(val
);
509 static inline u64
btrfs_timespec_sec(struct btrfs_inode_timespec
*ts
)
511 return le64_to_cpu(ts
->sec
);
514 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec
*ts
,
517 ts
->sec
= cpu_to_le64(val
);
520 static inline u32
btrfs_timespec_nsec(struct btrfs_inode_timespec
*ts
)
522 return le32_to_cpu(ts
->nsec
);
525 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec
*ts
,
528 ts
->nsec
= cpu_to_le32(val
);
531 static inline u32
btrfs_extent_refs(struct btrfs_extent_item
*ei
)
533 return le32_to_cpu(ei
->refs
);
536 static inline void btrfs_set_extent_refs(struct btrfs_extent_item
*ei
, u32 val
)
538 ei
->refs
= cpu_to_le32(val
);
541 static inline u64
btrfs_extent_owner(struct btrfs_extent_item
*ei
)
543 return le64_to_cpu(ei
->owner
);
546 static inline void btrfs_set_extent_owner(struct btrfs_extent_item
*ei
, u64 val
)
548 ei
->owner
= cpu_to_le64(val
);
551 static inline u64
btrfs_node_blockptr(struct btrfs_node
*n
, int nr
)
553 return le64_to_cpu(n
->ptrs
[nr
].blockptr
);
557 static inline void btrfs_set_node_blockptr(struct btrfs_node
*n
, int nr
,
560 n
->ptrs
[nr
].blockptr
= cpu_to_le64(val
);
563 static inline u32
btrfs_item_offset(struct btrfs_item
*item
)
565 return le32_to_cpu(item
->offset
);
568 static inline void btrfs_set_item_offset(struct btrfs_item
*item
, u32 val
)
570 item
->offset
= cpu_to_le32(val
);
573 static inline u32
btrfs_item_end(struct btrfs_item
*item
)
575 return le32_to_cpu(item
->offset
) + le32_to_cpu(item
->size
);
578 static inline u32
btrfs_item_size(struct btrfs_item
*item
)
580 return le32_to_cpu(item
->size
);
583 static inline void btrfs_set_item_size(struct btrfs_item
*item
, u32 val
)
585 item
->size
= cpu_to_le32(val
);
588 static inline u16
btrfs_dir_flags(struct btrfs_dir_item
*d
)
590 return le16_to_cpu(d
->flags
);
593 static inline void btrfs_set_dir_flags(struct btrfs_dir_item
*d
, u16 val
)
595 d
->flags
= cpu_to_le16(val
);
598 static inline u8
btrfs_dir_type(struct btrfs_dir_item
*d
)
603 static inline void btrfs_set_dir_type(struct btrfs_dir_item
*d
, u8 val
)
608 static inline u16
btrfs_dir_name_len(struct btrfs_dir_item
*d
)
610 return le16_to_cpu(d
->name_len
);
613 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item
*d
, u16 val
)
615 d
->name_len
= cpu_to_le16(val
);
618 static inline void btrfs_disk_key_to_cpu(struct btrfs_key
*cpu
,
619 struct btrfs_disk_key
*disk
)
621 cpu
->offset
= le64_to_cpu(disk
->offset
);
622 cpu
->type
= le32_to_cpu(disk
->type
);
623 cpu
->objectid
= le64_to_cpu(disk
->objectid
);
626 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key
*disk
,
627 struct btrfs_key
*cpu
)
629 disk
->offset
= cpu_to_le64(cpu
->offset
);
630 disk
->type
= cpu_to_le32(cpu
->type
);
631 disk
->objectid
= cpu_to_le64(cpu
->objectid
);
634 static inline u64
btrfs_disk_key_objectid(struct btrfs_disk_key
*disk
)
636 return le64_to_cpu(disk
->objectid
);
639 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key
*disk
,
642 disk
->objectid
= cpu_to_le64(val
);
645 static inline u64
btrfs_disk_key_offset(struct btrfs_disk_key
*disk
)
647 return le64_to_cpu(disk
->offset
);
650 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key
*disk
,
653 disk
->offset
= cpu_to_le64(val
);
656 static inline u8
btrfs_disk_key_type(struct btrfs_disk_key
*key
)
661 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key
*key
, u8 val
)
666 static inline u32
btrfs_key_type(struct btrfs_key
*key
)
671 static inline void btrfs_set_key_type(struct btrfs_key
*key
, u32 val
)
676 static inline u64
btrfs_header_bytenr(struct btrfs_header
*h
)
678 return le64_to_cpu(h
->bytenr
);
681 static inline void btrfs_set_header_bytenr(struct btrfs_header
*h
, u64 bytenr
)
683 h
->bytenr
= cpu_to_le64(bytenr
);
686 static inline u64
btrfs_header_generation(struct btrfs_header
*h
)
688 return le64_to_cpu(h
->generation
);
691 static inline void btrfs_set_header_generation(struct btrfs_header
*h
,
694 h
->generation
= cpu_to_le64(val
);
697 static inline u64
btrfs_header_owner(struct btrfs_header
*h
)
699 return le64_to_cpu(h
->owner
);
702 static inline void btrfs_set_header_owner(struct btrfs_header
*h
,
705 h
->owner
= cpu_to_le64(val
);
708 static inline u32
btrfs_header_nritems(struct btrfs_header
*h
)
710 return le32_to_cpu(h
->nritems
);
713 static inline void btrfs_set_header_nritems(struct btrfs_header
*h
, u32 val
)
715 h
->nritems
= cpu_to_le32(val
);
718 static inline u16
btrfs_header_flags(struct btrfs_header
*h
)
720 return le16_to_cpu(h
->flags
);
723 static inline void btrfs_set_header_flags(struct btrfs_header
*h
, u16 val
)
725 h
->flags
= cpu_to_le16(val
);
728 static inline int btrfs_header_level(struct btrfs_header
*h
)
733 static inline void btrfs_set_header_level(struct btrfs_header
*h
, int level
)
735 BUG_ON(level
> BTRFS_MAX_LEVEL
);
739 static inline int btrfs_is_leaf(struct btrfs_node
*n
)
741 return (btrfs_header_level(&n
->header
) == 0);
744 static inline u64
btrfs_root_bytenr(struct btrfs_root_item
*item
)
746 return le64_to_cpu(item
->bytenr
);
749 static inline void btrfs_set_root_bytenr(struct btrfs_root_item
*item
, u64 val
)
751 item
->bytenr
= cpu_to_le64(val
);
754 static inline u8
btrfs_root_level(struct btrfs_root_item
*item
)
759 static inline void btrfs_set_root_level(struct btrfs_root_item
*item
, u8 val
)
764 static inline u64
btrfs_root_dirid(struct btrfs_root_item
*item
)
766 return le64_to_cpu(item
->root_dirid
);
769 static inline void btrfs_set_root_dirid(struct btrfs_root_item
*item
, u64 val
)
771 item
->root_dirid
= cpu_to_le64(val
);
774 static inline u32
btrfs_root_refs(struct btrfs_root_item
*item
)
776 return le32_to_cpu(item
->refs
);
779 static inline void btrfs_set_root_refs(struct btrfs_root_item
*item
, u32 val
)
781 item
->refs
= cpu_to_le32(val
);
784 static inline u32
btrfs_root_flags(struct btrfs_root_item
*item
)
786 return le32_to_cpu(item
->flags
);
789 static inline void btrfs_set_root_flags(struct btrfs_root_item
*item
, u32 val
)
791 item
->flags
= cpu_to_le32(val
);
794 static inline void btrfs_set_root_bytes_used(struct btrfs_root_item
*item
,
797 item
->bytes_used
= cpu_to_le64(val
);
800 static inline u64
btrfs_root_bytes_used(struct btrfs_root_item
*item
)
802 return le64_to_cpu(item
->bytes_used
);
805 static inline u64
btrfs_super_bytenr(struct btrfs_super_block
*s
)
807 return le64_to_cpu(s
->bytenr
);
810 static inline void btrfs_set_super_bytenr(struct btrfs_super_block
*s
, u64 val
)
812 s
->bytenr
= cpu_to_le64(val
);
815 static inline u64
btrfs_super_generation(struct btrfs_super_block
*s
)
817 return le64_to_cpu(s
->generation
);
820 static inline void btrfs_set_super_generation(struct btrfs_super_block
*s
,
823 s
->generation
= cpu_to_le64(val
);
826 static inline u8
btrfs_super_root_level(struct btrfs_super_block
*s
)
828 return s
->root_level
;
831 static inline void btrfs_set_super_root_level(struct btrfs_super_block
*s
,
837 static inline u64
btrfs_super_root(struct btrfs_super_block
*s
)
839 return le64_to_cpu(s
->root
);
842 static inline void btrfs_set_super_root(struct btrfs_super_block
*s
, u64 val
)
844 s
->root
= cpu_to_le64(val
);
847 static inline u64
btrfs_super_total_bytes(struct btrfs_super_block
*s
)
849 return le64_to_cpu(s
->total_bytes
);
852 static inline void btrfs_set_super_total_bytes(struct btrfs_super_block
*s
,
855 s
->total_bytes
= cpu_to_le64(val
);
858 static inline u64
btrfs_super_bytes_used(struct btrfs_super_block
*s
)
860 return le64_to_cpu(s
->bytes_used
);
863 static inline void btrfs_set_super_bytes_used(struct btrfs_super_block
*s
,
866 s
->bytes_used
= cpu_to_le64(val
);
869 static inline u32
btrfs_super_sectorsize(struct btrfs_super_block
*s
)
871 return le32_to_cpu(s
->sectorsize
);
874 static inline void btrfs_set_super_sectorsize(struct btrfs_super_block
*s
,
877 s
->sectorsize
= cpu_to_le32(val
);
880 static inline u32
btrfs_super_nodesize(struct btrfs_super_block
*s
)
882 return le32_to_cpu(s
->nodesize
);
885 static inline void btrfs_set_super_nodesize(struct btrfs_super_block
*s
,
888 s
->nodesize
= cpu_to_le32(val
);
891 static inline u32
btrfs_super_leafsize(struct btrfs_super_block
*s
)
893 return le32_to_cpu(s
->leafsize
);
896 static inline void btrfs_set_super_leafsize(struct btrfs_super_block
*s
,
899 s
->leafsize
= cpu_to_le32(val
);
902 static inline u64
btrfs_super_root_dir(struct btrfs_super_block
*s
)
904 return le64_to_cpu(s
->root_dir_objectid
);
907 static inline void btrfs_set_super_root_dir(struct btrfs_super_block
*s
, u64
910 s
->root_dir_objectid
= cpu_to_le64(val
);
913 static inline u8
*btrfs_leaf_data(struct btrfs_leaf
*l
)
915 return (u8
*)l
->items
;
918 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item
*e
)
922 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item
*e
,
928 static inline char *btrfs_file_extent_inline_start(struct
929 btrfs_file_extent_item
*e
)
931 return (char *)(&e
->disk_bytenr
);
934 static inline u32
btrfs_file_extent_calc_inline_size(u32 datasize
)
936 return (unsigned long)(&((struct
937 btrfs_file_extent_item
*)NULL
)->disk_bytenr
) + datasize
;
940 static inline u32
btrfs_file_extent_inline_len(struct btrfs_item
*e
)
942 struct btrfs_file_extent_item
*fe
= NULL
;
943 return btrfs_item_size(e
) - (unsigned long)(&fe
->disk_bytenr
);
946 static inline u64
btrfs_file_extent_disk_bytenr(struct btrfs_file_extent_item
949 return le64_to_cpu(e
->disk_bytenr
);
952 static inline void btrfs_set_file_extent_disk_bytenr(struct
953 btrfs_file_extent_item
956 e
->disk_bytenr
= cpu_to_le64(val
);
959 static inline u64
btrfs_file_extent_generation(struct btrfs_file_extent_item
*e
)
961 return le64_to_cpu(e
->generation
);
964 static inline void btrfs_set_file_extent_generation(struct
965 btrfs_file_extent_item
*e
,
968 e
->generation
= cpu_to_le64(val
);
971 static inline u64
btrfs_file_extent_disk_num_bytes(struct
972 btrfs_file_extent_item
*e
)
974 return le64_to_cpu(e
->disk_num_bytes
);
977 static inline void btrfs_set_file_extent_disk_num_bytes(struct
978 btrfs_file_extent_item
981 e
->disk_num_bytes
= cpu_to_le64(val
);
984 static inline u64
btrfs_file_extent_offset(struct btrfs_file_extent_item
*e
)
986 return le64_to_cpu(e
->offset
);
989 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
992 e
->offset
= cpu_to_le64(val
);
995 static inline u64
btrfs_file_extent_num_bytes(struct btrfs_file_extent_item
998 return le64_to_cpu(e
->num_bytes
);
1001 static inline void btrfs_set_file_extent_num_bytes(struct
1002 btrfs_file_extent_item
*e
,
1005 e
->num_bytes
= cpu_to_le64(val
);
1008 /* helper function to cast into the data area of the leaf. */
1009 #define btrfs_item_ptr(leaf, slot, type) \
1010 ((type *)(btrfs_leaf_data(leaf) + \
1011 btrfs_item_offset((leaf)->items + (slot))))
1013 static inline u32
btrfs_level_size(struct btrfs_root
*root
, int level
)
1016 return root
->leafsize
;
1017 return root
->nodesize
;
1019 int btrfs_comp_keys(struct btrfs_disk_key
*disk
, struct btrfs_key
*k2
);
1020 int btrfs_extend_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1021 *root
, struct btrfs_path
*path
, u32 data_size
);
1022 struct btrfs_buffer
*btrfs_alloc_free_block(struct btrfs_trans_handle
*trans
,
1023 struct btrfs_root
*root
,
1025 int btrfs_inc_ref(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
1026 struct btrfs_buffer
*buf
);
1027 int btrfs_free_extent(struct btrfs_trans_handle
*trans
, struct btrfs_root
1028 *root
, u64 bytenr
, u64 num_bytes
, int pin
);
1029 int btrfs_search_slot(struct btrfs_trans_handle
*trans
, struct btrfs_root
1030 *root
, struct btrfs_key
*key
, struct btrfs_path
*p
, int
1032 void btrfs_release_path(struct btrfs_root
*root
, struct btrfs_path
*p
);
1033 void btrfs_init_path(struct btrfs_path
*p
);
1034 int btrfs_del_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
1035 struct btrfs_path
*path
);
1036 int btrfs_insert_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1037 *root
, struct btrfs_key
*key
, void *data
, u32 data_size
);
1038 int btrfs_insert_empty_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1039 *root
, struct btrfs_path
*path
, struct btrfs_key
1040 *cpu_key
, u32 data_size
);
1041 int btrfs_next_leaf(struct btrfs_root
*root
, struct btrfs_path
*path
);
1042 int btrfs_leaf_free_space(struct btrfs_root
*root
, struct btrfs_leaf
*leaf
);
1043 int btrfs_drop_snapshot(struct btrfs_trans_handle
*trans
, struct btrfs_root
1044 *root
, struct btrfs_buffer
*snap
);
1045 int btrfs_finish_extent_commit(struct btrfs_trans_handle
*trans
, struct
1047 int btrfs_del_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
1048 struct btrfs_key
*key
);
1049 int btrfs_insert_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
1050 *root
, struct btrfs_key
*key
, struct btrfs_root_item
1052 int btrfs_update_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
1053 *root
, struct btrfs_key
*key
, struct btrfs_root_item
1055 int btrfs_find_last_root(struct btrfs_root
*root
, u64 objectid
, struct
1056 btrfs_root_item
*item
, struct btrfs_key
*key
);
1057 int btrfs_insert_dir_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1058 *root
, char *name
, int name_len
, u64 dir
,
1059 struct btrfs_key
*location
, u8 type
);
1060 int btrfs_lookup_dir_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1061 *root
, struct btrfs_path
*path
, u64 dir
, char *name
,
1062 int name_len
, int mod
);
1063 int btrfs_match_dir_item_name(struct btrfs_root
*root
, struct btrfs_path
*path
,
1064 char *name
, int name_len
);
1065 int btrfs_find_free_objectid(struct btrfs_trans_handle
*trans
,
1066 struct btrfs_root
*fs_root
,
1067 u64 dirid
, u64
*objectid
);
1068 int btrfs_insert_inode(struct btrfs_trans_handle
*trans
, struct btrfs_root
1069 *root
, u64 objectid
, struct btrfs_inode_item
1071 int btrfs_lookup_inode(struct btrfs_trans_handle
*trans
, struct btrfs_root
1072 *root
, struct btrfs_path
*path
, u64 objectid
, int mod
);
1073 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle
*trans
,
1074 struct btrfs_root
*root
);
1075 int btrfs_free_block_groups(struct btrfs_fs_info
*info
);
1076 int btrfs_read_block_groups(struct btrfs_root
*root
);
1077 int btrfs_insert_block_group(struct btrfs_trans_handle
*trans
,
1078 struct btrfs_root
*root
,
1079 struct btrfs_key
*key
,
1080 struct btrfs_block_group_item
*bi
);