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 "_B5RfS_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
62 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
66 * the device items go into the chunk tree. The key is in the form
67 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
69 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
72 * we can actually store much bigger names, but lets not confuse the rest
75 #define BTRFS_NAME_LEN 255
77 /* 32 bytes in various csum fields */
78 #define BTRFS_CSUM_SIZE 32
79 /* four bytes for CRC32 */
80 #define BTRFS_CRC32_SIZE 4
81 #define BTRFS_EMPTY_DIR_SIZE 0
83 #define BTRFS_FT_UNKNOWN 0
84 #define BTRFS_FT_REG_FILE 1
85 #define BTRFS_FT_DIR 2
86 #define BTRFS_FT_CHRDEV 3
87 #define BTRFS_FT_BLKDEV 4
88 #define BTRFS_FT_FIFO 5
89 #define BTRFS_FT_SOCK 6
90 #define BTRFS_FT_SYMLINK 7
91 #define BTRFS_FT_XATTR 8
92 #define BTRFS_FT_MAX 9
95 * the key defines the order in the tree, and so it also defines (optimal)
96 * block layout. objectid corresonds to the inode number. The flags
97 * tells us things about the object, and is a kind of stream selector.
98 * so for a given inode, keys with flags of 1 might refer to the inode
99 * data, flags of 2 may point to file data in the btree and flags == 3
100 * may point to extents.
102 * offset is the starting byte offset for this key in the stream.
104 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
105 * in cpu native order. Otherwise they are identical and their sizes
106 * should be the same (ie both packed)
108 struct btrfs_disk_key
{
112 } __attribute__ ((__packed__
));
118 } __attribute__ ((__packed__
));
120 struct btrfs_mapping_tree
{
121 struct cache_tree cache_tree
;
124 #define BTRFS_UUID_SIZE 16
125 struct btrfs_dev_item
{
126 /* the internal btrfs device id */
129 /* size of the device */
135 /* optimal io alignment for this device */
138 /* optimal io width for this device */
141 /* minimal io size for this device */
144 /* type and info about this device */
147 /* grouping information for allocation decisions */
150 /* seek speed 0-100 where 100 is fastest */
153 /* bandwidth 0-100 where 100 is fastest */
156 /* btrfs generated uuid for this device */
157 u8 uuid
[BTRFS_UUID_SIZE
];
158 } __attribute__ ((__packed__
));
160 struct btrfs_stripe
{
163 u8 dev_uuid
[BTRFS_UUID_SIZE
];
164 } __attribute__ ((__packed__
));
167 /* size of this chunk in bytes */
170 /* objectid of the root referencing this chunk */
176 /* optimal io alignment for this chunk */
179 /* optimal io width for this chunk */
182 /* minimal io size for this chunk */
185 /* 2^16 stripes is quite a lot, a second limit is the size of a single
190 /* sub stripes only matter for raid10 */
192 struct btrfs_stripe stripe
;
193 /* additional stripes go here */
194 } __attribute__ ((__packed__
));
196 static inline unsigned long btrfs_chunk_item_size(int num_stripes
)
198 BUG_ON(num_stripes
== 0);
199 return sizeof(struct btrfs_chunk
) +
200 sizeof(struct btrfs_stripe
) * (num_stripes
- 1);
203 #define BTRFS_FSID_SIZE 16
204 #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
207 * every tree block (leaf or node) starts with this header.
209 struct btrfs_header
{
210 /* these first four must match the super block */
211 u8 csum
[BTRFS_CSUM_SIZE
];
212 u8 fsid
[BTRFS_FSID_SIZE
]; /* FS specific uuid */
213 __le64 bytenr
; /* which block this node is supposed to live in */
216 /* allowed to be different from the super from here on down */
217 u8 chunk_tree_uuid
[BTRFS_UUID_SIZE
];
222 } __attribute__ ((__packed__
));
224 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
225 sizeof(struct btrfs_header)) / \
226 sizeof(struct btrfs_key_ptr))
227 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
228 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
229 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
230 sizeof(struct btrfs_item) - \
231 sizeof(struct btrfs_file_extent_item))
234 * this is a very generous portion of the super block, giving us
235 * room to translate 14 chunks with 3 stripes each.
237 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
240 * the super block basically lists the main trees of the FS
241 * it currently lacks any block count etc etc
243 struct btrfs_super_block
{
244 u8 csum
[BTRFS_CSUM_SIZE
];
245 /* the first 3 fields must match struct btrfs_header */
246 u8 fsid
[BTRFS_FSID_SIZE
]; /* FS specific uuid */
247 __le64 bytenr
; /* this block number */
250 /* allowed to be different from the btrfs_header from here own down */
257 __le64 root_dir_objectid
;
263 __le32 sys_chunk_array_size
;
266 struct btrfs_dev_item dev_item
;
267 u8 sys_chunk_array
[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE
];
268 } __attribute__ ((__packed__
));
271 * A leaf is full of items. offset and size tell us where to find
272 * the item in the leaf (relative to the start of the data area)
275 struct btrfs_disk_key key
;
278 } __attribute__ ((__packed__
));
281 * leaves have an item area and a data area:
282 * [item0, item1....itemN] [free space] [dataN...data1, data0]
284 * The data is separate from the items to get the keys closer together
288 struct btrfs_header header
;
289 struct btrfs_item items
[];
290 } __attribute__ ((__packed__
));
293 * all non-leaf blocks are nodes, they hold only keys and pointers to
296 struct btrfs_key_ptr
{
297 struct btrfs_disk_key key
;
300 } __attribute__ ((__packed__
));
303 struct btrfs_header header
;
304 struct btrfs_key_ptr ptrs
[];
305 } __attribute__ ((__packed__
));
308 * btrfs_paths remember the path taken from the root down to the leaf.
309 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
310 * to any other levels that are present.
312 * The slots array records the index of the item or block pointer
313 * used while walking the tree.
316 struct extent_buffer
*nodes
[BTRFS_MAX_LEVEL
];
317 int slots
[BTRFS_MAX_LEVEL
];
323 * items in the extent btree are used to record the objectid of the
324 * owner of the block and the number of references
326 struct btrfs_extent_item
{
328 } __attribute__ ((__packed__
));
330 struct btrfs_extent_ref
{
335 } __attribute__ ((__packed__
));
337 /* dev extents record free space on individual devices. The owner
338 * field points back to the chunk allocation mapping tree that allocated
339 * the extent. The chunk tree uuid field is a way to double check the owner
341 struct btrfs_dev_extent
{
343 __le64 chunk_objectid
;
346 u8 chunk_tree_uuid
[BTRFS_UUID_SIZE
];
347 } __attribute__ ((__packed__
));
349 struct btrfs_inode_ref
{
352 } __attribute__ ((__packed__
));
354 struct btrfs_timespec
{
357 } __attribute__ ((__packed__
));
360 * there is no padding here on purpose. If you want to extent the inode,
361 * make a new item type
363 struct btrfs_inode_item
{
375 struct btrfs_timespec atime
;
376 struct btrfs_timespec ctime
;
377 struct btrfs_timespec mtime
;
378 struct btrfs_timespec otime
;
379 } __attribute__ ((__packed__
));
381 struct btrfs_dir_item
{
382 struct btrfs_disk_key location
;
386 } __attribute__ ((__packed__
));
388 struct btrfs_root_item
{
389 struct btrfs_inode_item inode
;
396 struct btrfs_disk_key drop_progress
;
399 } __attribute__ ((__packed__
));
401 #define BTRFS_FILE_EXTENT_REG 0
402 #define BTRFS_FILE_EXTENT_INLINE 1
404 struct btrfs_file_extent_item
{
408 * disk space consumed by the extent, checksum blocks are included
412 __le64 disk_num_bytes
;
414 * the logical offset in file blocks (no csums)
415 * this extent record is for. This allows a file extent to point
416 * into the middle of an existing extent on disk, sharing it
417 * between two snapshots (useful if some bytes in the middle of the
418 * extent have changed
422 * the logical number of file blocks (no csums included)
425 } __attribute__ ((__packed__
));
427 struct btrfs_csum_item
{
429 } __attribute__ ((__packed__
));
431 /* tag for the radix tree of block groups in ram */
432 #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
433 #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
434 #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
435 #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
436 #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
437 #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
438 #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
440 struct btrfs_block_group_item
{
442 __le64 chunk_objectid
;
444 } __attribute__ ((__packed__
));
446 struct btrfs_space_info
{
452 struct list_head list
;
455 struct btrfs_block_group_cache
{
456 struct cache_extent cache
;
457 struct btrfs_key key
;
458 struct btrfs_block_group_item item
;
459 struct btrfs_space_info
*space_info
;
465 struct btrfs_extent_ops
{
466 int (*alloc_extent
)(struct btrfs_root
*root
, u64 num_bytes
,
467 u64 hint_byte
, struct btrfs_key
*ins
);
468 int (*free_extent
)(struct btrfs_root
*root
, u64 bytenr
,
473 struct btrfs_fs_devices
;
474 struct btrfs_fs_info
{
475 u8 fsid
[BTRFS_FSID_SIZE
];
476 u8 chunk_tree_uuid
[BTRFS_UUID_SIZE
];
477 struct btrfs_root
*fs_root
;
478 struct btrfs_root
*extent_root
;
479 struct btrfs_root
*tree_root
;
480 struct btrfs_root
*chunk_root
;
481 struct btrfs_root
*dev_root
;
483 struct extent_io_tree extent_cache
;
484 struct extent_io_tree free_space_cache
;
485 struct extent_io_tree block_group_cache
;
486 struct extent_io_tree pinned_extents
;
487 struct extent_io_tree pending_del
;
488 struct extent_io_tree extent_ins
;
490 /* logical->physical extent mapping */
491 struct btrfs_mapping_tree mapping_tree
;
494 u64 last_trans_committed
;
496 u64 avail_data_alloc_bits
;
497 u64 avail_metadata_alloc_bits
;
498 u64 avail_system_alloc_bits
;
499 u64 data_alloc_profile
;
500 u64 metadata_alloc_profile
;
501 u64 system_alloc_profile
;
503 struct btrfs_trans_handle
*running_transaction
;
504 struct btrfs_super_block super_copy
;
505 struct extent_buffer
*sb_buffer
;
506 struct mutex fs_mutex
;
509 struct btrfs_extent_ops
*extent_ops
;
510 struct list_head dirty_cowonly_roots
;
512 struct btrfs_fs_devices
*fs_devices
;
513 struct list_head space_info
;
515 int force_system_allocs
;
520 * in ram representation of the tree. extent_root is used for all allocations
521 * and for the extent tree extent_root root.
524 struct extent_buffer
*node
;
525 struct extent_buffer
*commit_root
;
526 struct btrfs_root_item root_item
;
527 struct btrfs_key root_key
;
528 struct btrfs_fs_info
*fs_info
;
532 /* data allocations are done in sectorsize units */
535 /* node allocations are done in nodesize units */
538 /* leaf allocations are done in leafsize units */
541 /* leaf allocations are done in leafsize units */
550 u64 last_inode_alloc
;
552 /* the dirty list is only used by non-reference counted roots */
553 struct list_head dirty_list
;
557 * inode items have the data typically returned from stat and store other
558 * info about object characteristics. There is one for every file and dir in
561 #define BTRFS_INODE_ITEM_KEY 1
562 #define BTRFS_INODE_REF_KEY 2
563 #define BTRFS_XATTR_ITEM_KEY 8
565 /* reserve 3-15 close to the inode for later flexibility */
568 * dir items are the name -> inode pointers in a directory. There is one
569 * for every name in a directory.
571 #define BTRFS_DIR_ITEM_KEY 16
572 #define BTRFS_DIR_INDEX_KEY 17
574 * extent data is for file data
576 #define BTRFS_EXTENT_DATA_KEY 18
578 * csum items have the checksums for data in the extents
580 #define BTRFS_CSUM_ITEM_KEY 19
582 /* reserve 20-31 for other file stuff */
585 * root items point to tree roots. There are typically in the root
586 * tree used by the super block to find all the other trees
588 #define BTRFS_ROOT_ITEM_KEY 32
590 * extent items are in the extent map tree. These record which blocks
591 * are used, and how many references there are to each block
593 #define BTRFS_EXTENT_ITEM_KEY 33
594 #define BTRFS_EXTENT_REF_KEY 34
597 * block groups give us hints into the extent allocation trees. Which
598 * blocks are free etc etc
600 #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
602 #define BTRFS_DEV_EXTENT_KEY 75
603 #define BTRFS_DEV_ITEM_KEY 76
604 #define BTRFS_CHUNK_ITEM_KEY 77
607 * string items are for debugging. They just store a short string of
610 #define BTRFS_STRING_ITEM_KEY 253
614 #define BTRFS_INODE_NODATASUM (1 << 0)
615 #define BTRFS_INODE_NODATACOW (1 << 1)
616 #define BTRFS_INODE_READONLY (1 << 2)
618 #define read_eb_member(eb, ptr, type, member, result) ( \
619 read_extent_buffer(eb, (char *)(result), \
620 ((unsigned long)(ptr)) + \
621 offsetof(type, member), \
622 sizeof(((type *)0)->member)))
624 #define write_eb_member(eb, ptr, type, member, result) ( \
625 write_extent_buffer(eb, (char *)(result), \
626 ((unsigned long)(ptr)) + \
627 offsetof(type, member), \
628 sizeof(((type *)0)->member)))
630 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
631 static inline u##bits btrfs_##name(struct extent_buffer *eb) \
633 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
634 return le##bits##_to_cpu(h->member); \
636 static inline void btrfs_set_##name(struct extent_buffer *eb, \
639 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
640 h->member = cpu_to_le##bits(val); \
643 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
644 static inline u##bits btrfs_##name(struct extent_buffer *eb, \
647 unsigned long offset = (unsigned long)s; \
648 type *p = (type *) (eb->data + offset); \
649 return le##bits##_to_cpu(p->member); \
651 static inline void btrfs_set_##name(struct extent_buffer *eb, \
652 type *s, u##bits val) \
654 unsigned long offset = (unsigned long)s; \
655 type *p = (type *) (eb->data + offset); \
656 p->member = cpu_to_le##bits(val); \
659 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
660 static inline u##bits btrfs_##name(type *s) \
662 return le##bits##_to_cpu(s->member); \
664 static inline void btrfs_set_##name(type *s, u##bits val) \
666 s->member = cpu_to_le##bits(val); \
669 BTRFS_SETGET_FUNCS(device_type
, struct btrfs_dev_item
, type
, 64);
670 BTRFS_SETGET_FUNCS(device_total_bytes
, struct btrfs_dev_item
, total_bytes
, 64);
671 BTRFS_SETGET_FUNCS(device_bytes_used
, struct btrfs_dev_item
, bytes_used
, 64);
672 BTRFS_SETGET_FUNCS(device_io_align
, struct btrfs_dev_item
, io_align
, 32);
673 BTRFS_SETGET_FUNCS(device_io_width
, struct btrfs_dev_item
, io_width
, 32);
674 BTRFS_SETGET_FUNCS(device_sector_size
, struct btrfs_dev_item
, sector_size
, 32);
675 BTRFS_SETGET_FUNCS(device_id
, struct btrfs_dev_item
, devid
, 64);
676 BTRFS_SETGET_FUNCS(device_group
, struct btrfs_dev_item
, dev_group
, 32);
677 BTRFS_SETGET_FUNCS(device_seek_speed
, struct btrfs_dev_item
, seek_speed
, 8);
678 BTRFS_SETGET_FUNCS(device_bandwidth
, struct btrfs_dev_item
, bandwidth
, 8);
680 BTRFS_SETGET_STACK_FUNCS(stack_device_type
, struct btrfs_dev_item
, type
, 64);
681 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes
, struct btrfs_dev_item
,
683 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used
, struct btrfs_dev_item
,
685 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align
, struct btrfs_dev_item
,
687 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width
, struct btrfs_dev_item
,
689 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size
, struct btrfs_dev_item
,
691 BTRFS_SETGET_STACK_FUNCS(stack_device_id
, struct btrfs_dev_item
, devid
, 64);
692 BTRFS_SETGET_STACK_FUNCS(stack_device_group
, struct btrfs_dev_item
,
694 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed
, struct btrfs_dev_item
,
696 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth
, struct btrfs_dev_item
,
699 static inline char *btrfs_device_uuid(struct btrfs_dev_item
*d
)
701 return (char *)d
+ offsetof(struct btrfs_dev_item
, uuid
);
704 BTRFS_SETGET_FUNCS(chunk_length
, struct btrfs_chunk
, length
, 64);
705 BTRFS_SETGET_FUNCS(chunk_owner
, struct btrfs_chunk
, owner
, 64);
706 BTRFS_SETGET_FUNCS(chunk_stripe_len
, struct btrfs_chunk
, stripe_len
, 64);
707 BTRFS_SETGET_FUNCS(chunk_io_align
, struct btrfs_chunk
, io_align
, 32);
708 BTRFS_SETGET_FUNCS(chunk_io_width
, struct btrfs_chunk
, io_width
, 32);
709 BTRFS_SETGET_FUNCS(chunk_sector_size
, struct btrfs_chunk
, sector_size
, 32);
710 BTRFS_SETGET_FUNCS(chunk_type
, struct btrfs_chunk
, type
, 64);
711 BTRFS_SETGET_FUNCS(chunk_num_stripes
, struct btrfs_chunk
, num_stripes
, 16);
712 BTRFS_SETGET_FUNCS(chunk_sub_stripes
, struct btrfs_chunk
, sub_stripes
, 16);
713 BTRFS_SETGET_FUNCS(stripe_devid
, struct btrfs_stripe
, devid
, 64);
714 BTRFS_SETGET_FUNCS(stripe_offset
, struct btrfs_stripe
, offset
, 64);
716 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe
*s
)
718 return (char *)s
+ offsetof(struct btrfs_stripe
, dev_uuid
);
721 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length
, struct btrfs_chunk
, length
, 64);
722 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner
, struct btrfs_chunk
, owner
, 64);
723 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len
, struct btrfs_chunk
,
725 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align
, struct btrfs_chunk
,
727 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width
, struct btrfs_chunk
,
729 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size
, struct btrfs_chunk
,
731 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type
, struct btrfs_chunk
, type
, 64);
732 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes
, struct btrfs_chunk
,
734 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes
, struct btrfs_chunk
,
736 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid
, struct btrfs_stripe
, devid
, 64);
737 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset
, struct btrfs_stripe
, offset
, 64);
739 static inline struct btrfs_stripe
*btrfs_stripe_nr(struct btrfs_chunk
*c
,
742 unsigned long offset
= (unsigned long)c
;
743 offset
+= offsetof(struct btrfs_chunk
, stripe
);
744 offset
+= nr
* sizeof(struct btrfs_stripe
);
745 return (struct btrfs_stripe
*)offset
;
748 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk
*c
, int nr
)
750 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c
, nr
));
753 static inline u64
btrfs_stripe_offset_nr(struct extent_buffer
*eb
,
754 struct btrfs_chunk
*c
, int nr
)
756 return btrfs_stripe_offset(eb
, btrfs_stripe_nr(c
, nr
));
759 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer
*eb
,
760 struct btrfs_chunk
*c
, int nr
,
763 btrfs_set_stripe_offset(eb
, btrfs_stripe_nr(c
, nr
), val
);
766 static inline u64
btrfs_stripe_devid_nr(struct extent_buffer
*eb
,
767 struct btrfs_chunk
*c
, int nr
)
769 return btrfs_stripe_devid(eb
, btrfs_stripe_nr(c
, nr
));
772 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer
*eb
,
773 struct btrfs_chunk
*c
, int nr
,
776 btrfs_set_stripe_devid(eb
, btrfs_stripe_nr(c
, nr
), val
);
779 /* struct btrfs_block_group_item */
780 BTRFS_SETGET_STACK_FUNCS(block_group_used
, struct btrfs_block_group_item
,
782 BTRFS_SETGET_FUNCS(disk_block_group_used
, struct btrfs_block_group_item
,
784 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid
,
785 struct btrfs_block_group_item
, chunk_objectid
, 64);
787 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid
,
788 struct btrfs_block_group_item
, chunk_objectid
, 64);
789 BTRFS_SETGET_FUNCS(disk_block_group_flags
,
790 struct btrfs_block_group_item
, flags
, 64);
791 BTRFS_SETGET_STACK_FUNCS(block_group_flags
,
792 struct btrfs_block_group_item
, flags
, 64);
794 /* struct btrfs_inode_ref */
795 BTRFS_SETGET_FUNCS(inode_ref_name_len
, struct btrfs_inode_ref
, name_len
, 16);
797 /* struct btrfs_inode_item */
798 BTRFS_SETGET_FUNCS(inode_generation
, struct btrfs_inode_item
, generation
, 64);
799 BTRFS_SETGET_FUNCS(inode_size
, struct btrfs_inode_item
, size
, 64);
800 BTRFS_SETGET_FUNCS(inode_nblocks
, struct btrfs_inode_item
, nblocks
, 64);
801 BTRFS_SETGET_FUNCS(inode_block_group
, struct btrfs_inode_item
, block_group
, 64);
802 BTRFS_SETGET_FUNCS(inode_nlink
, struct btrfs_inode_item
, nlink
, 32);
803 BTRFS_SETGET_FUNCS(inode_uid
, struct btrfs_inode_item
, uid
, 32);
804 BTRFS_SETGET_FUNCS(inode_gid
, struct btrfs_inode_item
, gid
, 32);
805 BTRFS_SETGET_FUNCS(inode_mode
, struct btrfs_inode_item
, mode
, 32);
806 BTRFS_SETGET_FUNCS(inode_rdev
, struct btrfs_inode_item
, rdev
, 64);
807 BTRFS_SETGET_FUNCS(inode_flags
, struct btrfs_inode_item
, flags
, 16);
808 BTRFS_SETGET_FUNCS(inode_compat_flags
, struct btrfs_inode_item
,
811 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation
,
812 struct btrfs_inode_item
, generation
, 64);
813 BTRFS_SETGET_STACK_FUNCS(stack_inode_size
,
814 struct btrfs_inode_item
, size
, 64);
815 BTRFS_SETGET_STACK_FUNCS(stack_inode_nblocks
,
816 struct btrfs_inode_item
, nblocks
, 64);
817 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group
,
818 struct btrfs_inode_item
, block_group
, 64);
819 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink
,
820 struct btrfs_inode_item
, nlink
, 32);
821 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid
,
822 struct btrfs_inode_item
, uid
, 32);
823 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid
,
824 struct btrfs_inode_item
, gid
, 32);
825 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode
,
826 struct btrfs_inode_item
, mode
, 32);
827 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev
,
828 struct btrfs_inode_item
, rdev
, 64);
829 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags
,
830 struct btrfs_inode_item
, flags
, 16);
831 BTRFS_SETGET_STACK_FUNCS(stack_inode_compat_flags
,
832 struct btrfs_inode_item
, compat_flags
, 16);
834 static inline struct btrfs_timespec
*
835 btrfs_inode_atime(struct btrfs_inode_item
*inode_item
)
837 unsigned long ptr
= (unsigned long)inode_item
;
838 ptr
+= offsetof(struct btrfs_inode_item
, atime
);
839 return (struct btrfs_timespec
*)ptr
;
842 static inline struct btrfs_timespec
*
843 btrfs_inode_mtime(struct btrfs_inode_item
*inode_item
)
845 unsigned long ptr
= (unsigned long)inode_item
;
846 ptr
+= offsetof(struct btrfs_inode_item
, mtime
);
847 return (struct btrfs_timespec
*)ptr
;
850 static inline struct btrfs_timespec
*
851 btrfs_inode_ctime(struct btrfs_inode_item
*inode_item
)
853 unsigned long ptr
= (unsigned long)inode_item
;
854 ptr
+= offsetof(struct btrfs_inode_item
, ctime
);
855 return (struct btrfs_timespec
*)ptr
;
858 static inline struct btrfs_timespec
*
859 btrfs_inode_otime(struct btrfs_inode_item
*inode_item
)
861 unsigned long ptr
= (unsigned long)inode_item
;
862 ptr
+= offsetof(struct btrfs_inode_item
, otime
);
863 return (struct btrfs_timespec
*)ptr
;
866 BTRFS_SETGET_FUNCS(timespec_sec
, struct btrfs_timespec
, sec
, 64);
867 BTRFS_SETGET_FUNCS(timespec_nsec
, struct btrfs_timespec
, nsec
, 32);
868 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec
, struct btrfs_timespec
,
870 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec
, struct btrfs_timespec
,
873 /* struct btrfs_dev_extent */
874 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree
, struct btrfs_dev_extent
,
876 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid
, struct btrfs_dev_extent
,
878 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset
, struct btrfs_dev_extent
,
880 BTRFS_SETGET_FUNCS(dev_extent_length
, struct btrfs_dev_extent
, length
, 64);
882 static inline u8
*btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent
*dev
)
884 unsigned long ptr
= offsetof(struct btrfs_dev_extent
, chunk_tree_uuid
);
885 return (u8
*)((unsigned long)dev
+ ptr
);
888 /* struct btrfs_extent_item */
889 BTRFS_SETGET_FUNCS(extent_refs
, struct btrfs_extent_item
, refs
, 32);
891 /* struct btrfs_extent_ref */
892 BTRFS_SETGET_FUNCS(ref_root
, struct btrfs_extent_ref
, root
, 64);
893 BTRFS_SETGET_FUNCS(ref_generation
, struct btrfs_extent_ref
, generation
, 64);
894 BTRFS_SETGET_FUNCS(ref_objectid
, struct btrfs_extent_ref
, objectid
, 64);
895 BTRFS_SETGET_FUNCS(ref_offset
, struct btrfs_extent_ref
, offset
, 64);
897 BTRFS_SETGET_STACK_FUNCS(stack_ref_root
, struct btrfs_extent_ref
, root
, 64);
898 BTRFS_SETGET_STACK_FUNCS(stack_ref_generation
, struct btrfs_extent_ref
,
900 BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid
, struct btrfs_extent_ref
,
902 BTRFS_SETGET_STACK_FUNCS(stack_ref_offset
, struct btrfs_extent_ref
, offset
, 64);
904 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs
, struct btrfs_extent_item
,
907 /* struct btrfs_node */
908 BTRFS_SETGET_FUNCS(key_blockptr
, struct btrfs_key_ptr
, blockptr
, 64);
909 BTRFS_SETGET_FUNCS(key_generation
, struct btrfs_key_ptr
, generation
, 64);
911 static inline u64
btrfs_node_blockptr(struct extent_buffer
*eb
, int nr
)
914 ptr
= offsetof(struct btrfs_node
, ptrs
) +
915 sizeof(struct btrfs_key_ptr
) * nr
;
916 return btrfs_key_blockptr(eb
, (struct btrfs_key_ptr
*)ptr
);
919 static inline void btrfs_set_node_blockptr(struct extent_buffer
*eb
,
923 ptr
= offsetof(struct btrfs_node
, ptrs
) +
924 sizeof(struct btrfs_key_ptr
) * nr
;
925 btrfs_set_key_blockptr(eb
, (struct btrfs_key_ptr
*)ptr
, val
);
928 static inline u64
btrfs_node_ptr_generation(struct extent_buffer
*eb
, int nr
)
931 ptr
= offsetof(struct btrfs_node
, ptrs
) +
932 sizeof(struct btrfs_key_ptr
) * nr
;
933 return btrfs_key_generation(eb
, (struct btrfs_key_ptr
*)ptr
);
936 static inline void btrfs_set_node_ptr_generation(struct extent_buffer
*eb
,
940 ptr
= offsetof(struct btrfs_node
, ptrs
) +
941 sizeof(struct btrfs_key_ptr
) * nr
;
942 btrfs_set_key_generation(eb
, (struct btrfs_key_ptr
*)ptr
, val
);
945 static inline unsigned long btrfs_node_key_ptr_offset(int nr
)
947 return offsetof(struct btrfs_node
, ptrs
) +
948 sizeof(struct btrfs_key_ptr
) * nr
;
951 static inline void btrfs_node_key(struct extent_buffer
*eb
,
952 struct btrfs_disk_key
*disk_key
, int nr
)
955 ptr
= btrfs_node_key_ptr_offset(nr
);
956 read_eb_member(eb
, (struct btrfs_key_ptr
*)ptr
,
957 struct btrfs_key_ptr
, key
, disk_key
);
960 static inline void btrfs_set_node_key(struct extent_buffer
*eb
,
961 struct btrfs_disk_key
*disk_key
, int nr
)
964 ptr
= btrfs_node_key_ptr_offset(nr
);
965 write_eb_member(eb
, (struct btrfs_key_ptr
*)ptr
,
966 struct btrfs_key_ptr
, key
, disk_key
);
969 /* struct btrfs_item */
970 BTRFS_SETGET_FUNCS(item_offset
, struct btrfs_item
, offset
, 32);
971 BTRFS_SETGET_FUNCS(item_size
, struct btrfs_item
, size
, 32);
973 static inline unsigned long btrfs_item_nr_offset(int nr
)
975 return offsetof(struct btrfs_leaf
, items
) +
976 sizeof(struct btrfs_item
) * nr
;
979 static inline struct btrfs_item
*btrfs_item_nr(struct extent_buffer
*eb
,
982 return (struct btrfs_item
*)btrfs_item_nr_offset(nr
);
985 static inline u32
btrfs_item_end(struct extent_buffer
*eb
,
986 struct btrfs_item
*item
)
988 return btrfs_item_offset(eb
, item
) + btrfs_item_size(eb
, item
);
991 static inline u32
btrfs_item_end_nr(struct extent_buffer
*eb
, int nr
)
993 return btrfs_item_end(eb
, btrfs_item_nr(eb
, nr
));
996 static inline u32
btrfs_item_offset_nr(struct extent_buffer
*eb
, int nr
)
998 return btrfs_item_offset(eb
, btrfs_item_nr(eb
, nr
));
1001 static inline u32
btrfs_item_size_nr(struct extent_buffer
*eb
, int nr
)
1003 return btrfs_item_size(eb
, btrfs_item_nr(eb
, nr
));
1006 static inline void btrfs_item_key(struct extent_buffer
*eb
,
1007 struct btrfs_disk_key
*disk_key
, int nr
)
1009 struct btrfs_item
*item
= btrfs_item_nr(eb
, nr
);
1010 read_eb_member(eb
, item
, struct btrfs_item
, key
, disk_key
);
1013 static inline void btrfs_set_item_key(struct extent_buffer
*eb
,
1014 struct btrfs_disk_key
*disk_key
, int nr
)
1016 struct btrfs_item
*item
= btrfs_item_nr(eb
, nr
);
1017 write_eb_member(eb
, item
, struct btrfs_item
, key
, disk_key
);
1020 /* struct btrfs_dir_item */
1021 BTRFS_SETGET_FUNCS(dir_data_len
, struct btrfs_dir_item
, data_len
, 16);
1022 BTRFS_SETGET_FUNCS(dir_type
, struct btrfs_dir_item
, type
, 8);
1023 BTRFS_SETGET_FUNCS(dir_name_len
, struct btrfs_dir_item
, name_len
, 16);
1025 static inline void btrfs_dir_item_key(struct extent_buffer
*eb
,
1026 struct btrfs_dir_item
*item
,
1027 struct btrfs_disk_key
*key
)
1029 read_eb_member(eb
, item
, struct btrfs_dir_item
, location
, key
);
1032 static inline void btrfs_set_dir_item_key(struct extent_buffer
*eb
,
1033 struct btrfs_dir_item
*item
,
1034 struct btrfs_disk_key
*key
)
1036 write_eb_member(eb
, item
, struct btrfs_dir_item
, location
, key
);
1039 /* struct btrfs_disk_key */
1040 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid
, struct btrfs_disk_key
,
1042 BTRFS_SETGET_STACK_FUNCS(disk_key_offset
, struct btrfs_disk_key
, offset
, 64);
1043 BTRFS_SETGET_STACK_FUNCS(disk_key_type
, struct btrfs_disk_key
, type
, 8);
1045 static inline void btrfs_disk_key_to_cpu(struct btrfs_key
*cpu
,
1046 struct btrfs_disk_key
*disk
)
1048 cpu
->offset
= le64_to_cpu(disk
->offset
);
1049 cpu
->type
= disk
->type
;
1050 cpu
->objectid
= le64_to_cpu(disk
->objectid
);
1053 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key
*disk
,
1054 struct btrfs_key
*cpu
)
1056 disk
->offset
= cpu_to_le64(cpu
->offset
);
1057 disk
->type
= cpu
->type
;
1058 disk
->objectid
= cpu_to_le64(cpu
->objectid
);
1061 static inline void btrfs_node_key_to_cpu(struct extent_buffer
*eb
,
1062 struct btrfs_key
*key
, int nr
)
1064 struct btrfs_disk_key disk_key
;
1065 btrfs_node_key(eb
, &disk_key
, nr
);
1066 btrfs_disk_key_to_cpu(key
, &disk_key
);
1069 static inline void btrfs_item_key_to_cpu(struct extent_buffer
*eb
,
1070 struct btrfs_key
*key
, int nr
)
1072 struct btrfs_disk_key disk_key
;
1073 btrfs_item_key(eb
, &disk_key
, nr
);
1074 btrfs_disk_key_to_cpu(key
, &disk_key
);
1077 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer
*eb
,
1078 struct btrfs_dir_item
*item
,
1079 struct btrfs_key
*key
)
1081 struct btrfs_disk_key disk_key
;
1082 btrfs_dir_item_key(eb
, item
, &disk_key
);
1083 btrfs_disk_key_to_cpu(key
, &disk_key
);
1087 static inline u8
btrfs_key_type(struct btrfs_key
*key
)
1092 static inline void btrfs_set_key_type(struct btrfs_key
*key
, u8 val
)
1097 /* struct btrfs_header */
1098 BTRFS_SETGET_HEADER_FUNCS(header_bytenr
, struct btrfs_header
, bytenr
, 64);
1099 BTRFS_SETGET_HEADER_FUNCS(header_generation
, struct btrfs_header
,
1101 BTRFS_SETGET_HEADER_FUNCS(header_owner
, struct btrfs_header
, owner
, 64);
1102 BTRFS_SETGET_HEADER_FUNCS(header_nritems
, struct btrfs_header
, nritems
, 32);
1103 BTRFS_SETGET_HEADER_FUNCS(header_flags
, struct btrfs_header
, flags
, 64);
1104 BTRFS_SETGET_HEADER_FUNCS(header_level
, struct btrfs_header
, level
, 8);
1106 static inline int btrfs_header_flag(struct extent_buffer
*eb
, u64 flag
)
1108 return (btrfs_header_flags(eb
) & flag
) == flag
;
1111 static inline int btrfs_set_header_flag(struct extent_buffer
*eb
, u64 flag
)
1113 u64 flags
= btrfs_header_flags(eb
);
1114 btrfs_set_header_flags(eb
, flags
| flag
);
1115 return (flags
& flag
) == flag
;
1118 static inline int btrfs_clear_header_flag(struct extent_buffer
*eb
, u64 flag
)
1120 u64 flags
= btrfs_header_flags(eb
);
1121 btrfs_set_header_flags(eb
, flags
& ~flag
);
1122 return (flags
& flag
) == flag
;
1125 static inline u8
*btrfs_header_fsid(struct extent_buffer
*eb
)
1127 unsigned long ptr
= offsetof(struct btrfs_header
, fsid
);
1131 static inline u8
*btrfs_header_chunk_tree_uuid(struct extent_buffer
*eb
)
1133 unsigned long ptr
= offsetof(struct btrfs_header
, chunk_tree_uuid
);
1137 static inline u8
*btrfs_super_fsid(struct extent_buffer
*eb
)
1139 unsigned long ptr
= offsetof(struct btrfs_super_block
, fsid
);
1143 static inline u8
*btrfs_header_csum(struct extent_buffer
*eb
)
1145 unsigned long ptr
= offsetof(struct btrfs_header
, csum
);
1149 static inline struct btrfs_node
*btrfs_buffer_node(struct extent_buffer
*eb
)
1154 static inline struct btrfs_leaf
*btrfs_buffer_leaf(struct extent_buffer
*eb
)
1159 static inline struct btrfs_header
*btrfs_buffer_header(struct extent_buffer
*eb
)
1164 static inline int btrfs_is_leaf(struct extent_buffer
*eb
)
1166 return (btrfs_header_level(eb
) == 0);
1169 /* struct btrfs_root_item */
1170 BTRFS_SETGET_FUNCS(disk_root_refs
, struct btrfs_root_item
, refs
, 32);
1171 BTRFS_SETGET_FUNCS(disk_root_bytenr
, struct btrfs_root_item
, bytenr
, 64);
1172 BTRFS_SETGET_FUNCS(disk_root_level
, struct btrfs_root_item
, level
, 8);
1174 BTRFS_SETGET_STACK_FUNCS(root_bytenr
, struct btrfs_root_item
, bytenr
, 64);
1175 BTRFS_SETGET_STACK_FUNCS(root_level
, struct btrfs_root_item
, level
, 8);
1176 BTRFS_SETGET_STACK_FUNCS(root_dirid
, struct btrfs_root_item
, root_dirid
, 64);
1177 BTRFS_SETGET_STACK_FUNCS(root_refs
, struct btrfs_root_item
, refs
, 32);
1178 BTRFS_SETGET_STACK_FUNCS(root_flags
, struct btrfs_root_item
, flags
, 32);
1179 BTRFS_SETGET_STACK_FUNCS(root_used
, struct btrfs_root_item
, bytes_used
, 64);
1180 BTRFS_SETGET_STACK_FUNCS(root_limit
, struct btrfs_root_item
, byte_limit
, 64);
1182 /* struct btrfs_super_block */
1183 BTRFS_SETGET_STACK_FUNCS(super_bytenr
, struct btrfs_super_block
, bytenr
, 64);
1184 BTRFS_SETGET_STACK_FUNCS(super_generation
, struct btrfs_super_block
,
1186 BTRFS_SETGET_STACK_FUNCS(super_root
, struct btrfs_super_block
, root
, 64);
1187 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size
,
1188 struct btrfs_super_block
, sys_chunk_array_size
, 32);
1189 BTRFS_SETGET_STACK_FUNCS(super_root_level
, struct btrfs_super_block
,
1191 BTRFS_SETGET_STACK_FUNCS(super_chunk_root
, struct btrfs_super_block
,
1193 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level
, struct btrfs_super_block
,
1194 chunk_root_level
, 64);
1195 BTRFS_SETGET_STACK_FUNCS(super_total_bytes
, struct btrfs_super_block
,
1197 BTRFS_SETGET_STACK_FUNCS(super_bytes_used
, struct btrfs_super_block
,
1199 BTRFS_SETGET_STACK_FUNCS(super_sectorsize
, struct btrfs_super_block
,
1201 BTRFS_SETGET_STACK_FUNCS(super_nodesize
, struct btrfs_super_block
,
1203 BTRFS_SETGET_STACK_FUNCS(super_leafsize
, struct btrfs_super_block
,
1205 BTRFS_SETGET_STACK_FUNCS(super_stripesize
, struct btrfs_super_block
,
1207 BTRFS_SETGET_STACK_FUNCS(super_root_dir
, struct btrfs_super_block
,
1208 root_dir_objectid
, 64);
1209 BTRFS_SETGET_STACK_FUNCS(super_num_devices
, struct btrfs_super_block
,
1212 static inline unsigned long btrfs_leaf_data(struct extent_buffer
*l
)
1214 return offsetof(struct btrfs_leaf
, items
);
1217 /* struct btrfs_file_extent_item */
1218 BTRFS_SETGET_FUNCS(file_extent_type
, struct btrfs_file_extent_item
, type
, 8);
1220 static inline unsigned long btrfs_file_extent_inline_start(struct
1221 btrfs_file_extent_item
*e
)
1223 unsigned long offset
= (unsigned long)e
;
1224 offset
+= offsetof(struct btrfs_file_extent_item
, disk_bytenr
);
1228 static inline u32
btrfs_file_extent_calc_inline_size(u32 datasize
)
1230 return offsetof(struct btrfs_file_extent_item
, disk_bytenr
) + datasize
;
1233 static inline u32
btrfs_file_extent_inline_len(struct extent_buffer
*eb
,
1234 struct btrfs_item
*e
)
1236 unsigned long offset
;
1237 offset
= offsetof(struct btrfs_file_extent_item
, disk_bytenr
);
1238 return btrfs_item_size(eb
, e
) - offset
;
1241 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr
, struct btrfs_file_extent_item
,
1243 BTRFS_SETGET_FUNCS(file_extent_generation
, struct btrfs_file_extent_item
,
1245 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes
, struct btrfs_file_extent_item
,
1246 disk_num_bytes
, 64);
1247 BTRFS_SETGET_FUNCS(file_extent_offset
, struct btrfs_file_extent_item
,
1249 BTRFS_SETGET_FUNCS(file_extent_num_bytes
, struct btrfs_file_extent_item
,
1252 static inline u32
btrfs_level_size(struct btrfs_root
*root
, int level
) {
1254 return root
->leafsize
;
1255 return root
->nodesize
;
1258 /* helper function to cast into the data area of the leaf. */
1259 #define btrfs_item_ptr(leaf, slot, type) \
1260 ((type *)(btrfs_leaf_data(leaf) + \
1261 btrfs_item_offset_nr(leaf, slot)))
1263 #define btrfs_item_ptr_offset(leaf, slot) \
1264 ((unsigned long)(btrfs_leaf_data(leaf) + \
1265 btrfs_item_offset_nr(leaf, slot)))
1268 u32
btrfs_count_snapshots_in_path(struct btrfs_root
*root
,
1269 struct btrfs_path
*count_path
,
1271 int btrfs_extent_post_op(struct btrfs_trans_handle
*trans
,
1272 struct btrfs_root
*root
);
1273 int btrfs_copy_pinned(struct btrfs_root
*root
, struct extent_io_tree
*copy
);
1274 struct btrfs_block_group_cache
*btrfs_lookup_block_group(struct
1275 btrfs_fs_info
*info
,
1277 struct btrfs_block_group_cache
*btrfs_find_block_group(struct btrfs_root
*root
,
1278 struct btrfs_block_group_cache
1279 *hint
, u64 search_start
,
1280 int data
, int owner
);
1281 int btrfs_inc_root_ref(struct btrfs_trans_handle
*trans
,
1282 struct btrfs_root
*root
, u64 owner_objectid
);
1283 struct extent_buffer
*btrfs_alloc_free_block(struct btrfs_trans_handle
*trans
,
1284 struct btrfs_root
*root
, u32 size
,
1286 u64 hint
, u64 empty_size
);
1287 struct extent_buffer
*__btrfs_alloc_free_block(struct btrfs_trans_handle
*trans
,
1288 struct btrfs_root
*root
,
1296 int btrfs_grow_extent_tree(struct btrfs_trans_handle
*trans
,
1297 struct btrfs_root
*root
, u64 new_size
);
1298 int btrfs_shrink_extent_tree(struct btrfs_root
*root
, u64 new_size
);
1299 int btrfs_insert_extent_backref(struct btrfs_trans_handle
*trans
,
1300 struct btrfs_root
*root
,
1301 struct btrfs_path
*path
, u64 bytenr
,
1302 u64 root_objectid
, u64 ref_generation
,
1303 u64 owner
, u64 owner_offset
);
1304 int btrfs_alloc_extent(struct btrfs_trans_handle
*trans
,
1305 struct btrfs_root
*root
,
1306 u64 num_bytes
, u64 root_objectid
, u64 ref_generation
,
1307 u64 owner
, u64 owner_offset
,
1308 u64 empty_size
, u64 hint_byte
,
1309 u64 search_end
, struct btrfs_key
*ins
, int data
);
1310 int btrfs_inc_ref(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
1311 struct extent_buffer
*buf
);
1312 int btrfs_free_extent(struct btrfs_trans_handle
*trans
, struct btrfs_root
1313 *root
, u64 bytenr
, u64 num_bytes
,
1314 u64 root_objectid
, u64 ref_generation
,
1315 u64 owner_objectid
, u64 owner_offset
, int pin
);
1316 int btrfs_finish_extent_commit(struct btrfs_trans_handle
*trans
,
1317 struct btrfs_root
*root
,
1318 struct extent_io_tree
*unpin
);
1319 int btrfs_inc_extent_ref(struct btrfs_trans_handle
*trans
,
1320 struct btrfs_root
*root
,
1321 u64 bytenr
, u64 num_bytes
,
1322 u64 root_objectid
, u64 ref_generation
,
1323 u64 owner
, u64 owner_offset
);
1324 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle
*trans
,
1325 struct btrfs_root
*root
);
1326 int btrfs_free_block_groups(struct btrfs_fs_info
*info
);
1327 int btrfs_read_block_groups(struct btrfs_root
*root
);
1328 int btrfs_make_block_group(struct btrfs_trans_handle
*trans
,
1329 struct btrfs_root
*root
, u64 bytes_used
,
1330 u64 type
, u64 chunk_objectid
, u64 chunk_offset
,
1332 u64
btrfs_hash_extent_ref(u64 root_objectid
, u64 ref_generation
,
1333 u64 owner
, u64 owner_offset
);
1334 int btrfs_update_block_group(struct btrfs_trans_handle
*trans
,
1335 struct btrfs_root
*root
, u64 bytenr
, u64 num
,
1336 int alloc
, int mark_free
);
1338 int btrfs_previous_item(struct btrfs_root
*root
,
1339 struct btrfs_path
*path
, u64 min_objectid
,
1341 int btrfs_comp_keys(struct btrfs_disk_key
*disk
, struct btrfs_key
*k2
);
1342 int btrfs_cow_block(struct btrfs_trans_handle
*trans
,
1343 struct btrfs_root
*root
, struct extent_buffer
*buf
,
1344 struct extent_buffer
*parent
, int parent_slot
,
1345 struct extent_buffer
**cow_ret
);
1346 int __btrfs_cow_block(struct btrfs_trans_handle
*trans
,
1347 struct btrfs_root
*root
,
1348 struct extent_buffer
*buf
,
1349 struct extent_buffer
*parent
, int parent_slot
,
1350 struct extent_buffer
**cow_ret
,
1351 u64 search_start
, u64 empty_size
);
1352 int btrfs_copy_root(struct btrfs_trans_handle
*trans
,
1353 struct btrfs_root
*root
,
1354 struct extent_buffer
*buf
,
1355 struct extent_buffer
**cow_ret
, u64 new_root_objectid
);
1356 int btrfs_extend_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1357 *root
, struct btrfs_path
*path
, u32 data_size
);
1358 int btrfs_truncate_item(struct btrfs_trans_handle
*trans
,
1359 struct btrfs_root
*root
,
1360 struct btrfs_path
*path
,
1361 u32 new_size
, int from_end
);
1362 int btrfs_search_slot(struct btrfs_trans_handle
*trans
, struct btrfs_root
1363 *root
, struct btrfs_key
*key
, struct btrfs_path
*p
, int
1365 int btrfs_realloc_node(struct btrfs_trans_handle
*trans
,
1366 struct btrfs_root
*root
, struct extent_buffer
*parent
,
1367 int start_slot
, int cache_only
, u64
*last_ret
,
1368 struct btrfs_key
*progress
);
1369 void btrfs_release_path(struct btrfs_root
*root
, struct btrfs_path
*p
);
1370 struct btrfs_path
*btrfs_alloc_path(void);
1371 void btrfs_free_path(struct btrfs_path
*p
);
1372 void btrfs_init_path(struct btrfs_path
*p
);
1373 int btrfs_del_items(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
1374 struct btrfs_path
*path
, int slot
, int nr
);
1376 static inline int btrfs_del_item(struct btrfs_trans_handle
*trans
,
1377 struct btrfs_root
*root
,
1378 struct btrfs_path
*path
)
1380 return btrfs_del_items(trans
, root
, path
, path
->slots
[0], 1);
1383 int btrfs_insert_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1384 *root
, struct btrfs_key
*key
, void *data
, u32 data_size
);
1385 int btrfs_insert_empty_items(struct btrfs_trans_handle
*trans
,
1386 struct btrfs_root
*root
,
1387 struct btrfs_path
*path
,
1388 struct btrfs_key
*cpu_key
, u32
*data_size
, int nr
);
1390 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle
*trans
,
1391 struct btrfs_root
*root
,
1392 struct btrfs_path
*path
,
1393 struct btrfs_key
*key
,
1396 return btrfs_insert_empty_items(trans
, root
, path
, key
, &data_size
, 1);
1399 int btrfs_next_leaf(struct btrfs_root
*root
, struct btrfs_path
*path
);
1400 int btrfs_prev_leaf(struct btrfs_root
*root
, struct btrfs_path
*path
);
1401 int btrfs_leaf_free_space(struct btrfs_root
*root
, struct extent_buffer
*leaf
);
1402 int btrfs_drop_snapshot(struct btrfs_trans_handle
*trans
, struct btrfs_root
1407 int btrfs_del_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
1408 struct btrfs_key
*key
);
1409 int btrfs_insert_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
1410 *root
, struct btrfs_key
*key
, struct btrfs_root_item
1412 int btrfs_update_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
1413 *root
, struct btrfs_key
*key
, struct btrfs_root_item
1415 int btrfs_find_last_root(struct btrfs_root
*root
, u64 objectid
, struct
1416 btrfs_root_item
*item
, struct btrfs_key
*key
);
1417 int btrfs_find_dead_roots(struct btrfs_root
*root
, u64 objectid
,
1418 struct btrfs_root
*latest_root
);
1420 int btrfs_insert_dir_item(struct btrfs_trans_handle
*trans
, struct btrfs_root
1421 *root
, const char *name
, int name_len
, u64 dir
,
1422 struct btrfs_key
*location
, u8 type
);
1423 struct btrfs_dir_item
*btrfs_lookup_dir_item(struct btrfs_trans_handle
*trans
,
1424 struct btrfs_root
*root
,
1425 struct btrfs_path
*path
, u64 dir
,
1426 const char *name
, int name_len
,
1428 struct btrfs_dir_item
*
1429 btrfs_lookup_dir_index_item(struct btrfs_trans_handle
*trans
,
1430 struct btrfs_root
*root
,
1431 struct btrfs_path
*path
, u64 dir
,
1432 u64 objectid
, const char *name
, int name_len
,
1434 struct btrfs_dir_item
*btrfs_match_dir_item_name(struct btrfs_root
*root
,
1435 struct btrfs_path
*path
,
1436 const char *name
, int name_len
);
1437 int btrfs_delete_one_dir_name(struct btrfs_trans_handle
*trans
,
1438 struct btrfs_root
*root
,
1439 struct btrfs_path
*path
,
1440 struct btrfs_dir_item
*di
);
1441 int btrfs_insert_xattr_item(struct btrfs_trans_handle
*trans
,
1442 struct btrfs_root
*root
, const char *name
,
1443 u16 name_len
, const void *data
, u16 data_len
,
1445 struct btrfs_dir_item
*btrfs_lookup_xattr(struct btrfs_trans_handle
*trans
,
1446 struct btrfs_root
*root
,
1447 struct btrfs_path
*path
, u64 dir
,
1448 const char *name
, u16 name_len
,
1451 int btrfs_find_free_objectid(struct btrfs_trans_handle
*trans
,
1452 struct btrfs_root
*fs_root
,
1453 u64 dirid
, u64
*objectid
);
1454 int btrfs_find_highest_inode(struct btrfs_root
*fs_root
, u64
*objectid
);
1457 int btrfs_insert_inode_ref(struct btrfs_trans_handle
*trans
,
1458 struct btrfs_root
*root
,
1459 const char *name
, int name_len
,
1460 u64 inode_objectid
, u64 ref_objectid
);
1461 int btrfs_del_inode_ref(struct btrfs_trans_handle
*trans
,
1462 struct btrfs_root
*root
,
1463 const char *name
, int name_len
,
1464 u64 inode_objectid
, u64 ref_objectid
);
1465 int btrfs_insert_empty_inode(struct btrfs_trans_handle
*trans
,
1466 struct btrfs_root
*root
,
1467 struct btrfs_path
*path
, u64 objectid
);
1468 int btrfs_insert_inode(struct btrfs_trans_handle
*trans
, struct btrfs_root
1469 *root
, u64 objectid
, struct btrfs_inode_item
1471 int btrfs_lookup_inode(struct btrfs_trans_handle
*trans
, struct btrfs_root
1472 *root
, struct btrfs_path
*path
,
1473 struct btrfs_key
*location
, int mod
);
1476 int btrfs_insert_file_extent(struct btrfs_trans_handle
*trans
,
1477 struct btrfs_root
*root
,
1478 u64 objectid
, u64 pos
, u64 offset
,
1481 int btrfs_insert_inline_extent(struct btrfs_trans_handle
*trans
,
1482 struct btrfs_root
*root
, u64 objectid
,
1483 u64 offset
, char *buffer
, size_t size
);
1484 int btrfs_lookup_file_extent(struct btrfs_trans_handle
*trans
,
1485 struct btrfs_root
*root
,
1486 struct btrfs_path
*path
, u64 objectid
,
1487 u64 bytenr
, int mod
);
1488 int btrfs_csum_file_block(struct btrfs_trans_handle
*trans
,
1489 struct btrfs_root
*root
,
1490 struct btrfs_inode_item
*inode
,
1491 u64 objectid
, u64 offset
,
1492 char *data
, size_t len
);
1493 struct btrfs_csum_item
*btrfs_lookup_csum(struct btrfs_trans_handle
*trans
,
1494 struct btrfs_root
*root
,
1495 struct btrfs_path
*path
,
1496 u64 objectid
, u64 offset
,
1498 int btrfs_csum_truncate(struct btrfs_trans_handle
*trans
,
1499 struct btrfs_root
*root
, struct btrfs_path
*path
,