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"
26 #include "extent_io.h"
29 struct btrfs_trans_handle
;
30 #define BTRFS_MAGIC "_B4RfS_M"
32 #define BTRFS_MAX_LEVEL 8
34 /* holds pointers to all of the tree roots */
35 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
37 /* stores information about which extents are in use, and reference counts */
38 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
41 * chunk tree stores translations from logical -> physical block numbering
42 * the super block points to the chunk tree
44 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
47 * stores information about which areas of a given device are in use.
48 * one per device. The tree of tree roots points to the device tree
50 #define BTRFS_DEV_TREE_OBJECTID 4ULL
52 /* one per subvolume, storing files and directories */
53 #define BTRFS_FS_TREE_OBJECTID 5ULL
55 /* directory objectid inside the root tree */
56 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
59 * All files have objectids higher than this.
61 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
65 * the device items go into the chunk tree. The key is in the form
66 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
68 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
71 * we can actually store much bigger names, but lets not confuse the rest
74 #define BTRFS_NAME_LEN 255
76 /* 32 bytes in various csum fields */
77 #define BTRFS_CSUM_SIZE 32
78 /* four bytes for CRC32 */
79 #define BTRFS_CRC32_SIZE 4
80 #define BTRFS_EMPTY_DIR_SIZE 0
82 #define BTRFS_FT_UNKNOWN 0
83 #define BTRFS_FT_REG_FILE 1
84 #define BTRFS_FT_DIR 2
85 #define BTRFS_FT_CHRDEV 3
86 #define BTRFS_FT_BLKDEV 4
87 #define BTRFS_FT_FIFO 5
88 #define BTRFS_FT_SOCK 6
89 #define BTRFS_FT_SYMLINK 7
90 #define BTRFS_FT_XATTR 8
91 #define BTRFS_FT_MAX 9
94 * the key defines the order in the tree, and so it also defines (optimal)
95 * block layout. objectid corresonds to the inode number. The flags
96 * tells us things about the object, and is a kind of stream selector.
97 * so for a given inode, keys with flags of 1 might refer to the inode
98 * data, flags of 2 may point to file data in the btree and flags == 3
99 * may point to extents.
101 * offset is the starting byte offset for this key in the stream.
103 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
104 * in cpu native order. Otherwise they are identical and their sizes
105 * should be the same (ie both packed)
107 struct btrfs_disk_key
{
111 } __attribute__ ((__packed__
));
117 } __attribute__ ((__packed__
));
119 struct btrfs_mapping_tree
{
120 struct cache_tree cache_tree
;
123 #define BTRFS_DEV_UUID_SIZE 16
124 struct btrfs_dev_item
{
125 /* the internal btrfs device id */
128 /* size of the device */
134 /* optimal io alignment for this device */
137 /* optimal io width for this device */
140 /* minimal io size for this device */
143 /* type and info about this device */
146 /* btrfs generated uuid for this device */
147 u8 uuid
[BTRFS_DEV_UUID_SIZE
];
148 } __attribute__ ((__packed__
));
150 struct btrfs_stripe
{
153 } __attribute__ ((__packed__
));
160 /* optimal io alignment for this chunk */
163 /* optimal io width for this chunk */
166 /* minimal io size for this chunk */
169 /* 2^16 stripes is quite a lot, a second limit is the size of a single
173 struct btrfs_stripe stripe
;
174 /* additional stripes go here */
175 } __attribute__ ((__packed__
));
177 static inline unsigned long btrfs_chunk_item_size(int num_stripes
)
179 BUG_ON(num_stripes
== 0);
180 return sizeof(struct btrfs_chunk
) +
181 sizeof(struct btrfs_stripe
) * (num_stripes
- 1);
184 #define BTRFS_FSID_SIZE 16
186 * every tree block (leaf or node) starts with this header.
188 struct btrfs_header
{
189 u8 csum
[BTRFS_CSUM_SIZE
];
190 u8 fsid
[BTRFS_FSID_SIZE
]; /* FS specific uuid */
191 __le64 bytenr
; /* which block this node is supposed to live in */
197 } __attribute__ ((__packed__
));
199 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
200 sizeof(struct btrfs_header)) / \
201 sizeof(struct btrfs_key_ptr))
202 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
203 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
204 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
205 sizeof(struct btrfs_item) - \
206 sizeof(struct btrfs_file_extent_item))
209 * this is a very generous portion of the super block, giving us
210 * room to translate 14 chunks with 3 stripes each.
212 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
215 * the super block basically lists the main trees of the FS
216 * it currently lacks any block count etc etc
218 struct btrfs_super_block
{
219 u8 csum
[BTRFS_CSUM_SIZE
];
220 /* the first 3 fields must match struct btrfs_header */
221 u8 fsid
[BTRFS_FSID_SIZE
]; /* FS specific uuid */
222 __le64 bytenr
; /* this block number */
229 __le64 root_dir_objectid
;
235 __le32 sys_chunk_array_size
;
238 struct btrfs_dev_item dev_item
;
239 u8 sys_chunk_array
[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE
];
240 } __attribute__ ((__packed__
));
243 * A leaf is full of items. offset and size tell us where to find
244 * the item in the leaf (relative to the start of the data area)
247 struct btrfs_disk_key key
;
250 } __attribute__ ((__packed__
));
253 * leaves have an item area and a data area:
254 * [item0, item1....itemN] [free space] [dataN...data1, data0]
256 * The data is separate from the items to get the keys closer together
260 struct btrfs_header header
;
261 struct btrfs_item items
[];
262 } __attribute__ ((__packed__
));
265 * all non-leaf blocks are nodes, they hold only keys and pointers to
268 struct btrfs_key_ptr
{
269 struct btrfs_disk_key key
;
272 } __attribute__ ((__packed__
));
275 struct btrfs_header header
;
276 struct btrfs_key_ptr ptrs
[];
277 } __attribute__ ((__packed__
));
280 * btrfs_paths remember the path taken from the root down to the leaf.
281 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
282 * to any other levels that are present.
284 * The slots array records the index of the item or block pointer
285 * used while walking the tree.
288 struct extent_buffer
*nodes
[BTRFS_MAX_LEVEL
];
289 int slots
[BTRFS_MAX_LEVEL
];
295 * items in the extent btree are used to record the objectid of the
296 * owner of the block and the number of references
298 struct btrfs_extent_item
{
300 } __attribute__ ((__packed__
));
302 struct btrfs_extent_ref
{
307 } __attribute__ ((__packed__
));
309 /* dev extents record free space on individual devices. The owner
310 * field points back to the chunk allocation mapping tree that allocated
313 struct btrfs_dev_extent
{
316 } __attribute__ ((__packed__
));
319 struct btrfs_inode_ref
{
322 } __attribute__ ((__packed__
));
324 struct btrfs_timespec
{
327 } __attribute__ ((__packed__
));
330 * there is no padding here on purpose. If you want to extent the inode,
331 * make a new item type
333 struct btrfs_inode_item
{
345 struct btrfs_timespec atime
;
346 struct btrfs_timespec ctime
;
347 struct btrfs_timespec mtime
;
348 struct btrfs_timespec otime
;
349 } __attribute__ ((__packed__
));
351 struct btrfs_dir_item
{
352 struct btrfs_disk_key location
;
356 } __attribute__ ((__packed__
));
358 struct btrfs_root_item
{
359 struct btrfs_inode_item inode
;
366 struct btrfs_disk_key drop_progress
;
369 } __attribute__ ((__packed__
));
371 #define BTRFS_FILE_EXTENT_REG 0
372 #define BTRFS_FILE_EXTENT_INLINE 1
374 struct btrfs_file_extent_item
{
378 * disk space consumed by the extent, checksum blocks are included
382 __le64 disk_num_bytes
;
384 * the logical offset in file blocks (no csums)
385 * this extent record is for. This allows a file extent to point
386 * into the middle of an existing extent on disk, sharing it
387 * between two snapshots (useful if some bytes in the middle of the
388 * extent have changed
392 * the logical number of file blocks (no csums included)
395 } __attribute__ ((__packed__
));
397 struct btrfs_csum_item
{
399 } __attribute__ ((__packed__
));
401 /* tag for the radix tree of block groups in ram */
402 #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
403 #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
404 #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
406 struct btrfs_block_group_item
{
409 __le64 chunk_objectid
;
411 } __attribute__ ((__packed__
));
413 struct btrfs_space_info
{
419 struct list_head list
;
422 struct btrfs_block_group_cache
{
423 struct cache_extent cache
;
424 struct btrfs_key key
;
425 struct btrfs_block_group_item item
;
426 struct btrfs_space_info
*space_info
;
432 struct btrfs_extent_ops
{
433 int (*alloc_extent
)(struct btrfs_root
*root
, u64 num_bytes
,
434 u64 hint_byte
, struct btrfs_key
*ins
);
435 int (*free_extent
)(struct btrfs_root
*root
, u64 bytenr
,
440 struct btrfs_fs_info
{
441 u8 fsid
[BTRFS_FSID_SIZE
];
442 struct btrfs_root
*fs_root
;
443 struct btrfs_root
*extent_root
;
444 struct btrfs_root
*tree_root
;
445 struct btrfs_root
*chunk_root
;
446 struct btrfs_root
*dev_root
;
448 struct extent_io_tree extent_cache
;
449 struct extent_io_tree free_space_cache
;
450 struct extent_io_tree block_group_cache
;
451 struct extent_io_tree pinned_extents
;
452 struct extent_io_tree pending_del
;
453 struct extent_io_tree extent_ins
;
455 /* logical->physical extent mapping */
456 struct btrfs_mapping_tree mapping_tree
;
459 u64 last_trans_committed
;
460 struct btrfs_trans_handle
*running_transaction
;
461 struct btrfs_super_block super_copy
;
462 struct extent_buffer
*sb_buffer
;
463 struct mutex fs_mutex
;
466 struct btrfs_extent_ops
*extent_ops
;
467 struct list_head dirty_cowonly_roots
;
469 struct list_head devices
;
470 struct list_head space_info
;
472 int force_system_allocs
;
477 * in ram representation of the tree. extent_root is used for all allocations
478 * and for the extent tree extent_root root.
481 struct extent_buffer
*node
;
482 struct extent_buffer
*commit_root
;
483 struct btrfs_root_item root_item
;
484 struct btrfs_key root_key
;
485 struct btrfs_fs_info
*fs_info
;
489 /* data allocations are done in sectorsize units */
492 /* node allocations are done in nodesize units */
495 /* leaf allocations are done in leafsize units */
498 /* leaf allocations are done in leafsize units */
507 u64 last_inode_alloc
;
509 /* the dirty list is only used by non-reference counted roots */
510 struct list_head dirty_list
;
514 * inode items have the data typically returned from stat and store other
515 * info about object characteristics. There is one for every file and dir in
518 #define BTRFS_INODE_ITEM_KEY 1
519 #define BTRFS_INODE_REF_KEY 2
520 #define BTRFS_XATTR_ITEM_KEY 8
522 /* reserve 3-15 close to the inode for later flexibility */
525 * dir items are the name -> inode pointers in a directory. There is one
526 * for every name in a directory.
528 #define BTRFS_DIR_ITEM_KEY 16
529 #define BTRFS_DIR_INDEX_KEY 17
531 * extent data is for file data
533 #define BTRFS_EXTENT_DATA_KEY 18
535 * csum items have the checksums for data in the extents
537 #define BTRFS_CSUM_ITEM_KEY 19
539 /* reserve 20-31 for other file stuff */
542 * root items point to tree roots. There are typically in the root
543 * tree used by the super block to find all the other trees
545 #define BTRFS_ROOT_ITEM_KEY 32
547 * extent items are in the extent map tree. These record which blocks
548 * are used, and how many references there are to each block
550 #define BTRFS_EXTENT_ITEM_KEY 33
551 #define BTRFS_EXTENT_REF_KEY 34
554 * block groups give us hints into the extent allocation trees. Which
555 * blocks are free etc etc
557 #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
559 #define BTRFS_DEV_EXTENT_KEY 75
560 #define BTRFS_DEV_ITEM_KEY 76
561 #define BTRFS_CHUNK_ITEM_KEY 77
564 * string items are for debugging. They just store a short string of
567 #define BTRFS_STRING_ITEM_KEY 253
571 #define BTRFS_INODE_NODATASUM (1 << 0)
572 #define BTRFS_INODE_NODATACOW (1 << 1)
573 #define BTRFS_INODE_READONLY (1 << 2)
575 #define read_eb_member(eb, ptr, type, member, result) ( \
576 read_extent_buffer(eb, (char *)(result), \
577 ((unsigned long)(ptr)) + \
578 offsetof(type, member), \
579 sizeof(((type *)0)->member)))
581 #define write_eb_member(eb, ptr, type, member, result) ( \
582 write_extent_buffer(eb, (char *)(result), \
583 ((unsigned long)(ptr)) + \
584 offsetof(type, member), \
585 sizeof(((type *)0)->member)))
587 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
588 static inline u##bits btrfs_##name(struct extent_buffer *eb) \
590 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
591 return le##bits##_to_cpu(h->member); \
593 static inline void btrfs_set_##name(struct extent_buffer *eb, \
596 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
597 h->member = cpu_to_le##bits(val); \
600 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
601 static inline u##bits btrfs_##name(struct extent_buffer *eb, \
604 unsigned long offset = (unsigned long)s; \
605 type *p = (type *) (eb->data + offset); \
606 return le##bits##_to_cpu(p->member); \
608 static inline void btrfs_set_##name(struct extent_buffer *eb, \
609 type *s, u##bits val) \
611 unsigned long offset = (unsigned long)s; \
612 type *p = (type *) (eb->data + offset); \
613 p->member = cpu_to_le##bits(val); \
616 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
617 static inline u##bits btrfs_##name(type *s) \
619 return le##bits##_to_cpu(s->member); \
621 static inline void btrfs_set_##name(type *s, u##bits val) \
623 s->member = cpu_to_le##bits(val); \
626 BTRFS_SETGET_FUNCS(device_type
, struct btrfs_dev_item
, type
, 64);
627 BTRFS_SETGET_FUNCS(device_total_bytes
, struct btrfs_dev_item
, total_bytes
, 64);
628 BTRFS_SETGET_FUNCS(device_bytes_used
, struct btrfs_dev_item
, bytes_used
, 64);
629 BTRFS_SETGET_FUNCS(device_io_align
, struct btrfs_dev_item
, io_align
, 32);
630 BTRFS_SETGET_FUNCS(device_io_width
, struct btrfs_dev_item
, io_width
, 32);
631 BTRFS_SETGET_FUNCS(device_sector_size
, struct btrfs_dev_item
, sector_size
, 32);
632 BTRFS_SETGET_FUNCS(device_id
, struct btrfs_dev_item
, devid
, 64);
634 BTRFS_SETGET_STACK_FUNCS(stack_device_type
, struct btrfs_dev_item
, type
, 64);
635 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes
, struct btrfs_dev_item
,
637 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used
, struct btrfs_dev_item
,
639 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align
, struct btrfs_dev_item
,
641 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width
, struct btrfs_dev_item
,
643 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size
, struct btrfs_dev_item
,
645 BTRFS_SETGET_STACK_FUNCS(stack_device_id
, struct btrfs_dev_item
, devid
, 64);
647 static inline char *btrfs_device_uuid(struct btrfs_dev_item
*d
)
649 return (char *)d
+ offsetof(struct btrfs_dev_item
, uuid
);
652 BTRFS_SETGET_FUNCS(chunk_owner
, struct btrfs_chunk
, owner
, 64);
653 BTRFS_SETGET_FUNCS(chunk_stripe_len
, struct btrfs_chunk
, stripe_len
, 64);
654 BTRFS_SETGET_FUNCS(chunk_io_align
, struct btrfs_chunk
, io_align
, 32);
655 BTRFS_SETGET_FUNCS(chunk_io_width
, struct btrfs_chunk
, io_width
, 32);
656 BTRFS_SETGET_FUNCS(chunk_sector_size
, struct btrfs_chunk
, sector_size
, 32);
657 BTRFS_SETGET_FUNCS(chunk_type
, struct btrfs_chunk
, type
, 64);
658 BTRFS_SETGET_FUNCS(chunk_num_stripes
, struct btrfs_chunk
, num_stripes
, 16);
659 BTRFS_SETGET_FUNCS(stripe_devid
, struct btrfs_stripe
, devid
, 64);
660 BTRFS_SETGET_FUNCS(stripe_offset
, struct btrfs_stripe
, offset
, 64);
662 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner
, struct btrfs_chunk
, owner
, 64);
663 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len
, struct btrfs_chunk
,
665 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align
, struct btrfs_chunk
,
667 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width
, struct btrfs_chunk
,
669 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size
, struct btrfs_chunk
,
671 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type
, struct btrfs_chunk
, type
, 64);
672 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes
, struct btrfs_chunk
,
674 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid
, struct btrfs_stripe
, devid
, 64);
675 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset
, struct btrfs_stripe
, offset
, 64);
677 static inline struct btrfs_stripe
*btrfs_stripe_nr(struct btrfs_chunk
*c
,
680 unsigned long offset
= (unsigned long)c
;
681 offset
+= offsetof(struct btrfs_chunk
, stripe
);
682 offset
+= nr
* sizeof(struct btrfs_stripe
);
683 return (struct btrfs_stripe
*)offset
;
686 static inline u64
btrfs_stripe_offset_nr(struct extent_buffer
*eb
,
687 struct btrfs_chunk
*c
, int nr
)
689 return btrfs_stripe_offset(eb
, btrfs_stripe_nr(c
, nr
));
692 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer
*eb
,
693 struct btrfs_chunk
*c
, int nr
,
696 btrfs_set_stripe_offset(eb
, btrfs_stripe_nr(c
, nr
), val
);
699 static inline u64
btrfs_stripe_devid_nr(struct extent_buffer
*eb
,
700 struct btrfs_chunk
*c
, int nr
)
702 return btrfs_stripe_devid(eb
, btrfs_stripe_nr(c
, nr
));
705 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer
*eb
,
706 struct btrfs_chunk
*c
, int nr
,
709 btrfs_set_stripe_devid(eb
, btrfs_stripe_nr(c
, nr
), val
);
712 /* struct btrfs_block_group_item */
713 BTRFS_SETGET_STACK_FUNCS(block_group_used
, struct btrfs_block_group_item
,
715 BTRFS_SETGET_FUNCS(disk_block_group_used
, struct btrfs_block_group_item
,
717 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_tree
, struct btrfs_block_group_item
,
719 BTRFS_SETGET_FUNCS(disk_block_group_chunk_tree
, struct btrfs_block_group_item
,
721 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid
,
722 struct btrfs_block_group_item
, chunk_objectid
, 64);
723 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objecitd
,
724 struct btrfs_block_group_item
, chunk_objectid
, 64);
725 BTRFS_SETGET_FUNCS(disk_block_group_flags
,
726 struct btrfs_block_group_item
, flags
, 64);
727 BTRFS_SETGET_STACK_FUNCS(block_group_flags
,
728 struct btrfs_block_group_item
, flags
, 64);
730 /* struct btrfs_inode_ref */
731 BTRFS_SETGET_FUNCS(inode_ref_name_len
, struct btrfs_inode_ref
, name_len
, 16);
733 /* struct btrfs_inode_item */
734 BTRFS_SETGET_FUNCS(inode_generation
, struct btrfs_inode_item
, generation
, 64);
735 BTRFS_SETGET_FUNCS(inode_size
, struct btrfs_inode_item
, size
, 64);
736 BTRFS_SETGET_FUNCS(inode_nblocks
, struct btrfs_inode_item
, nblocks
, 64);
737 BTRFS_SETGET_FUNCS(inode_block_group
, struct btrfs_inode_item
, block_group
, 64);
738 BTRFS_SETGET_FUNCS(inode_nlink
, struct btrfs_inode_item
, nlink
, 32);
739 BTRFS_SETGET_FUNCS(inode_uid
, struct btrfs_inode_item
, uid
, 32);
740 BTRFS_SETGET_FUNCS(inode_gid
, struct btrfs_inode_item
, gid
, 32);
741 BTRFS_SETGET_FUNCS(inode_mode
, struct btrfs_inode_item
, mode
, 32);
742 BTRFS_SETGET_FUNCS(inode_rdev
, struct btrfs_inode_item
, rdev
, 64);
743 BTRFS_SETGET_FUNCS(inode_flags
, struct btrfs_inode_item
, flags
, 16);
744 BTRFS_SETGET_FUNCS(inode_compat_flags
, struct btrfs_inode_item
,
747 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation
,
748 struct btrfs_inode_item
, generation
, 64);
749 BTRFS_SETGET_STACK_FUNCS(stack_inode_size
,
750 struct btrfs_inode_item
, size
, 64);
751 BTRFS_SETGET_STACK_FUNCS(stack_inode_nblocks
,
752 struct btrfs_inode_item
, nblocks
, 64);
753 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group
,
754 struct btrfs_inode_item
, block_group
, 64);
755 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink
,
756 struct btrfs_inode_item
, nlink
, 32);
757 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid
,
758 struct btrfs_inode_item
, uid
, 32);
759 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid
,
760 struct btrfs_inode_item
, gid
, 32);
761 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode
,
762 struct btrfs_inode_item
, mode
, 32);
763 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev
,
764 struct btrfs_inode_item
, rdev
, 64);
765 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags
,
766 struct btrfs_inode_item
, flags
, 16);
767 BTRFS_SETGET_STACK_FUNCS(stack_inode_compat_flags
,
768 struct btrfs_inode_item
, compat_flags
, 16);
770 static inline struct btrfs_timespec
*
771 btrfs_inode_atime(struct btrfs_inode_item
*inode_item
)
773 unsigned long ptr
= (unsigned long)inode_item
;
774 ptr
+= offsetof(struct btrfs_inode_item
, atime
);
775 return (struct btrfs_timespec
*)ptr
;
778 static inline struct btrfs_timespec
*
779 btrfs_inode_mtime(struct btrfs_inode_item
*inode_item
)
781 unsigned long ptr
= (unsigned long)inode_item
;
782 ptr
+= offsetof(struct btrfs_inode_item
, mtime
);
783 return (struct btrfs_timespec
*)ptr
;
786 static inline struct btrfs_timespec
*
787 btrfs_inode_ctime(struct btrfs_inode_item
*inode_item
)
789 unsigned long ptr
= (unsigned long)inode_item
;
790 ptr
+= offsetof(struct btrfs_inode_item
, ctime
);
791 return (struct btrfs_timespec
*)ptr
;
794 static inline struct btrfs_timespec
*
795 btrfs_inode_otime(struct btrfs_inode_item
*inode_item
)
797 unsigned long ptr
= (unsigned long)inode_item
;
798 ptr
+= offsetof(struct btrfs_inode_item
, otime
);
799 return (struct btrfs_timespec
*)ptr
;
802 BTRFS_SETGET_FUNCS(timespec_sec
, struct btrfs_timespec
, sec
, 64);
803 BTRFS_SETGET_FUNCS(timespec_nsec
, struct btrfs_timespec
, nsec
, 32);
804 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec
, struct btrfs_timespec
,
806 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec
, struct btrfs_timespec
,
809 /* struct btrfs_dev_extent */
810 BTRFS_SETGET_FUNCS(dev_extent_owner
, struct btrfs_dev_extent
, owner
, 64);
811 BTRFS_SETGET_FUNCS(dev_extent_length
, struct btrfs_dev_extent
, length
, 64);
813 /* struct btrfs_extent_item */
814 BTRFS_SETGET_FUNCS(extent_refs
, struct btrfs_extent_item
, refs
, 32);
816 /* struct btrfs_extent_ref */
817 BTRFS_SETGET_FUNCS(ref_root
, struct btrfs_extent_ref
, root
, 64);
818 BTRFS_SETGET_FUNCS(ref_generation
, struct btrfs_extent_ref
, generation
, 64);
819 BTRFS_SETGET_FUNCS(ref_objectid
, struct btrfs_extent_ref
, objectid
, 64);
820 BTRFS_SETGET_FUNCS(ref_offset
, struct btrfs_extent_ref
, offset
, 64);
822 BTRFS_SETGET_STACK_FUNCS(stack_ref_root
, struct btrfs_extent_ref
, root
, 64);
823 BTRFS_SETGET_STACK_FUNCS(stack_ref_generation
, struct btrfs_extent_ref
,
825 BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid
, struct btrfs_extent_ref
,
827 BTRFS_SETGET_STACK_FUNCS(stack_ref_offset
, struct btrfs_extent_ref
, offset
, 64);
829 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs
, struct btrfs_extent_item
,
832 /* struct btrfs_node */
833 BTRFS_SETGET_FUNCS(key_blockptr
, struct btrfs_key_ptr
, blockptr
, 64);
834 BTRFS_SETGET_FUNCS(key_generation
, struct btrfs_key_ptr
, generation
, 64);
836 static inline u64
btrfs_node_blockptr(struct extent_buffer
*eb
, int nr
)
839 ptr
= offsetof(struct btrfs_node
, ptrs
) +
840 sizeof(struct btrfs_key_ptr
) * nr
;
841 return btrfs_key_blockptr(eb
, (struct btrfs_key_ptr
*)ptr
);
844 static inline void btrfs_set_node_blockptr(struct extent_buffer
*eb
,
848 ptr
= offsetof(struct btrfs_node
, ptrs
) +
849 sizeof(struct btrfs_key_ptr
) * nr
;
850 btrfs_set_key_blockptr(eb
, (struct btrfs_key_ptr
*)ptr
, val
);
853 static inline u64
btrfs_node_ptr_generation(struct extent_buffer
*eb
, int nr
)
856 ptr
= offsetof(struct btrfs_node
, ptrs
) +
857 sizeof(struct btrfs_key_ptr
) * nr
;
858 return btrfs_key_generation(eb
, (struct btrfs_key_ptr
*)ptr
);
861 static inline void btrfs_set_node_ptr_generation(struct extent_buffer
*eb
,
865 ptr
= offsetof(struct btrfs_node
, ptrs
) +
866 sizeof(struct btrfs_key_ptr
) * nr
;
867 btrfs_set_key_generation(eb
, (struct btrfs_key_ptr
*)ptr
, val
);
870 static inline unsigned long btrfs_node_key_ptr_offset(int nr
)
872 return offsetof(struct btrfs_node
, ptrs
) +
873 sizeof(struct btrfs_key_ptr
) * nr
;
876 static inline void btrfs_node_key(struct extent_buffer
*eb
,
877 struct btrfs_disk_key
*disk_key
, int nr
)
880 ptr
= btrfs_node_key_ptr_offset(nr
);
881 read_eb_member(eb
, (struct btrfs_key_ptr
*)ptr
,
882 struct btrfs_key_ptr
, key
, disk_key
);
885 static inline void btrfs_set_node_key(struct extent_buffer
*eb
,
886 struct btrfs_disk_key
*disk_key
, int nr
)
889 ptr
= btrfs_node_key_ptr_offset(nr
);
890 write_eb_member(eb
, (struct btrfs_key_ptr
*)ptr
,
891 struct btrfs_key_ptr
, key
, disk_key
);
894 /* struct btrfs_item */
895 BTRFS_SETGET_FUNCS(item_offset
, struct btrfs_item
, offset
, 32);
896 BTRFS_SETGET_FUNCS(item_size
, struct btrfs_item
, size
, 32);
898 static inline unsigned long btrfs_item_nr_offset(int nr
)
900 return offsetof(struct btrfs_leaf
, items
) +
901 sizeof(struct btrfs_item
) * nr
;
904 static inline struct btrfs_item
*btrfs_item_nr(struct extent_buffer
*eb
,
907 return (struct btrfs_item
*)btrfs_item_nr_offset(nr
);
910 static inline u32
btrfs_item_end(struct extent_buffer
*eb
,
911 struct btrfs_item
*item
)
913 return btrfs_item_offset(eb
, item
) + btrfs_item_size(eb
, item
);
916 static inline u32
btrfs_item_end_nr(struct extent_buffer
*eb
, int nr
)
918 return btrfs_item_end(eb
, btrfs_item_nr(eb
, nr
));
921 static inline u32
btrfs_item_offset_nr(struct extent_buffer
*eb
, int nr
)
923 return btrfs_item_offset(eb
, btrfs_item_nr(eb
, nr
));
926 static inline u32
btrfs_item_size_nr(struct extent_buffer
*eb
, int nr
)
928 return btrfs_item_size(eb
, btrfs_item_nr(eb
, nr
));
931 static inline void btrfs_item_key(struct extent_buffer
*eb
,
932 struct btrfs_disk_key
*disk_key
, int nr
)
934 struct btrfs_item
*item
= btrfs_item_nr(eb
, nr
);
935 read_eb_member(eb
, item
, struct btrfs_item
, key
, disk_key
);
938 static inline void btrfs_set_item_key(struct extent_buffer
*eb
,
939 struct btrfs_disk_key
*disk_key
, int nr
)
941 struct btrfs_item
*item
= btrfs_item_nr(eb
, nr
);
942 write_eb_member(eb
, item
, struct btrfs_item
, key
, disk_key
);
945 /* struct btrfs_dir_item */
946 BTRFS_SETGET_FUNCS(dir_data_len
, struct btrfs_dir_item
, data_len
, 16);
947 BTRFS_SETGET_FUNCS(dir_type
, struct btrfs_dir_item
, type
, 8);
948 BTRFS_SETGET_FUNCS(dir_name_len
, struct btrfs_dir_item
, name_len
, 16);
950 static inline void btrfs_dir_item_key(struct extent_buffer
*eb
,
951 struct btrfs_dir_item
*item
,
952 struct btrfs_disk_key
*key
)
954 read_eb_member(eb
, item
, struct btrfs_dir_item
, location
, key
);
957 static inline void btrfs_set_dir_item_key(struct extent_buffer
*eb
,
958 struct btrfs_dir_item
*item
,
959 struct btrfs_disk_key
*key
)
961 write_eb_member(eb
, item
, struct btrfs_dir_item
, location
, key
);
964 /* struct btrfs_disk_key */
965 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid
, struct btrfs_disk_key
,
967 BTRFS_SETGET_STACK_FUNCS(disk_key_offset
, struct btrfs_disk_key
, offset
, 64);
968 BTRFS_SETGET_STACK_FUNCS(disk_key_type
, struct btrfs_disk_key
, type
, 8);
970 static inline void btrfs_disk_key_to_cpu(struct btrfs_key
*cpu
,
971 struct btrfs_disk_key
*disk
)
973 cpu
->offset
= le64_to_cpu(disk
->offset
);
974 cpu
->type
= disk
->type
;
975 cpu
->objectid
= le64_to_cpu(disk
->objectid
);
978 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key
*disk
,
979 struct btrfs_key
*cpu
)
981 disk
->offset
= cpu_to_le64(cpu
->offset
);
982 disk
->type
= cpu
->type
;
983 disk
->objectid
= cpu_to_le64(cpu
->objectid
);
986 static inline void btrfs_node_key_to_cpu(struct extent_buffer
*eb
,
987 struct btrfs_key
*key
, int nr
)
989 struct btrfs_disk_key disk_key
;
990 btrfs_node_key(eb
, &disk_key
, nr
);
991 btrfs_disk_key_to_cpu(key
, &disk_key
);
994 static inline void btrfs_item_key_to_cpu(struct extent_buffer
*eb
,
995 struct btrfs_key
*key
, int nr
)
997 struct btrfs_disk_key disk_key
;
998 btrfs_item_key(eb
, &disk_key
, nr
);
999 btrfs_disk_key_to_cpu(key
, &disk_key
);
1002 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer
*eb
,
1003 struct btrfs_dir_item
*item
,
1004 struct btrfs_key
*key
)
1006 struct btrfs_disk_key disk_key
;
1007 btrfs_dir_item_key(eb
, item
, &disk_key
);
1008 btrfs_disk_key_to_cpu(key
, &disk_key
);
1012 static inline u8
btrfs_key_type(struct btrfs_key
*key
)
1017 static inline void btrfs_set_key_type(struct btrfs_key
*key
, u8 val
)
1022 /* struct btrfs_header */
1023 BTRFS_SETGET_HEADER_FUNCS(header_bytenr
, struct btrfs_header
, bytenr
, 64);
1024 BTRFS_SETGET_HEADER_FUNCS(header_generation
, struct btrfs_header
,
1026 BTRFS_SETGET_HEADER_FUNCS(header_owner
, struct btrfs_header
, owner
, 64);
1027 BTRFS_SETGET_HEADER_FUNCS(header_nritems
, struct btrfs_header
, nritems
, 32);
1028 BTRFS_SETGET_HEADER_FUNCS(header_flags
, struct btrfs_header
, flags
, 16);
1029 BTRFS_SETGET_HEADER_FUNCS(header_level
, struct btrfs_header
, level
, 8);
1031 static inline u8
*btrfs_header_fsid(struct extent_buffer
*eb
)
1033 unsigned long ptr
= offsetof(struct btrfs_header
, fsid
);
1037 static inline u8
*btrfs_super_fsid(struct extent_buffer
*eb
)
1039 unsigned long ptr
= offsetof(struct btrfs_super_block
, fsid
);
1043 static inline u8
*btrfs_header_csum(struct extent_buffer
*eb
)
1045 unsigned long ptr
= offsetof(struct btrfs_header
, csum
);
1049 static inline struct btrfs_node
*btrfs_buffer_node(struct extent_buffer
*eb
)
1054 static inline struct btrfs_leaf
*btrfs_buffer_leaf(struct extent_buffer
*eb
)
1059 static inline struct btrfs_header
*btrfs_buffer_header(struct extent_buffer
*eb
)
1064 static inline int btrfs_is_leaf(struct extent_buffer
*eb
)
1066 return (btrfs_header_level(eb
) == 0);
1069 /* struct btrfs_root_item */
1070 BTRFS_SETGET_FUNCS(disk_root_refs
, struct btrfs_root_item
, refs
, 32);
1071 BTRFS_SETGET_FUNCS(disk_root_bytenr
, struct btrfs_root_item
, bytenr
, 64);
1072 BTRFS_SETGET_FUNCS(disk_root_level
, struct btrfs_root_item
, level
, 8);
1074 BTRFS_SETGET_STACK_FUNCS(root_bytenr
, struct btrfs_root_item
, bytenr
, 64);
1075 BTRFS_SETGET_STACK_FUNCS(root_level
, struct btrfs_root_item
, level
, 8);
1076 BTRFS_SETGET_STACK_FUNCS(root_dirid
, struct btrfs_root_item
, root_dirid
, 64);
1077 BTRFS_SETGET_STACK_FUNCS(root_refs
, struct btrfs_root_item
, refs
, 32);
1078 BTRFS_SETGET_STACK_FUNCS(root_flags
, struct btrfs_root_item
, flags
, 32);
1079 BTRFS_SETGET_STACK_FUNCS(root_used
, struct btrfs_root_item
, bytes_used
, 64);
1080 BTRFS_SETGET_STACK_FUNCS(root_limit
, struct btrfs_root_item
, byte_limit
, 64);
1082 /* struct btrfs_super_block */
1083 BTRFS_SETGET_STACK_FUNCS(super_bytenr
, struct btrfs_super_block
, bytenr
, 64);
1084 BTRFS_SETGET_STACK_FUNCS(super_generation
, struct btrfs_super_block
,
1086 BTRFS_SETGET_STACK_FUNCS(super_root
, struct btrfs_super_block
, root
, 64);
1087 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size
,
1088 struct btrfs_super_block
, sys_chunk_array_size
, 32);
1089 BTRFS_SETGET_STACK_FUNCS(super_root_level
, struct btrfs_super_block
,
1091 BTRFS_SETGET_STACK_FUNCS(super_chunk_root
, struct btrfs_super_block
,
1093 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level
, struct btrfs_super_block
,
1094 chunk_root_level
, 64);
1095 BTRFS_SETGET_STACK_FUNCS(super_total_bytes
, struct btrfs_super_block
,
1097 BTRFS_SETGET_STACK_FUNCS(super_bytes_used
, struct btrfs_super_block
,
1099 BTRFS_SETGET_STACK_FUNCS(super_sectorsize
, struct btrfs_super_block
,
1101 BTRFS_SETGET_STACK_FUNCS(super_nodesize
, struct btrfs_super_block
,
1103 BTRFS_SETGET_STACK_FUNCS(super_leafsize
, struct btrfs_super_block
,
1105 BTRFS_SETGET_STACK_FUNCS(super_stripesize
, struct btrfs_super_block
,
1107 BTRFS_SETGET_STACK_FUNCS(super_root_dir
, struct btrfs_super_block
,
1108 root_dir_objectid
, 64);
1109 BTRFS_SETGET_STACK_FUNCS(super_num_devices
, struct btrfs_super_block
,
1112 static inline unsigned long btrfs_leaf_data(struct extent_buffer
*l
)
1114 return offsetof(struct btrfs_leaf
, items
);
1117 /* struct btrfs_file_extent_item */
1118 BTRFS_SETGET_FUNCS(file_extent_type
, struct btrfs_file_extent_item
, type
, 8);
1120 static inline unsigned long btrfs_file_extent_inline_start(struct
1121 btrfs_file_extent_item
*e
)
1123 unsigned long offset
= (unsigned long)e
;
1124 offset
+= offsetof(struct btrfs_file_extent_item
, disk_bytenr
);
1128 static inline u32
btrfs_file_extent_calc_inline_size(u32 datasize
)
1130 return offsetof(struct btrfs_file_extent_item
, disk_bytenr
) + datasize
;
1133 static inline u32
btrfs_file_extent_inline_len(struct extent_buffer
*eb
,
1134 struct btrfs_item
*e
)
1136 unsigned long offset
;
1137 offset
= offsetof(struct btrfs_file_extent_item
, disk_bytenr
);
1138 return btrfs_item_size(eb
, e
) - offset
;
1141 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr
, struct btrfs_file_extent_item
,
1143 BTRFS_SETGET_FUNCS(file_extent_generation
, struct btrfs_file_extent_item
,
1145 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes
, struct btrfs_file_extent_item
,
1146 disk_num_bytes
, 64);
1147 BTRFS_SETGET_FUNCS(file_extent_offset
, struct btrfs_file_extent_item
,
1149 BTRFS_SETGET_FUNCS(file_extent_num_bytes
, struct btrfs_file_extent_item
,
1152 static inline u32
btrfs_level_size(struct btrfs_root
*root
, int level
) {
1154 return root
->leafsize
;
1155 return root
->nodesize
;
1158 /* helper function to cast into the data area of the leaf. */
1159 #define btrfs_item_ptr(leaf, slot, type) \
1160 ((type *)(btrfs_leaf_data(leaf) + \
1161 btrfs_item_offset_nr(leaf, slot)))
1163 #define btrfs_item_ptr_offset(leaf, slot) \
1164 ((unsigned long)(btrfs_leaf_data(leaf) + \
1165 btrfs_item_offset_nr(leaf, slot)))
1168 u32
btrfs_count_snapshots_in_path(struct btrfs_root
*root
,
1169 struct btrfs_path
*count_path
,
1171 int btrfs_extent_post_op(struct btrfs_trans_handle
*trans
,
1172 struct btrfs_root
*root
);
1173 int btrfs_copy_pinned(struct btrfs_root
*root
, struct extent_io_tree
*copy
);
1174 struct btrfs_block_group_cache
*btrfs_lookup_block_group(struct
1175 btrfs_fs_info
*info
,
1177 struct btrfs_block_group_cache
*btrfs_find_block_group(struct btrfs_root
*root
,
1178 struct btrfs_block_group_cache
1179 *hint
, u64 search_start
,
1180 int data
, int owner
);
1181 int btrfs_inc_root_ref(struct btrfs_trans_handle
*trans
,
1182 struct btrfs_root
*root
, u64 owner_objectid
);
1183 struct extent_buffer
*btrfs_alloc_free_block(struct btrfs_trans_handle
*trans
,
1184 struct btrfs_root
*root
, u32 size
,
1186 u64 hint
, u64 empty_size
);
1187 struct extent_buffer
*__btrfs_alloc_free_block(struct btrfs_trans_handle
*trans
,
1188 struct btrfs_root
*root
,
1196 int btrfs_grow_extent_tree(struct btrfs_trans_handle
*trans
,
1197 struct btrfs_root
*root
, u64 new_size
);
1198 int btrfs_shrink_extent_tree(struct btrfs_root
*root
, u64 new_size
);
1199 int btrfs_insert_extent_backref(struct btrfs_trans_handle
*trans
,
1200 struct btrfs_root
*root
,
1201 struct btrfs_path
*path
, u64 bytenr
,
1202 u64 root_objectid
, u64 ref_generation
,
1203 u64 owner
, u64 owner_offset
);
1204 int btrfs_alloc_extent(struct btrfs_trans_handle
*trans
,
1205 struct btrfs_root
*root
,
1206 u64 num_bytes
, u64 root_objectid
, u64 ref_generation
,
1207 u64 owner
, u64 owner_offset
,
1208 u64 empty_size
, u64 hint_byte
,
1209 u64 search_end
, struct btrfs_key
*ins
, int data
);
1210 int btrfs_inc_ref(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
1211 struct extent_buffer
*buf
);
1212 int btrfs_free_extent(struct btrfs_trans_handle
*trans
, struct btrfs_root
1213 *root
, u64 bytenr
, u64 num_bytes
,
1214 u64 root_objectid
, u64 ref_generation
,
1215 u64 owner_objectid
, u64 owner_offset
, int pin
);
1216 int btrfs_finish_extent_commit(struct btrfs_trans_handle
*trans
,
1217 struct btrfs_root
*root
,
1218 struct extent_io_tree
*unpin
);
1219 int btrfs_inc_extent_ref(struct btrfs_trans_handle
*trans
,
1220 struct btrfs_root
*root
,
1221 u64 bytenr
, u64 num_bytes
,
1222 u64 root_objectid
, u64 ref_generation
,
1223 u64 owner
, u64 owner_offset
);
1224 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle
*trans
,
1225 struct btrfs_root
*root
);
1226 int btrfs_free_block_groups(struct btrfs_fs_info
*info
);
1227 int btrfs_read_block_groups(struct btrfs_root
*root
);
1228 int btrfs_make_block_group(struct btrfs_trans_handle
*trans
,
1229 struct btrfs_root
*root
, u64 bytes_used
,
1230 u64 type
, u64 chunk_tree
, u64 chunk_objectid
,
1232 u64
btrfs_hash_extent_ref(u64 root_objectid
, u64 ref_generation
,
1233 u64 owner
, u64 owner_offset
);
1234 int btrfs_update_block_group(struct btrfs_trans_handle
*trans
,
1235 struct btrfs_root
*root
, u64 bytenr
, u64 num
,
1236 int alloc
, int mark_free
);
1238 int btrfs_previous_item(struct btrfs_root
*root
,
1239 struct btrfs_path
*path
, u64 min_objectid
,
1241 int btrfs_comp_keys(struct btrfs_disk_key
*disk
, struct btrfs_key
*k2
);
1242 int btrfs_cow_block(struct btrfs_trans_handle
*trans
,
1243 struct btrfs_root
*root
, struct extent_buffer
*buf
,
1244 struct extent_buffer
*parent
, int parent_slot
,
1245 struct extent_buffer
**cow_ret
);
1246 int btrfs_copy_root(struct btrfs_trans_handle
*trans
,
1247 struct btrfs_root
*root
,
1248 struct extent_buffer
*buf
,
1249 struct extent_buffer
**cow_ret
, u64 new_root_objectid
);
1250 int btrfs_extend_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1251 *root
, struct btrfs_path
*path
, u32 data_size
);
1252 int btrfs_truncate_item(struct btrfs_trans_handle
*trans
,
1253 struct btrfs_root
*root
,
1254 struct btrfs_path
*path
,
1255 u32 new_size
, int from_end
);
1256 int btrfs_search_slot(struct btrfs_trans_handle
*trans
, struct btrfs_root
1257 *root
, struct btrfs_key
*key
, struct btrfs_path
*p
, int
1259 int btrfs_realloc_node(struct btrfs_trans_handle
*trans
,
1260 struct btrfs_root
*root
, struct extent_buffer
*parent
,
1261 int start_slot
, int cache_only
, u64
*last_ret
,
1262 struct btrfs_key
*progress
);
1263 void btrfs_release_path(struct btrfs_root
*root
, struct btrfs_path
*p
);
1264 struct btrfs_path
*btrfs_alloc_path(void);
1265 void btrfs_free_path(struct btrfs_path
*p
);
1266 void btrfs_init_path(struct btrfs_path
*p
);
1267 int btrfs_del_items(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
1268 struct btrfs_path
*path
, int slot
, int nr
);
1270 static inline int btrfs_del_item(struct btrfs_trans_handle
*trans
,
1271 struct btrfs_root
*root
,
1272 struct btrfs_path
*path
)
1274 return btrfs_del_items(trans
, root
, path
, path
->slots
[0], 1);
1277 int btrfs_insert_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1278 *root
, struct btrfs_key
*key
, void *data
, u32 data_size
);
1279 int btrfs_insert_empty_items(struct btrfs_trans_handle
*trans
,
1280 struct btrfs_root
*root
,
1281 struct btrfs_path
*path
,
1282 struct btrfs_key
*cpu_key
, u32
*data_size
, int nr
);
1284 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle
*trans
,
1285 struct btrfs_root
*root
,
1286 struct btrfs_path
*path
,
1287 struct btrfs_key
*key
,
1290 return btrfs_insert_empty_items(trans
, root
, path
, key
, &data_size
, 1);
1293 int btrfs_next_leaf(struct btrfs_root
*root
, struct btrfs_path
*path
);
1294 int btrfs_prev_leaf(struct btrfs_root
*root
, struct btrfs_path
*path
);
1295 int btrfs_leaf_free_space(struct btrfs_root
*root
, struct extent_buffer
*leaf
);
1296 int btrfs_drop_snapshot(struct btrfs_trans_handle
*trans
, struct btrfs_root
1301 int btrfs_del_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
1302 struct btrfs_key
*key
);
1303 int btrfs_insert_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
1304 *root
, struct btrfs_key
*key
, struct btrfs_root_item
1306 int btrfs_update_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
1307 *root
, struct btrfs_key
*key
, struct btrfs_root_item
1309 int btrfs_find_last_root(struct btrfs_root
*root
, u64 objectid
, struct
1310 btrfs_root_item
*item
, struct btrfs_key
*key
);
1311 int btrfs_find_dead_roots(struct btrfs_root
*root
, u64 objectid
,
1312 struct btrfs_root
*latest_root
);
1314 int btrfs_insert_dir_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1315 *root
, const char *name
, int name_len
, u64 dir
,
1316 struct btrfs_key
*location
, u8 type
);
1317 struct btrfs_dir_item
*btrfs_lookup_dir_item(struct btrfs_trans_handle
*trans
,
1318 struct btrfs_root
*root
,
1319 struct btrfs_path
*path
, u64 dir
,
1320 const char *name
, int name_len
,
1322 struct btrfs_dir_item
*
1323 btrfs_lookup_dir_index_item(struct btrfs_trans_handle
*trans
,
1324 struct btrfs_root
*root
,
1325 struct btrfs_path
*path
, u64 dir
,
1326 u64 objectid
, const char *name
, int name_len
,
1328 struct btrfs_dir_item
*btrfs_match_dir_item_name(struct btrfs_root
*root
,
1329 struct btrfs_path
*path
,
1330 const char *name
, int name_len
);
1331 int btrfs_delete_one_dir_name(struct btrfs_trans_handle
*trans
,
1332 struct btrfs_root
*root
,
1333 struct btrfs_path
*path
,
1334 struct btrfs_dir_item
*di
);
1335 int btrfs_insert_xattr_item(struct btrfs_trans_handle
*trans
,
1336 struct btrfs_root
*root
, const char *name
,
1337 u16 name_len
, const void *data
, u16 data_len
,
1339 struct btrfs_dir_item
*btrfs_lookup_xattr(struct btrfs_trans_handle
*trans
,
1340 struct btrfs_root
*root
,
1341 struct btrfs_path
*path
, u64 dir
,
1342 const char *name
, u16 name_len
,
1345 int btrfs_find_free_objectid(struct btrfs_trans_handle
*trans
,
1346 struct btrfs_root
*fs_root
,
1347 u64 dirid
, u64
*objectid
);
1348 int btrfs_find_highest_inode(struct btrfs_root
*fs_root
, u64
*objectid
);
1351 int btrfs_insert_inode_ref(struct btrfs_trans_handle
*trans
,
1352 struct btrfs_root
*root
,
1353 const char *name
, int name_len
,
1354 u64 inode_objectid
, u64 ref_objectid
);
1355 int btrfs_del_inode_ref(struct btrfs_trans_handle
*trans
,
1356 struct btrfs_root
*root
,
1357 const char *name
, int name_len
,
1358 u64 inode_objectid
, u64 ref_objectid
);
1359 int btrfs_insert_empty_inode(struct btrfs_trans_handle
*trans
,
1360 struct btrfs_root
*root
,
1361 struct btrfs_path
*path
, u64 objectid
);
1362 int btrfs_insert_inode(struct btrfs_trans_handle
*trans
, struct btrfs_root
1363 *root
, u64 objectid
, struct btrfs_inode_item
1365 int btrfs_lookup_inode(struct btrfs_trans_handle
*trans
, struct btrfs_root
1366 *root
, struct btrfs_path
*path
,
1367 struct btrfs_key
*location
, int mod
);
1370 int btrfs_insert_file_extent(struct btrfs_trans_handle
*trans
,
1371 struct btrfs_root
*root
,
1372 u64 objectid
, u64 pos
, u64 offset
,
1375 int btrfs_insert_inline_extent(struct btrfs_trans_handle
*trans
,
1376 struct btrfs_root
*root
, u64 objectid
,
1377 u64 offset
, char *buffer
, size_t size
);
1378 int btrfs_lookup_file_extent(struct btrfs_trans_handle
*trans
,
1379 struct btrfs_root
*root
,
1380 struct btrfs_path
*path
, u64 objectid
,
1381 u64 bytenr
, int mod
);
1382 int btrfs_csum_file_block(struct btrfs_trans_handle
*trans
,
1383 struct btrfs_root
*root
,
1384 struct btrfs_inode_item
*inode
,
1385 u64 objectid
, u64 offset
,
1386 char *data
, size_t len
);
1387 struct btrfs_csum_item
*btrfs_lookup_csum(struct btrfs_trans_handle
*trans
,
1388 struct btrfs_root
*root
,
1389 struct btrfs_path
*path
,
1390 u64 objectid
, u64 offset
,
1392 int btrfs_csum_truncate(struct btrfs_trans_handle
*trans
,
1393 struct btrfs_root
*root
, struct btrfs_path
*path
,