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"
25 struct btrfs_trans_handle
;
27 #define BTRFS_MAGIC "_BtRfS_M"
29 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
30 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
31 #define BTRFS_FS_TREE_OBJECTID 3ULL
32 #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
33 #define BTRFS_FIRST_FREE_OBJECTID 5ULL
36 * we can actually store much bigger names, but lets not confuse the rest
39 #define BTRFS_NAME_LEN 255
41 /* 32 bytes in various csum fields */
42 #define BTRFS_CSUM_SIZE 32
44 #define BTRFS_FT_UNKNOWN 0
45 #define BTRFS_FT_REG_FILE 1
46 #define BTRFS_FT_DIR 2
47 #define BTRFS_FT_CHRDEV 3
48 #define BTRFS_FT_BLKDEV 4
49 #define BTRFS_FT_FIFO 5
50 #define BTRFS_FT_SOCK 6
51 #define BTRFS_FT_SYMLINK 7
52 #define BTRFS_FT_MAX 8
55 * the key defines the order in the tree, and so it also defines (optimal)
56 * block layout. objectid corresonds to the inode number. The flags
57 * tells us things about the object, and is a kind of stream selector.
58 * so for a given inode, keys with flags of 1 might refer to the inode
59 * data, flags of 2 may point to file data in the btree and flags == 3
60 * may point to extents.
62 * offset is the starting byte offset for this key in the stream.
64 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
65 * in cpu native order. Otherwise they are identical and their sizes
66 * should be the same (ie both packed)
68 struct btrfs_disk_key
{
72 } __attribute__ ((__packed__
));
78 } __attribute__ ((__packed__
));
81 * every tree block (leaf or node) starts with this header.
84 u8 csum
[BTRFS_CSUM_SIZE
];
85 u8 fsid
[16]; /* FS specific uuid */
86 __le64 blocknr
; /* which block this node is supposed to live in */
92 } __attribute__ ((__packed__
));
94 #define BTRFS_MAX_LEVEL 8
95 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
96 sizeof(struct btrfs_header)) / \
97 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
98 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
99 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
103 * the super block basically lists the main trees of the FS
104 * it currently lacks any block count etc etc
106 struct btrfs_super_block
{
107 u8 csum
[BTRFS_CSUM_SIZE
];
108 /* the first 3 fields must match struct btrfs_header */
109 u8 fsid
[16]; /* FS specific uuid */
110 __le64 blocknr
; /* this block number */
117 __le64 root_dir_objectid
;
118 } __attribute__ ((__packed__
));
121 * A leaf is full of items. offset and size tell us where to find
122 * the item in the leaf (relative to the start of the data area)
125 struct btrfs_disk_key key
;
128 } __attribute__ ((__packed__
));
131 * leaves have an item area and a data area:
132 * [item0, item1....itemN] [free space] [dataN...data1, data0]
134 * The data is separate from the items to get the keys closer together
138 struct btrfs_header header
;
139 struct btrfs_item items
[];
140 } __attribute__ ((__packed__
));
143 * all non-leaf blocks are nodes, they hold only keys and pointers to
146 struct btrfs_key_ptr
{
147 struct btrfs_disk_key key
;
149 } __attribute__ ((__packed__
));
152 struct btrfs_header header
;
153 struct btrfs_key_ptr ptrs
[];
154 } __attribute__ ((__packed__
));
157 * btrfs_paths remember the path taken from the root down to the leaf.
158 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
159 * to any other levels that are present.
161 * The slots array records the index of the item or block pointer
162 * used while walking the tree.
165 struct btrfs_buffer
*nodes
[BTRFS_MAX_LEVEL
];
166 int slots
[BTRFS_MAX_LEVEL
];
170 * items in the extent btree are used to record the objectid of the
171 * owner of the block and the number of references
173 struct btrfs_extent_item
{
176 } __attribute__ ((__packed__
));
178 struct btrfs_inode_timespec
{
181 } __attribute__ ((__packed__
));
184 * there is no padding here on purpose. If you want to extent the inode,
185 * make a new item type
187 struct btrfs_inode_item
{
199 struct btrfs_inode_timespec atime
;
200 struct btrfs_inode_timespec ctime
;
201 struct btrfs_inode_timespec mtime
;
202 struct btrfs_inode_timespec otime
;
203 } __attribute__ ((__packed__
));
205 /* inline data is just a blob of bytes */
206 struct btrfs_inline_data_item
{
208 } __attribute__ ((__packed__
));
210 struct btrfs_dir_item
{
211 struct btrfs_disk_key location
;
215 } __attribute__ ((__packed__
));
217 struct btrfs_root_item
{
218 struct btrfs_inode_item inode
;
225 } __attribute__ ((__packed__
));
227 #define BTRFS_FILE_EXTENT_REG 0
228 #define BTRFS_FILE_EXTENT_INLINE 1
230 struct btrfs_file_extent_item
{
234 * disk space consumed by the extent, checksum blocks are included
238 __le64 disk_num_blocks
;
240 * the logical offset in file blocks (no csums)
241 * this extent record is for. This allows a file extent to point
242 * into the middle of an existing extent on disk, sharing it
243 * between two snapshots (useful if some bytes in the middle of the
244 * extent have changed
248 * the logical number of file blocks (no csums included)
251 } __attribute__ ((__packed__
));
253 struct btrfs_csum_item
{
254 u8 csum
[BTRFS_CSUM_SIZE
];
255 } __attribute__ ((__packed__
));
257 /* tag for the radix tree of block groups in ram */
258 #define BTRFS_BLOCK_GROUP_DIRTY 0
259 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
262 #define BTRFS_BLOCK_GROUP_DATA 1
263 struct btrfs_block_group_item
{
266 } __attribute__ ((__packed__
));
268 struct btrfs_block_group_cache
{
269 struct btrfs_key key
;
270 struct btrfs_block_group_item item
;
273 struct btrfs_fs_info
{
274 struct btrfs_root
*fs_root
;
275 struct btrfs_root
*extent_root
;
276 struct btrfs_root
*tree_root
;
277 struct btrfs_key current_insert
;
278 struct btrfs_key last_insert
;
279 struct radix_tree_root cache_radix
;
280 struct radix_tree_root pinned_radix
;
281 struct radix_tree_root block_group_radix
;
282 struct list_head trans
;
283 struct list_head cache
;
284 u64 last_inode_alloc
;
285 u64 last_inode_alloc_dirid
;
289 struct btrfs_trans_handle
*running_transaction
;
290 struct btrfs_super_block
*disk_super
;
294 * in ram representation of the tree. extent_root is used for all allocations
295 * and for the extent tree extent_root root. current_insert is used
296 * only for the extent tree.
299 struct btrfs_buffer
*node
;
300 struct btrfs_buffer
*commit_root
;
301 struct btrfs_root_item root_item
;
302 struct btrfs_key root_key
;
303 struct btrfs_fs_info
*fs_info
;
309 /* the lower bits in the key flags defines the item type */
310 #define BTRFS_KEY_TYPE_MAX 256
311 #define BTRFS_KEY_TYPE_SHIFT 24
312 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
313 BTRFS_KEY_TYPE_SHIFT)
316 * inode items have the data typically returned from stat and store other
317 * info about object characteristics. There is one for every file and dir in
320 #define BTRFS_INODE_ITEM_KEY 1
322 /* reserve 2-15 close to the inode for later flexibility */
325 * dir items are the name -> inode pointers in a directory. There is one
326 * for every name in a directory.
328 #define BTRFS_DIR_ITEM_KEY 16
329 #define BTRFS_DIR_INDEX_KEY 17
331 * extent data is for file data
333 #define BTRFS_EXTENT_DATA_KEY 18
335 * csum items have the checksums for data in the extents
337 #define BTRFS_CSUM_ITEM_KEY 19
339 /* reserve 20-31 for other file stuff */
342 * root items point to tree roots. There are typically in the root
343 * tree used by the super block to find all the other trees
345 #define BTRFS_ROOT_ITEM_KEY 32
347 * extent items are in the extent map tree. These record which blocks
348 * are used, and how many references there are to each block
350 #define BTRFS_EXTENT_ITEM_KEY 33
353 * block groups give us hints into the extent allocation trees. Which
354 * blocks are free etc etc
356 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
359 * string items are for debugging. They just store a short string of
362 #define BTRFS_STRING_ITEM_KEY 253
365 static inline u64
btrfs_block_group_used(struct btrfs_block_group_item
*bi
)
367 return le64_to_cpu(bi
->used
);
370 static inline void btrfs_set_block_group_used(struct
371 btrfs_block_group_item
*bi
,
374 bi
->used
= cpu_to_le64(val
);
377 static inline u64
btrfs_inode_generation(struct btrfs_inode_item
*i
)
379 return le64_to_cpu(i
->generation
);
382 static inline void btrfs_set_inode_generation(struct btrfs_inode_item
*i
,
385 i
->generation
= cpu_to_le64(val
);
388 static inline u64
btrfs_inode_size(struct btrfs_inode_item
*i
)
390 return le64_to_cpu(i
->size
);
393 static inline void btrfs_set_inode_size(struct btrfs_inode_item
*i
, u64 val
)
395 i
->size
= cpu_to_le64(val
);
398 static inline u64
btrfs_inode_nblocks(struct btrfs_inode_item
*i
)
400 return le64_to_cpu(i
->nblocks
);
403 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item
*i
, u64 val
)
405 i
->nblocks
= cpu_to_le64(val
);
408 static inline u64
btrfs_inode_block_group(struct btrfs_inode_item
*i
)
410 return le64_to_cpu(i
->block_group
);
413 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item
*i
,
416 i
->block_group
= cpu_to_le64(val
);
419 static inline u32
btrfs_inode_nlink(struct btrfs_inode_item
*i
)
421 return le32_to_cpu(i
->nlink
);
424 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item
*i
, u32 val
)
426 i
->nlink
= cpu_to_le32(val
);
429 static inline u32
btrfs_inode_uid(struct btrfs_inode_item
*i
)
431 return le32_to_cpu(i
->uid
);
434 static inline void btrfs_set_inode_uid(struct btrfs_inode_item
*i
, u32 val
)
436 i
->uid
= cpu_to_le32(val
);
439 static inline u32
btrfs_inode_gid(struct btrfs_inode_item
*i
)
441 return le32_to_cpu(i
->gid
);
444 static inline void btrfs_set_inode_gid(struct btrfs_inode_item
*i
, u32 val
)
446 i
->gid
= cpu_to_le32(val
);
449 static inline u32
btrfs_inode_mode(struct btrfs_inode_item
*i
)
451 return le32_to_cpu(i
->mode
);
454 static inline void btrfs_set_inode_mode(struct btrfs_inode_item
*i
, u32 val
)
456 i
->mode
= cpu_to_le32(val
);
459 static inline u32
btrfs_inode_rdev(struct btrfs_inode_item
*i
)
461 return le32_to_cpu(i
->rdev
);
464 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item
*i
, u32 val
)
466 i
->rdev
= cpu_to_le32(val
);
469 static inline u16
btrfs_inode_flags(struct btrfs_inode_item
*i
)
471 return le16_to_cpu(i
->flags
);
474 static inline void btrfs_set_inode_flags(struct btrfs_inode_item
*i
, u16 val
)
476 i
->flags
= cpu_to_le16(val
);
479 static inline u16
btrfs_inode_compat_flags(struct btrfs_inode_item
*i
)
481 return le16_to_cpu(i
->compat_flags
);
484 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item
*i
,
487 i
->compat_flags
= cpu_to_le16(val
);
490 static inline u64
btrfs_timespec_sec(struct btrfs_inode_timespec
*ts
)
492 return le64_to_cpu(ts
->sec
);
495 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec
*ts
,
498 ts
->sec
= cpu_to_le64(val
);
501 static inline u32
btrfs_timespec_nsec(struct btrfs_inode_timespec
*ts
)
503 return le32_to_cpu(ts
->nsec
);
506 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec
*ts
,
509 ts
->nsec
= cpu_to_le32(val
);
512 static inline u32
btrfs_extent_refs(struct btrfs_extent_item
*ei
)
514 return le32_to_cpu(ei
->refs
);
517 static inline void btrfs_set_extent_refs(struct btrfs_extent_item
*ei
, u32 val
)
519 ei
->refs
= cpu_to_le32(val
);
522 static inline u64
btrfs_extent_owner(struct btrfs_extent_item
*ei
)
524 return le64_to_cpu(ei
->owner
);
527 static inline void btrfs_set_extent_owner(struct btrfs_extent_item
*ei
, u64 val
)
529 ei
->owner
= cpu_to_le64(val
);
532 static inline u64
btrfs_node_blockptr(struct btrfs_node
*n
, int nr
)
534 return le64_to_cpu(n
->ptrs
[nr
].blockptr
);
538 static inline void btrfs_set_node_blockptr(struct btrfs_node
*n
, int nr
,
541 n
->ptrs
[nr
].blockptr
= cpu_to_le64(val
);
544 static inline u32
btrfs_item_offset(struct btrfs_item
*item
)
546 return le32_to_cpu(item
->offset
);
549 static inline void btrfs_set_item_offset(struct btrfs_item
*item
, u32 val
)
551 item
->offset
= cpu_to_le32(val
);
554 static inline u32
btrfs_item_end(struct btrfs_item
*item
)
556 return le32_to_cpu(item
->offset
) + le16_to_cpu(item
->size
);
559 static inline u16
btrfs_item_size(struct btrfs_item
*item
)
561 return le16_to_cpu(item
->size
);
564 static inline void btrfs_set_item_size(struct btrfs_item
*item
, u16 val
)
566 item
->size
= cpu_to_le16(val
);
569 static inline u16
btrfs_dir_flags(struct btrfs_dir_item
*d
)
571 return le16_to_cpu(d
->flags
);
574 static inline void btrfs_set_dir_flags(struct btrfs_dir_item
*d
, u16 val
)
576 d
->flags
= cpu_to_le16(val
);
579 static inline u8
btrfs_dir_type(struct btrfs_dir_item
*d
)
584 static inline void btrfs_set_dir_type(struct btrfs_dir_item
*d
, u8 val
)
589 static inline u16
btrfs_dir_name_len(struct btrfs_dir_item
*d
)
591 return le16_to_cpu(d
->name_len
);
594 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item
*d
, u16 val
)
596 d
->name_len
= cpu_to_le16(val
);
599 static inline void btrfs_disk_key_to_cpu(struct btrfs_key
*cpu
,
600 struct btrfs_disk_key
*disk
)
602 cpu
->offset
= le64_to_cpu(disk
->offset
);
603 cpu
->flags
= le32_to_cpu(disk
->flags
);
604 cpu
->objectid
= le64_to_cpu(disk
->objectid
);
607 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key
*disk
,
608 struct btrfs_key
*cpu
)
610 disk
->offset
= cpu_to_le64(cpu
->offset
);
611 disk
->flags
= cpu_to_le32(cpu
->flags
);
612 disk
->objectid
= cpu_to_le64(cpu
->objectid
);
615 static inline u64
btrfs_disk_key_objectid(struct btrfs_disk_key
*disk
)
617 return le64_to_cpu(disk
->objectid
);
620 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key
*disk
,
623 disk
->objectid
= cpu_to_le64(val
);
626 static inline u64
btrfs_disk_key_offset(struct btrfs_disk_key
*disk
)
628 return le64_to_cpu(disk
->offset
);
631 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key
*disk
,
634 disk
->offset
= cpu_to_le64(val
);
637 static inline u32
btrfs_disk_key_flags(struct btrfs_disk_key
*disk
)
639 return le32_to_cpu(disk
->flags
);
642 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key
*disk
,
645 disk
->flags
= cpu_to_le32(val
);
648 static inline u32
btrfs_disk_key_type(struct btrfs_disk_key
*key
)
650 return le32_to_cpu(key
->flags
) >> BTRFS_KEY_TYPE_SHIFT
;
653 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key
*key
,
656 u32 flags
= btrfs_disk_key_flags(key
);
657 BUG_ON(val
>= BTRFS_KEY_TYPE_MAX
);
658 val
= val
<< BTRFS_KEY_TYPE_SHIFT
;
659 flags
= (flags
& ~BTRFS_KEY_TYPE_MASK
) | val
;
660 btrfs_set_disk_key_flags(key
, flags
);
663 static inline u32
btrfs_key_type(struct btrfs_key
*key
)
665 return key
->flags
>> BTRFS_KEY_TYPE_SHIFT
;
668 static inline void btrfs_set_key_type(struct btrfs_key
*key
, u32 val
)
670 BUG_ON(val
>= BTRFS_KEY_TYPE_MAX
);
671 val
= val
<< BTRFS_KEY_TYPE_SHIFT
;
672 key
->flags
= (key
->flags
& ~(BTRFS_KEY_TYPE_MASK
)) | val
;
675 static inline u64
btrfs_header_blocknr(struct btrfs_header
*h
)
677 return le64_to_cpu(h
->blocknr
);
680 static inline void btrfs_set_header_blocknr(struct btrfs_header
*h
, u64 blocknr
)
682 h
->blocknr
= cpu_to_le64(blocknr
);
685 static inline u64
btrfs_header_generation(struct btrfs_header
*h
)
687 return le64_to_cpu(h
->generation
);
690 static inline void btrfs_set_header_generation(struct btrfs_header
*h
,
693 h
->generation
= cpu_to_le64(val
);
696 static inline u64
btrfs_header_owner(struct btrfs_header
*h
)
698 return le64_to_cpu(h
->owner
);
701 static inline void btrfs_set_header_owner(struct btrfs_header
*h
,
704 h
->owner
= cpu_to_le64(val
);
707 static inline u16
btrfs_header_nritems(struct btrfs_header
*h
)
709 return le16_to_cpu(h
->nritems
);
712 static inline void btrfs_set_header_nritems(struct btrfs_header
*h
, u16 val
)
714 h
->nritems
= cpu_to_le16(val
);
717 static inline u16
btrfs_header_flags(struct btrfs_header
*h
)
719 return le16_to_cpu(h
->flags
);
722 static inline void btrfs_set_header_flags(struct btrfs_header
*h
, u16 val
)
724 h
->flags
= cpu_to_le16(val
);
727 static inline int btrfs_header_level(struct btrfs_header
*h
)
732 static inline void btrfs_set_header_level(struct btrfs_header
*h
, int level
)
734 BUG_ON(level
> BTRFS_MAX_LEVEL
);
738 static inline int btrfs_is_leaf(struct btrfs_node
*n
)
740 return (btrfs_header_level(&n
->header
) == 0);
743 static inline u64
btrfs_root_blocknr(struct btrfs_root_item
*item
)
745 return le64_to_cpu(item
->blocknr
);
748 static inline void btrfs_set_root_blocknr(struct btrfs_root_item
*item
, u64 val
)
750 item
->blocknr
= cpu_to_le64(val
);
753 static inline u64
btrfs_root_dirid(struct btrfs_root_item
*item
)
755 return le64_to_cpu(item
->root_dirid
);
758 static inline void btrfs_set_root_dirid(struct btrfs_root_item
*item
, u64 val
)
760 item
->root_dirid
= cpu_to_le64(val
);
763 static inline u32
btrfs_root_refs(struct btrfs_root_item
*item
)
765 return le32_to_cpu(item
->refs
);
768 static inline void btrfs_set_root_refs(struct btrfs_root_item
*item
, u32 val
)
770 item
->refs
= cpu_to_le32(val
);
773 static inline u64
btrfs_super_blocknr(struct btrfs_super_block
*s
)
775 return le64_to_cpu(s
->blocknr
);
778 static inline void btrfs_set_super_blocknr(struct btrfs_super_block
*s
, u64 val
)
780 s
->blocknr
= cpu_to_le64(val
);
783 static inline u64
btrfs_super_generation(struct btrfs_super_block
*s
)
785 return le64_to_cpu(s
->generation
);
788 static inline void btrfs_set_super_generation(struct btrfs_super_block
*s
,
791 s
->generation
= cpu_to_le64(val
);
794 static inline u64
btrfs_super_root(struct btrfs_super_block
*s
)
796 return le64_to_cpu(s
->root
);
799 static inline void btrfs_set_super_root(struct btrfs_super_block
*s
, u64 val
)
801 s
->root
= cpu_to_le64(val
);
804 static inline u64
btrfs_super_total_blocks(struct btrfs_super_block
*s
)
806 return le64_to_cpu(s
->total_blocks
);
809 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block
*s
,
812 s
->total_blocks
= cpu_to_le64(val
);
815 static inline u64
btrfs_super_blocks_used(struct btrfs_super_block
*s
)
817 return le64_to_cpu(s
->blocks_used
);
820 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block
*s
,
823 s
->blocks_used
= cpu_to_le64(val
);
826 static inline u32
btrfs_super_blocksize(struct btrfs_super_block
*s
)
828 return le32_to_cpu(s
->blocksize
);
831 static inline void btrfs_set_super_blocksize(struct btrfs_super_block
*s
,
834 s
->blocksize
= cpu_to_le32(val
);
837 static inline u64
btrfs_super_root_dir(struct btrfs_super_block
*s
)
839 return le64_to_cpu(s
->root_dir_objectid
);
842 static inline void btrfs_set_super_root_dir(struct btrfs_super_block
*s
, u64
845 s
->root_dir_objectid
= cpu_to_le64(val
);
848 static inline u8
*btrfs_leaf_data(struct btrfs_leaf
*l
)
850 return (u8
*)l
->items
;
853 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item
*e
)
857 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item
*e
,
863 static inline char *btrfs_file_extent_inline_start(struct
864 btrfs_file_extent_item
*e
)
866 return (char *)(&e
->disk_blocknr
);
869 static inline u32
btrfs_file_extent_calc_inline_size(u32 datasize
)
871 return (unsigned long)(&((struct
872 btrfs_file_extent_item
*)NULL
)->disk_blocknr
) + datasize
;
875 static inline u32
btrfs_file_extent_inline_len(struct btrfs_item
*e
)
877 struct btrfs_file_extent_item
*fe
= NULL
;
878 return btrfs_item_size(e
) - (unsigned long)(&fe
->disk_blocknr
);
881 static inline u64
btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
884 return le64_to_cpu(e
->disk_blocknr
);
887 static inline void btrfs_set_file_extent_disk_blocknr(struct
888 btrfs_file_extent_item
891 e
->disk_blocknr
= cpu_to_le64(val
);
894 static inline u64
btrfs_file_extent_generation(struct btrfs_file_extent_item
*e
)
896 return le64_to_cpu(e
->generation
);
899 static inline void btrfs_set_file_extent_generation(struct
900 btrfs_file_extent_item
*e
,
903 e
->generation
= cpu_to_le64(val
);
906 static inline u64
btrfs_file_extent_disk_num_blocks(struct
907 btrfs_file_extent_item
*e
)
909 return le64_to_cpu(e
->disk_num_blocks
);
912 static inline void btrfs_set_file_extent_disk_num_blocks(struct
913 btrfs_file_extent_item
916 e
->disk_num_blocks
= cpu_to_le64(val
);
919 static inline u64
btrfs_file_extent_offset(struct btrfs_file_extent_item
*e
)
921 return le64_to_cpu(e
->offset
);
924 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
927 e
->offset
= cpu_to_le64(val
);
930 static inline u64
btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
933 return le64_to_cpu(e
->num_blocks
);
936 static inline void btrfs_set_file_extent_num_blocks(struct
937 btrfs_file_extent_item
*e
,
940 e
->num_blocks
= cpu_to_le64(val
);
943 /* helper function to cast into the data area of the leaf. */
944 #define btrfs_item_ptr(leaf, slot, type) \
945 ((type *)(btrfs_leaf_data(leaf) + \
946 btrfs_item_offset((leaf)->items + (slot))))
948 int btrfs_comp_keys(struct btrfs_disk_key
*disk
, struct btrfs_key
*k2
);
949 int btrfs_extend_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
950 *root
, struct btrfs_path
*path
, u32 data_size
);
951 struct btrfs_buffer
*btrfs_alloc_free_block(struct btrfs_trans_handle
*trans
,
952 struct btrfs_root
*root
);
953 int btrfs_inc_ref(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
954 struct btrfs_buffer
*buf
);
955 int btrfs_free_extent(struct btrfs_trans_handle
*trans
, struct btrfs_root
956 *root
, u64 blocknr
, u64 num_blocks
, int pin
);
957 int btrfs_search_slot(struct btrfs_trans_handle
*trans
, struct btrfs_root
958 *root
, struct btrfs_key
*key
, struct btrfs_path
*p
, int
960 void btrfs_release_path(struct btrfs_root
*root
, struct btrfs_path
*p
);
961 void btrfs_init_path(struct btrfs_path
*p
);
962 int btrfs_del_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
963 struct btrfs_path
*path
);
964 int btrfs_insert_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
965 *root
, struct btrfs_key
*key
, void *data
, u32 data_size
);
966 int btrfs_insert_empty_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
967 *root
, struct btrfs_path
*path
, struct btrfs_key
968 *cpu_key
, u32 data_size
);
969 int btrfs_next_leaf(struct btrfs_root
*root
, struct btrfs_path
*path
);
970 int btrfs_leaf_free_space(struct btrfs_root
*root
, struct btrfs_leaf
*leaf
);
971 int btrfs_drop_snapshot(struct btrfs_trans_handle
*trans
, struct btrfs_root
972 *root
, struct btrfs_buffer
*snap
);
973 int btrfs_finish_extent_commit(struct btrfs_trans_handle
*trans
, struct
975 int btrfs_del_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
976 struct btrfs_key
*key
);
977 int btrfs_insert_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
978 *root
, struct btrfs_key
*key
, struct btrfs_root_item
980 int btrfs_update_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
981 *root
, struct btrfs_key
*key
, struct btrfs_root_item
983 int btrfs_find_last_root(struct btrfs_root
*root
, u64 objectid
, struct
984 btrfs_root_item
*item
, struct btrfs_key
*key
);
985 int btrfs_insert_dir_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
986 *root
, char *name
, int name_len
, u64 dir
,
987 struct btrfs_key
*location
, u8 type
);
988 int btrfs_lookup_dir_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
989 *root
, struct btrfs_path
*path
, u64 dir
, char *name
,
990 int name_len
, int mod
);
991 int btrfs_match_dir_item_name(struct btrfs_root
*root
, struct btrfs_path
*path
,
992 char *name
, int name_len
);
993 int btrfs_find_free_objectid(struct btrfs_trans_handle
*trans
,
994 struct btrfs_root
*fs_root
,
995 u64 dirid
, u64
*objectid
);
996 int btrfs_insert_inode(struct btrfs_trans_handle
*trans
, struct btrfs_root
997 *root
, u64 objectid
, struct btrfs_inode_item
999 int btrfs_lookup_inode(struct btrfs_trans_handle
*trans
, struct btrfs_root
1000 *root
, struct btrfs_path
*path
, u64 objectid
, int mod
);
1001 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle
*trans
,
1002 struct btrfs_root
*root
);
1003 int btrfs_free_block_groups(struct btrfs_fs_info
*info
);
1004 int btrfs_read_block_groups(struct btrfs_root
*root
);
1005 int btrfs_insert_block_group(struct btrfs_trans_handle
*trans
,
1006 struct btrfs_root
*root
,
1007 struct btrfs_key
*key
,
1008 struct btrfs_block_group_item
*bi
);