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 "_B9RfS_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
58 /* oprhan objectid for tracking unlinked/truncated files */
59 #define BTRFS_ORPHAN_OBJECTID -5ULL
61 /* does write ahead logging to speed up fsyncs */
62 #define BTRFS_TREE_LOG_OBJECTID -6ULL
63 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
66 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
67 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
69 /* dummy objectid represents multiple objectids */
70 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
73 * All files have objectids in this range.
75 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
76 #define BTRFS_LAST_FREE_OBJECTID -256ULL
77 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
82 * the device items go into the chunk tree. The key is in the form
83 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
85 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
88 * we can actually store much bigger names, but lets not confuse the rest
91 #define BTRFS_NAME_LEN 255
93 /* 32 bytes in various csum fields */
94 #define BTRFS_CSUM_SIZE 32
95 /* four bytes for CRC32 */
96 #define BTRFS_CRC32_SIZE 4
97 #define BTRFS_EMPTY_DIR_SIZE 0
99 #define BTRFS_FT_UNKNOWN 0
100 #define BTRFS_FT_REG_FILE 1
101 #define BTRFS_FT_DIR 2
102 #define BTRFS_FT_CHRDEV 3
103 #define BTRFS_FT_BLKDEV 4
104 #define BTRFS_FT_FIFO 5
105 #define BTRFS_FT_SOCK 6
106 #define BTRFS_FT_SYMLINK 7
107 #define BTRFS_FT_XATTR 8
108 #define BTRFS_FT_MAX 9
111 * the key defines the order in the tree, and so it also defines (optimal)
112 * block layout. objectid corresonds to the inode number. The flags
113 * tells us things about the object, and is a kind of stream selector.
114 * so for a given inode, keys with flags of 1 might refer to the inode
115 * data, flags of 2 may point to file data in the btree and flags == 3
116 * may point to extents.
118 * offset is the starting byte offset for this key in the stream.
120 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
121 * in cpu native order. Otherwise they are identical and their sizes
122 * should be the same (ie both packed)
124 struct btrfs_disk_key {
128 } __attribute__ ((__packed__));
134 } __attribute__ ((__packed__));
136 struct btrfs_mapping_tree {
137 struct cache_tree cache_tree;
140 #define BTRFS_UUID_SIZE 16
141 struct btrfs_dev_item {
142 /* the internal btrfs device id */
145 /* size of the device */
151 /* optimal io alignment for this device */
154 /* optimal io width for this device */
157 /* minimal io size for this device */
160 /* type and info about this device */
163 /* grouping information for allocation decisions */
166 /* seek speed 0-100 where 100 is fastest */
169 /* bandwidth 0-100 where 100 is fastest */
172 /* btrfs generated uuid for this device */
173 u8 uuid[BTRFS_UUID_SIZE];
174 } __attribute__ ((__packed__));
176 struct btrfs_stripe {
179 u8 dev_uuid[BTRFS_UUID_SIZE];
180 } __attribute__ ((__packed__));
183 /* size of this chunk in bytes */
186 /* objectid of the root referencing this chunk */
192 /* optimal io alignment for this chunk */
195 /* optimal io width for this chunk */
198 /* minimal io size for this chunk */
201 /* 2^16 stripes is quite a lot, a second limit is the size of a single
206 /* sub stripes only matter for raid10 */
208 struct btrfs_stripe stripe;
209 /* additional stripes go here */
210 } __attribute__ ((__packed__));
212 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
214 BUG_ON(num_stripes == 0);
215 return sizeof(struct btrfs_chunk) +
216 sizeof(struct btrfs_stripe) * (num_stripes - 1);
219 #define BTRFS_FSID_SIZE 16
220 #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
223 * every tree block (leaf or node) starts with this header.
225 struct btrfs_header {
226 /* these first four must match the super block */
227 u8 csum[BTRFS_CSUM_SIZE];
228 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
229 __le64 bytenr; /* which block this node is supposed to live in */
232 /* allowed to be different from the super from here on down */
233 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
238 } __attribute__ ((__packed__));
240 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
241 sizeof(struct btrfs_header)) / \
242 sizeof(struct btrfs_key_ptr))
243 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
244 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
245 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
246 sizeof(struct btrfs_item) - \
247 sizeof(struct btrfs_file_extent_item))
250 * this is a very generous portion of the super block, giving us
251 * room to translate 14 chunks with 3 stripes each.
253 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
254 #define BTRFS_LABEL_SIZE 256
257 * the super block basically lists the main trees of the FS
258 * it currently lacks any block count etc etc
260 struct btrfs_super_block {
261 u8 csum[BTRFS_CSUM_SIZE];
262 /* the first 3 fields must match struct btrfs_header */
263 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
264 __le64 bytenr; /* this block number */
267 /* allowed to be different from the btrfs_header from here own down */
275 __le64 root_dir_objectid;
281 __le32 sys_chunk_array_size;
285 struct btrfs_dev_item dev_item;
286 char label[BTRFS_LABEL_SIZE];
287 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
288 } __attribute__ ((__packed__));
291 * A leaf is full of items. offset and size tell us where to find
292 * the item in the leaf (relative to the start of the data area)
295 struct btrfs_disk_key key;
298 } __attribute__ ((__packed__));
301 * leaves have an item area and a data area:
302 * [item0, item1....itemN] [free space] [dataN...data1, data0]
304 * The data is separate from the items to get the keys closer together
308 struct btrfs_header header;
309 struct btrfs_item items[];
310 } __attribute__ ((__packed__));
313 * all non-leaf blocks are nodes, they hold only keys and pointers to
316 struct btrfs_key_ptr {
317 struct btrfs_disk_key key;
320 } __attribute__ ((__packed__));
323 struct btrfs_header header;
324 struct btrfs_key_ptr ptrs[];
325 } __attribute__ ((__packed__));
328 * btrfs_paths remember the path taken from the root down to the leaf.
329 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
330 * to any other levels that are present.
332 * The slots array records the index of the item or block pointer
333 * used while walking the tree.
336 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
337 int slots[BTRFS_MAX_LEVEL];
343 * items in the extent btree are used to record the objectid of the
344 * owner of the block and the number of references
346 struct btrfs_extent_item {
348 } __attribute__ ((__packed__));
350 struct btrfs_extent_ref {
356 } __attribute__ ((__packed__));
358 /* dev extents record free space on individual devices. The owner
359 * field points back to the chunk allocation mapping tree that allocated
360 * the extent. The chunk tree uuid field is a way to double check the owner
362 struct btrfs_dev_extent {
364 __le64 chunk_objectid;
367 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
368 } __attribute__ ((__packed__));
370 struct btrfs_inode_ref {
374 } __attribute__ ((__packed__));
376 struct btrfs_timespec {
379 } __attribute__ ((__packed__));
382 * there is no padding here on purpose. If you want to extent the inode,
383 * make a new item type
385 struct btrfs_inode_item {
386 /* nfs style generation number */
388 /* transid that last touched this inode */
400 struct btrfs_timespec atime;
401 struct btrfs_timespec ctime;
402 struct btrfs_timespec mtime;
403 struct btrfs_timespec otime;
404 } __attribute__ ((__packed__));
406 struct btrfs_dir_item {
407 struct btrfs_disk_key location;
412 } __attribute__ ((__packed__));
414 struct btrfs_root_item {
415 struct btrfs_inode_item inode;
422 struct btrfs_disk_key drop_progress;
425 } __attribute__ ((__packed__));
427 #define BTRFS_FILE_EXTENT_REG 0
428 #define BTRFS_FILE_EXTENT_INLINE 1
430 struct btrfs_file_extent_item {
434 * disk space consumed by the extent, checksum blocks are included
438 __le64 disk_num_bytes;
440 * the logical offset in file blocks (no csums)
441 * this extent record is for. This allows a file extent to point
442 * into the middle of an existing extent on disk, sharing it
443 * between two snapshots (useful if some bytes in the middle of the
444 * extent have changed
448 * the logical number of file blocks (no csums included)
451 } __attribute__ ((__packed__));
453 struct btrfs_csum_item {
455 } __attribute__ ((__packed__));
457 /* tag for the radix tree of block groups in ram */
458 #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
459 #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
460 #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
461 #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
462 #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
463 #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
464 #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
466 struct btrfs_block_group_item {
468 __le64 chunk_objectid;
470 } __attribute__ ((__packed__));
472 struct btrfs_space_info {
478 struct list_head list;
481 struct btrfs_block_group_cache {
482 struct cache_extent cache;
483 struct btrfs_key key;
484 struct btrfs_block_group_item item;
485 struct btrfs_space_info *space_info;
491 struct btrfs_extent_ops {
492 int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
493 u64 hint_byte, struct btrfs_key *ins);
494 int (*free_extent)(struct btrfs_root *root, u64 bytenr,
499 struct btrfs_fs_devices;
500 struct btrfs_fs_info {
501 u8 fsid[BTRFS_FSID_SIZE];
502 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
503 struct btrfs_root *fs_root;
504 struct btrfs_root *extent_root;
505 struct btrfs_root *tree_root;
506 struct btrfs_root *chunk_root;
507 struct btrfs_root *dev_root;
509 /* the log root tree is a directory of all the other log roots */
510 struct btrfs_root *log_root_tree;
512 struct extent_io_tree extent_cache;
513 struct extent_io_tree free_space_cache;
514 struct extent_io_tree block_group_cache;
515 struct extent_io_tree pinned_extents;
516 struct extent_io_tree pending_del;
517 struct extent_io_tree extent_ins;
519 /* logical->physical extent mapping */
520 struct btrfs_mapping_tree mapping_tree;
523 u64 last_trans_committed;
525 u64 avail_data_alloc_bits;
526 u64 avail_metadata_alloc_bits;
527 u64 avail_system_alloc_bits;
528 u64 data_alloc_profile;
529 u64 metadata_alloc_profile;
530 u64 system_alloc_profile;
533 struct btrfs_trans_handle *running_transaction;
534 struct btrfs_super_block super_copy;
535 struct extent_buffer *sb_buffer;
536 struct mutex fs_mutex;
539 struct btrfs_extent_ops *extent_ops;
540 struct list_head dirty_cowonly_roots;
542 struct btrfs_fs_devices *fs_devices;
543 struct list_head space_info;
549 * in ram representation of the tree. extent_root is used for all allocations
550 * and for the extent tree extent_root root.
553 struct extent_buffer *node;
554 struct extent_buffer *commit_root;
555 struct btrfs_root_item root_item;
556 struct btrfs_key root_key;
557 struct btrfs_fs_info *fs_info;
561 /* data allocations are done in sectorsize units */
564 /* node allocations are done in nodesize units */
567 /* leaf allocations are done in leafsize units */
570 /* leaf allocations are done in leafsize units */
579 u64 last_inode_alloc;
581 /* the dirty list is only used by non-reference counted roots */
582 struct list_head dirty_list;
586 * inode items have the data typically returned from stat and store other
587 * info about object characteristics. There is one for every file and dir in
590 #define BTRFS_INODE_ITEM_KEY 1
591 #define BTRFS_INODE_REF_KEY 2
592 #define BTRFS_XATTR_ITEM_KEY 8
593 #define BTRFS_ORPHAN_ITEM_KEY 9
595 /* reserve 3-15 close to the inode for later flexibility */
598 * dir items are the name -> inode pointers in a directory. There is one
599 * for every name in a directory.
601 #define BTRFS_DIR_ITEM_KEY 16
602 #define BTRFS_DIR_INDEX_KEY 17
604 * extent data is for file data
606 #define BTRFS_EXTENT_DATA_KEY 18
608 * csum items have the checksums for data in the extents
610 #define BTRFS_CSUM_ITEM_KEY 19
612 /* reserve 20-31 for other file stuff */
615 * root items point to tree roots. There are typically in the root
616 * tree used by the super block to find all the other trees
618 #define BTRFS_ROOT_ITEM_KEY 32
620 * extent items are in the extent map tree. These record which blocks
621 * are used, and how many references there are to each block
623 #define BTRFS_EXTENT_ITEM_KEY 33
624 #define BTRFS_EXTENT_REF_KEY 34
627 * block groups give us hints into the extent allocation trees. Which
628 * blocks are free etc etc
630 #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
632 #define BTRFS_DEV_EXTENT_KEY 75
633 #define BTRFS_DEV_ITEM_KEY 76
634 #define BTRFS_CHUNK_ITEM_KEY 77
637 * string items are for debugging. They just store a short string of
640 #define BTRFS_STRING_ITEM_KEY 253
644 #define BTRFS_INODE_NODATASUM (1 << 0)
645 #define BTRFS_INODE_NODATACOW (1 << 1)
646 #define BTRFS_INODE_READONLY (1 << 2)
648 #define read_eb_member(eb, ptr, type, member, result) ( \
649 read_extent_buffer(eb, (char *)(result), \
650 ((unsigned long)(ptr)) + \
651 offsetof(type, member), \
652 sizeof(((type *)0)->member)))
654 #define write_eb_member(eb, ptr, type, member, result) ( \
655 write_extent_buffer(eb, (char *)(result), \
656 ((unsigned long)(ptr)) + \
657 offsetof(type, member), \
658 sizeof(((type *)0)->member)))
660 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
661 static inline u##bits btrfs_##name(struct extent_buffer *eb) \
663 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
664 return le##bits##_to_cpu(h->member); \
666 static inline void btrfs_set_##name(struct extent_buffer *eb, \
669 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
670 h->member = cpu_to_le##bits(val); \
673 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
674 static inline u##bits btrfs_##name(struct extent_buffer *eb, \
677 unsigned long offset = (unsigned long)s; \
678 type *p = (type *) (eb->data + offset); \
679 return le##bits##_to_cpu(p->member); \
681 static inline void btrfs_set_##name(struct extent_buffer *eb, \
682 type *s, u##bits val) \
684 unsigned long offset = (unsigned long)s; \
685 type *p = (type *) (eb->data + offset); \
686 p->member = cpu_to_le##bits(val); \
689 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
690 static inline u##bits btrfs_##name(type *s) \
692 return le##bits##_to_cpu(s->member); \
694 static inline void btrfs_set_##name(type *s, u##bits val) \
696 s->member = cpu_to_le##bits(val); \
699 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
700 BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
701 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
702 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
703 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
704 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
705 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
706 BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
707 BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
708 BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
710 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
711 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
713 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
715 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
717 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
719 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
721 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
722 BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
724 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
726 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
729 static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
731 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
734 BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
735 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
736 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
737 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
738 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
739 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
740 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
741 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
742 BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
743 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
744 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
746 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
748 return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
751 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
752 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
753 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
755 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
757 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
759 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
761 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
762 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
764 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
766 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
767 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
769 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
772 unsigned long offset = (unsigned long)c;
773 offset += offsetof(struct btrfs_chunk, stripe);
774 offset += nr * sizeof(struct btrfs_stripe);
775 return (struct btrfs_stripe *)offset;
778 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
780 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
783 static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
784 struct btrfs_chunk *c, int nr)
786 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
789 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
790 struct btrfs_chunk *c, int nr,
793 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
796 static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
797 struct btrfs_chunk *c, int nr)
799 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
802 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
803 struct btrfs_chunk *c, int nr,
806 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
809 /* struct btrfs_block_group_item */
810 BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
812 BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
814 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
815 struct btrfs_block_group_item, chunk_objectid, 64);
817 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
818 struct btrfs_block_group_item, chunk_objectid, 64);
819 BTRFS_SETGET_FUNCS(disk_block_group_flags,
820 struct btrfs_block_group_item, flags, 64);
821 BTRFS_SETGET_STACK_FUNCS(block_group_flags,
822 struct btrfs_block_group_item, flags, 64);
824 /* struct btrfs_inode_ref */
825 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
826 BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
828 /* struct btrfs_inode_item */
829 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
830 BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
831 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
832 BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
833 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
834 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
835 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
836 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
837 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
838 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
839 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
840 BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
843 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
844 struct btrfs_inode_item, generation, 64);
845 BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
846 struct btrfs_inode_item, size, 64);
847 BTRFS_SETGET_STACK_FUNCS(stack_inode_nblocks,
848 struct btrfs_inode_item, nblocks, 64);
849 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
850 struct btrfs_inode_item, block_group, 64);
851 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
852 struct btrfs_inode_item, nlink, 32);
853 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
854 struct btrfs_inode_item, uid, 32);
855 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
856 struct btrfs_inode_item, gid, 32);
857 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
858 struct btrfs_inode_item, mode, 32);
859 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
860 struct btrfs_inode_item, rdev, 64);
861 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
862 struct btrfs_inode_item, flags, 16);
863 BTRFS_SETGET_STACK_FUNCS(stack_inode_compat_flags,
864 struct btrfs_inode_item, compat_flags, 16);
866 static inline struct btrfs_timespec *
867 btrfs_inode_atime(struct btrfs_inode_item *inode_item)
869 unsigned long ptr = (unsigned long)inode_item;
870 ptr += offsetof(struct btrfs_inode_item, atime);
871 return (struct btrfs_timespec *)ptr;
874 static inline struct btrfs_timespec *
875 btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
877 unsigned long ptr = (unsigned long)inode_item;
878 ptr += offsetof(struct btrfs_inode_item, mtime);
879 return (struct btrfs_timespec *)ptr;
882 static inline struct btrfs_timespec *
883 btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
885 unsigned long ptr = (unsigned long)inode_item;
886 ptr += offsetof(struct btrfs_inode_item, ctime);
887 return (struct btrfs_timespec *)ptr;
890 static inline struct btrfs_timespec *
891 btrfs_inode_otime(struct btrfs_inode_item *inode_item)
893 unsigned long ptr = (unsigned long)inode_item;
894 ptr += offsetof(struct btrfs_inode_item, otime);
895 return (struct btrfs_timespec *)ptr;
898 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
899 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
900 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
902 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
905 /* struct btrfs_dev_extent */
906 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
908 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
910 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
912 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
914 static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
916 unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
917 return (u8 *)((unsigned long)dev + ptr);
920 /* struct btrfs_extent_ref */
921 BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
922 BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
923 BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
924 BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
925 BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32);
927 BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
928 BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
930 BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
932 BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref,
934 BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref,
937 /* struct btrfs_extent_item */
938 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
939 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
942 /* struct btrfs_node */
943 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
944 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
946 static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
949 ptr = offsetof(struct btrfs_node, ptrs) +
950 sizeof(struct btrfs_key_ptr) * nr;
951 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
954 static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
958 ptr = offsetof(struct btrfs_node, ptrs) +
959 sizeof(struct btrfs_key_ptr) * nr;
960 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
963 static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
966 ptr = offsetof(struct btrfs_node, ptrs) +
967 sizeof(struct btrfs_key_ptr) * nr;
968 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
971 static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
975 ptr = offsetof(struct btrfs_node, ptrs) +
976 sizeof(struct btrfs_key_ptr) * nr;
977 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
980 static inline unsigned long btrfs_node_key_ptr_offset(int nr)
982 return offsetof(struct btrfs_node, ptrs) +
983 sizeof(struct btrfs_key_ptr) * nr;
986 static inline void btrfs_node_key(struct extent_buffer *eb,
987 struct btrfs_disk_key *disk_key, int nr)
990 ptr = btrfs_node_key_ptr_offset(nr);
991 read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
992 struct btrfs_key_ptr, key, disk_key);
995 static inline void btrfs_set_node_key(struct extent_buffer *eb,
996 struct btrfs_disk_key *disk_key, int nr)
999 ptr = btrfs_node_key_ptr_offset(nr);
1000 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1001 struct btrfs_key_ptr, key, disk_key);
1004 /* struct btrfs_item */
1005 BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
1006 BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
1008 static inline unsigned long btrfs_item_nr_offset(int nr)
1010 return offsetof(struct btrfs_leaf, items) +
1011 sizeof(struct btrfs_item) * nr;
1014 static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
1017 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
1020 static inline u32 btrfs_item_end(struct extent_buffer *eb,
1021 struct btrfs_item *item)
1023 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
1026 static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
1028 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
1031 static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
1033 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
1036 static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
1038 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
1041 static inline void btrfs_item_key(struct extent_buffer *eb,
1042 struct btrfs_disk_key *disk_key, int nr)
1044 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1045 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
1048 static inline void btrfs_set_item_key(struct extent_buffer *eb,
1049 struct btrfs_disk_key *disk_key, int nr)
1051 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1052 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
1055 /* struct btrfs_dir_item */
1056 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
1057 BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
1058 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1059 BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
1061 static inline void btrfs_dir_item_key(struct extent_buffer *eb,
1062 struct btrfs_dir_item *item,
1063 struct btrfs_disk_key *key)
1065 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
1068 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
1069 struct btrfs_dir_item *item,
1070 struct btrfs_disk_key *key)
1072 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
1075 /* struct btrfs_disk_key */
1076 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
1078 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
1079 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
1081 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
1082 struct btrfs_disk_key *disk)
1084 cpu->offset = le64_to_cpu(disk->offset);
1085 cpu->type = disk->type;
1086 cpu->objectid = le64_to_cpu(disk->objectid);
1089 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
1090 struct btrfs_key *cpu)
1092 disk->offset = cpu_to_le64(cpu->offset);
1093 disk->type = cpu->type;
1094 disk->objectid = cpu_to_le64(cpu->objectid);
1097 static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
1098 struct btrfs_key *key, int nr)
1100 struct btrfs_disk_key disk_key;
1101 btrfs_node_key(eb, &disk_key, nr);
1102 btrfs_disk_key_to_cpu(key, &disk_key);
1105 static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
1106 struct btrfs_key *key, int nr)
1108 struct btrfs_disk_key disk_key;
1109 btrfs_item_key(eb, &disk_key, nr);
1110 btrfs_disk_key_to_cpu(key, &disk_key);
1113 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
1114 struct btrfs_dir_item *item,
1115 struct btrfs_key *key)
1117 struct btrfs_disk_key disk_key;
1118 btrfs_dir_item_key(eb, item, &disk_key);
1119 btrfs_disk_key_to_cpu(key, &disk_key);
1123 static inline u8 btrfs_key_type(struct btrfs_key *key)
1128 static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
1133 /* struct btrfs_header */
1134 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
1135 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
1137 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
1138 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
1139 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
1140 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
1142 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
1144 return (btrfs_header_flags(eb) & flag) == flag;
1147 static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
1149 u64 flags = btrfs_header_flags(eb);
1150 btrfs_set_header_flags(eb, flags | flag);
1151 return (flags & flag) == flag;
1154 static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
1156 u64 flags = btrfs_header_flags(eb);
1157 btrfs_set_header_flags(eb, flags & ~flag);
1158 return (flags & flag) == flag;
1161 static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
1163 unsigned long ptr = offsetof(struct btrfs_header, fsid);
1167 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
1169 unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
1173 static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1175 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1179 static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
1181 unsigned long ptr = offsetof(struct btrfs_header, csum);
1185 static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
1190 static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
1195 static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
1200 static inline int btrfs_is_leaf(struct extent_buffer *eb)
1202 return (btrfs_header_level(eb) == 0);
1205 /* struct btrfs_root_item */
1206 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
1207 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
1208 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
1210 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
1211 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
1212 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
1213 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
1214 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
1215 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
1216 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
1218 /* struct btrfs_super_block */
1219 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
1220 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
1222 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
1223 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
1224 struct btrfs_super_block, sys_chunk_array_size, 32);
1225 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
1227 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
1229 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
1230 chunk_root_level, 8);
1231 BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
1233 BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
1235 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
1237 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
1239 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
1241 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
1243 BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
1245 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
1247 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
1248 root_dir_objectid, 64);
1249 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
1252 static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
1254 return offsetof(struct btrfs_leaf, items);
1257 /* struct btrfs_file_extent_item */
1258 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
1260 static inline unsigned long btrfs_file_extent_inline_start(struct
1261 btrfs_file_extent_item *e)
1263 unsigned long offset = (unsigned long)e;
1264 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
1268 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
1270 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
1273 static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
1274 struct btrfs_item *e)
1276 unsigned long offset;
1277 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
1278 return btrfs_item_size(eb, e) - offset;
1281 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
1283 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
1285 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
1286 disk_num_bytes, 64);
1287 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
1289 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
1292 static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
1294 return root->leafsize;
1295 return root->nodesize;
1298 /* helper function to cast into the data area of the leaf. */
1299 #define btrfs_item_ptr(leaf, slot, type) \
1300 ((type *)(btrfs_leaf_data(leaf) + \
1301 btrfs_item_offset_nr(leaf, slot)))
1303 #define btrfs_item_ptr_offset(leaf, slot) \
1304 ((unsigned long)(btrfs_leaf_data(leaf) + \
1305 btrfs_item_offset_nr(leaf, slot)))
1308 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
1309 struct btrfs_root *root);
1310 int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
1311 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
1312 btrfs_fs_info *info,
1314 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1315 struct btrfs_block_group_cache
1316 *hint, u64 search_start,
1317 int data, int owner);
1318 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1319 struct btrfs_root *root,
1320 u32 blocksize, u64 parent,
1326 int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans,
1327 struct btrfs_root *root, u64 new_size);
1328 int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
1329 int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
1330 struct btrfs_root *root,
1331 struct btrfs_path *path,
1332 u64 bytenr, u64 parent,
1333 u64 root_objectid, u64 ref_generation,
1334 u64 owner, u64 owner_offset);
1335 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1336 struct btrfs_root *root,
1337 u64 num_bytes, u64 parent,
1338 u64 root_objectid, u64 ref_generation,
1339 u64 owner, u64 owner_offset,
1340 u64 empty_size, u64 hint_byte,
1341 u64 search_end, struct btrfs_key *ins, int data);
1342 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1343 struct extent_buffer *orig_buf, struct extent_buffer *buf,
1345 int btrfs_update_ref(struct btrfs_trans_handle *trans,
1346 struct btrfs_root *root, struct extent_buffer *orig_buf,
1347 struct extent_buffer *buf, int start_slot, int nr);
1348 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1349 *root, u64 bytenr, u64 num_bytes, u64 parent,
1350 u64 root_objectid, u64 ref_generation,
1351 u64 owner_objectid, u64 owner_offset, int pin);
1352 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1353 struct btrfs_root *root,
1354 struct extent_io_tree *unpin);
1355 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1356 struct btrfs_root *root,
1357 u64 bytenr, u64 num_bytes, u64 parent,
1358 u64 root_objectid, u64 ref_generation,
1359 u64 owner, u64 owner_offset);
1360 int btrfs_update_extent_ref(struct btrfs_trans_handle *trans,
1361 struct btrfs_root *root, u64 bytenr,
1362 u64 orig_parent, u64 parent,
1363 u64 root_objectid, u64 ref_generation,
1364 u64 owner_objectid, u64 owner_offset);
1365 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1366 struct btrfs_root *root);
1367 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1368 int btrfs_read_block_groups(struct btrfs_root *root);
1369 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1370 struct btrfs_root *root, u64 bytes_used,
1371 u64 type, u64 chunk_objectid, u64 chunk_offset,
1373 int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
1374 struct btrfs_root *root);
1375 int btrfs_update_block_group(struct btrfs_trans_handle *trans,
1376 struct btrfs_root *root, u64 bytenr, u64 num,
1377 int alloc, int mark_free);
1379 int btrfs_previous_item(struct btrfs_root *root,
1380 struct btrfs_path *path, u64 min_objectid,
1382 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1383 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1384 struct btrfs_root *root, struct extent_buffer *buf,
1385 struct extent_buffer *parent, int parent_slot,
1386 struct extent_buffer **cow_ret);
1387 int __btrfs_cow_block(struct btrfs_trans_handle *trans,
1388 struct btrfs_root *root,
1389 struct extent_buffer *buf,
1390 struct extent_buffer *parent, int parent_slot,
1391 struct extent_buffer **cow_ret,
1392 u64 search_start, u64 empty_size);
1393 int btrfs_copy_root(struct btrfs_trans_handle *trans,
1394 struct btrfs_root *root,
1395 struct extent_buffer *buf,
1396 struct extent_buffer **cow_ret, u64 new_root_objectid);
1397 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1398 *root, struct btrfs_path *path, u32 data_size);
1399 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1400 struct btrfs_root *root,
1401 struct btrfs_path *path,
1402 u32 new_size, int from_end);
1403 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1404 *root, struct btrfs_key *key, struct btrfs_path *p, int
1406 int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1407 struct btrfs_root *root, struct extent_buffer *parent,
1408 int start_slot, int cache_only, u64 *last_ret,
1409 struct btrfs_key *progress);
1410 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1411 struct btrfs_path *btrfs_alloc_path(void);
1412 void btrfs_free_path(struct btrfs_path *p);
1413 void btrfs_init_path(struct btrfs_path *p);
1414 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1415 struct btrfs_path *path, int slot, int nr);
1417 static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
1418 struct btrfs_root *root,
1419 struct btrfs_path *path)
1421 return btrfs_del_items(trans, root, path, path->slots[0], 1);
1424 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1425 *root, struct btrfs_key *key, void *data, u32 data_size);
1426 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
1427 struct btrfs_root *root,
1428 struct btrfs_path *path,
1429 struct btrfs_key *cpu_key, u32 *data_size, int nr);
1431 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
1432 struct btrfs_root *root,
1433 struct btrfs_path *path,
1434 struct btrfs_key *key,
1437 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
1440 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1441 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
1442 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
1443 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1445 int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
1446 struct btrfs_root *root, struct btrfs_path *path,
1447 struct btrfs_key *new_key);
1450 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1451 struct btrfs_key *key);
1452 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1453 *root, struct btrfs_key *key, struct btrfs_root_item
1455 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1456 *root, struct btrfs_key *key, struct btrfs_root_item
1458 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1459 btrfs_root_item *item, struct btrfs_key *key);
1460 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1461 struct btrfs_root *latest_root);
1463 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1464 *root, const char *name, int name_len, u64 dir,
1465 struct btrfs_key *location, u8 type);
1466 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1467 struct btrfs_root *root,
1468 struct btrfs_path *path, u64 dir,
1469 const char *name, int name_len,
1471 struct btrfs_dir_item *
1472 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1473 struct btrfs_root *root,
1474 struct btrfs_path *path, u64 dir,
1475 u64 objectid, const char *name, int name_len,
1477 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1478 struct btrfs_path *path,
1479 const char *name, int name_len);
1480 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1481 struct btrfs_root *root,
1482 struct btrfs_path *path,
1483 struct btrfs_dir_item *di);
1484 int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
1485 struct btrfs_root *root, const char *name,
1486 u16 name_len, const void *data, u16 data_len,
1488 struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
1489 struct btrfs_root *root,
1490 struct btrfs_path *path, u64 dir,
1491 const char *name, u16 name_len,
1494 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1495 struct btrfs_root *fs_root,
1496 u64 dirid, u64 *objectid);
1497 int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1500 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
1501 struct btrfs_root *root,
1502 const char *name, int name_len,
1503 u64 inode_objectid, u64 ref_objectid, u64 index);
1504 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
1505 struct btrfs_root *root,
1506 const char *name, int name_len,
1507 u64 inode_objectid, u64 ref_objectid);
1508 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1509 struct btrfs_root *root,
1510 struct btrfs_path *path, u64 objectid);
1511 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1512 *root, u64 objectid, struct btrfs_inode_item
1514 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1515 *root, struct btrfs_path *path,
1516 struct btrfs_key *location, int mod);
1519 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1520 struct btrfs_root *root,
1521 u64 objectid, u64 pos, u64 offset,
1524 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
1525 struct btrfs_root *root, u64 objectid,
1526 u64 offset, char *buffer, size_t size);
1527 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1528 struct btrfs_root *root,
1529 struct btrfs_path *path, u64 objectid,
1530 u64 bytenr, int mod);
1531 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1532 struct btrfs_root *root,
1533 struct btrfs_inode_item *inode,
1534 u64 objectid, u64 offset,
1535 char *data, size_t len);
1536 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1537 struct btrfs_root *root,
1538 struct btrfs_path *path,
1539 u64 objectid, u64 offset,
1541 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1542 struct btrfs_root *root, struct btrfs_path *path,