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 "_B8RfS_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
65 * All files have objectids higher than this.
67 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
68 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
72 * the device items go into the chunk tree. The key is in the form
73 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
75 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
78 * we can actually store much bigger names, but lets not confuse the rest
81 #define BTRFS_NAME_LEN 255
83 /* 32 bytes in various csum fields */
84 #define BTRFS_CSUM_SIZE 32
85 /* four bytes for CRC32 */
86 #define BTRFS_CRC32_SIZE 4
87 #define BTRFS_EMPTY_DIR_SIZE 0
89 #define BTRFS_FT_UNKNOWN 0
90 #define BTRFS_FT_REG_FILE 1
91 #define BTRFS_FT_DIR 2
92 #define BTRFS_FT_CHRDEV 3
93 #define BTRFS_FT_BLKDEV 4
94 #define BTRFS_FT_FIFO 5
95 #define BTRFS_FT_SOCK 6
96 #define BTRFS_FT_SYMLINK 7
97 #define BTRFS_FT_XATTR 8
98 #define BTRFS_FT_MAX 9
101 * the key defines the order in the tree, and so it also defines (optimal)
102 * block layout. objectid corresonds to the inode number. The flags
103 * tells us things about the object, and is a kind of stream selector.
104 * so for a given inode, keys with flags of 1 might refer to the inode
105 * data, flags of 2 may point to file data in the btree and flags == 3
106 * may point to extents.
108 * offset is the starting byte offset for this key in the stream.
110 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
111 * in cpu native order. Otherwise they are identical and their sizes
112 * should be the same (ie both packed)
114 struct btrfs_disk_key {
118 } __attribute__ ((__packed__));
124 } __attribute__ ((__packed__));
126 struct btrfs_mapping_tree {
127 struct cache_tree cache_tree;
130 #define BTRFS_UUID_SIZE 16
131 struct btrfs_dev_item {
132 /* the internal btrfs device id */
135 /* size of the device */
141 /* optimal io alignment for this device */
144 /* optimal io width for this device */
147 /* minimal io size for this device */
150 /* type and info about this device */
153 /* grouping information for allocation decisions */
156 /* seek speed 0-100 where 100 is fastest */
159 /* bandwidth 0-100 where 100 is fastest */
162 /* btrfs generated uuid for this device */
163 u8 uuid[BTRFS_UUID_SIZE];
164 } __attribute__ ((__packed__));
166 struct btrfs_stripe {
169 u8 dev_uuid[BTRFS_UUID_SIZE];
170 } __attribute__ ((__packed__));
173 /* size of this chunk in bytes */
176 /* objectid of the root referencing this chunk */
182 /* optimal io alignment for this chunk */
185 /* optimal io width for this chunk */
188 /* minimal io size for this chunk */
191 /* 2^16 stripes is quite a lot, a second limit is the size of a single
196 /* sub stripes only matter for raid10 */
198 struct btrfs_stripe stripe;
199 /* additional stripes go here */
200 } __attribute__ ((__packed__));
202 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
204 BUG_ON(num_stripes == 0);
205 return sizeof(struct btrfs_chunk) +
206 sizeof(struct btrfs_stripe) * (num_stripes - 1);
209 #define BTRFS_FSID_SIZE 16
210 #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
213 * every tree block (leaf or node) starts with this header.
215 struct btrfs_header {
216 /* these first four must match the super block */
217 u8 csum[BTRFS_CSUM_SIZE];
218 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
219 __le64 bytenr; /* which block this node is supposed to live in */
222 /* allowed to be different from the super from here on down */
223 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
228 } __attribute__ ((__packed__));
230 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
231 sizeof(struct btrfs_header)) / \
232 sizeof(struct btrfs_key_ptr))
233 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
234 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
235 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
236 sizeof(struct btrfs_item) - \
237 sizeof(struct btrfs_file_extent_item))
240 * this is a very generous portion of the super block, giving us
241 * room to translate 14 chunks with 3 stripes each.
243 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
244 #define BTRFS_LABEL_SIZE 256
247 * the super block basically lists the main trees of the FS
248 * it currently lacks any block count etc etc
250 struct btrfs_super_block {
251 u8 csum[BTRFS_CSUM_SIZE];
252 /* the first 3 fields must match struct btrfs_header */
253 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
254 __le64 bytenr; /* this block number */
257 /* allowed to be different from the btrfs_header from here own down */
265 __le64 root_dir_objectid;
271 __le32 sys_chunk_array_size;
275 struct btrfs_dev_item dev_item;
276 char label[BTRFS_LABEL_SIZE];
277 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
278 } __attribute__ ((__packed__));
281 * A leaf is full of items. offset and size tell us where to find
282 * the item in the leaf (relative to the start of the data area)
285 struct btrfs_disk_key key;
288 } __attribute__ ((__packed__));
291 * leaves have an item area and a data area:
292 * [item0, item1....itemN] [free space] [dataN...data1, data0]
294 * The data is separate from the items to get the keys closer together
298 struct btrfs_header header;
299 struct btrfs_item items[];
300 } __attribute__ ((__packed__));
303 * all non-leaf blocks are nodes, they hold only keys and pointers to
306 struct btrfs_key_ptr {
307 struct btrfs_disk_key key;
310 } __attribute__ ((__packed__));
313 struct btrfs_header header;
314 struct btrfs_key_ptr ptrs[];
315 } __attribute__ ((__packed__));
318 * btrfs_paths remember the path taken from the root down to the leaf.
319 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
320 * to any other levels that are present.
322 * The slots array records the index of the item or block pointer
323 * used while walking the tree.
326 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
327 int slots[BTRFS_MAX_LEVEL];
333 * items in the extent btree are used to record the objectid of the
334 * owner of the block and the number of references
336 struct btrfs_extent_item {
338 } __attribute__ ((__packed__));
340 struct btrfs_extent_ref {
345 } __attribute__ ((__packed__));
347 /* dev extents record free space on individual devices. The owner
348 * field points back to the chunk allocation mapping tree that allocated
349 * the extent. The chunk tree uuid field is a way to double check the owner
351 struct btrfs_dev_extent {
353 __le64 chunk_objectid;
356 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
357 } __attribute__ ((__packed__));
359 struct btrfs_inode_ref {
363 } __attribute__ ((__packed__));
365 struct btrfs_timespec {
368 } __attribute__ ((__packed__));
371 * there is no padding here on purpose. If you want to extent the inode,
372 * make a new item type
374 struct btrfs_inode_item {
375 /* nfs style generation number */
377 /* transid that last touched this inode */
389 struct btrfs_timespec atime;
390 struct btrfs_timespec ctime;
391 struct btrfs_timespec mtime;
392 struct btrfs_timespec otime;
393 } __attribute__ ((__packed__));
395 struct btrfs_dir_item {
396 struct btrfs_disk_key location;
401 } __attribute__ ((__packed__));
403 struct btrfs_root_item {
404 struct btrfs_inode_item inode;
411 struct btrfs_disk_key drop_progress;
414 } __attribute__ ((__packed__));
416 #define BTRFS_FILE_EXTENT_REG 0
417 #define BTRFS_FILE_EXTENT_INLINE 1
419 struct btrfs_file_extent_item {
423 * disk space consumed by the extent, checksum blocks are included
427 __le64 disk_num_bytes;
429 * the logical offset in file blocks (no csums)
430 * this extent record is for. This allows a file extent to point
431 * into the middle of an existing extent on disk, sharing it
432 * between two snapshots (useful if some bytes in the middle of the
433 * extent have changed
437 * the logical number of file blocks (no csums included)
440 } __attribute__ ((__packed__));
442 struct btrfs_csum_item {
444 } __attribute__ ((__packed__));
446 /* tag for the radix tree of block groups in ram */
447 #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
448 #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
449 #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
450 #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
451 #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
452 #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
453 #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
455 struct btrfs_block_group_item {
457 __le64 chunk_objectid;
459 } __attribute__ ((__packed__));
461 struct btrfs_space_info {
467 struct list_head list;
470 struct btrfs_block_group_cache {
471 struct cache_extent cache;
472 struct btrfs_key key;
473 struct btrfs_block_group_item item;
474 struct btrfs_space_info *space_info;
480 struct btrfs_extent_ops {
481 int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
482 u64 hint_byte, struct btrfs_key *ins);
483 int (*free_extent)(struct btrfs_root *root, u64 bytenr,
488 struct btrfs_fs_devices;
489 struct btrfs_fs_info {
490 u8 fsid[BTRFS_FSID_SIZE];
491 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
492 struct btrfs_root *fs_root;
493 struct btrfs_root *extent_root;
494 struct btrfs_root *tree_root;
495 struct btrfs_root *chunk_root;
496 struct btrfs_root *dev_root;
498 /* the log root tree is a directory of all the other log roots */
499 struct btrfs_root *log_root_tree;
501 struct extent_io_tree extent_cache;
502 struct extent_io_tree free_space_cache;
503 struct extent_io_tree block_group_cache;
504 struct extent_io_tree pinned_extents;
505 struct extent_io_tree pending_del;
506 struct extent_io_tree extent_ins;
508 /* logical->physical extent mapping */
509 struct btrfs_mapping_tree mapping_tree;
512 u64 last_trans_committed;
514 u64 avail_data_alloc_bits;
515 u64 avail_metadata_alloc_bits;
516 u64 avail_system_alloc_bits;
517 u64 data_alloc_profile;
518 u64 metadata_alloc_profile;
519 u64 system_alloc_profile;
522 struct btrfs_trans_handle *running_transaction;
523 struct btrfs_super_block super_copy;
524 struct extent_buffer *sb_buffer;
525 struct mutex fs_mutex;
528 struct btrfs_extent_ops *extent_ops;
529 struct list_head dirty_cowonly_roots;
531 struct btrfs_fs_devices *fs_devices;
532 struct list_head space_info;
538 * in ram representation of the tree. extent_root is used for all allocations
539 * and for the extent tree extent_root root.
542 struct extent_buffer *node;
543 struct extent_buffer *commit_root;
544 struct btrfs_root_item root_item;
545 struct btrfs_key root_key;
546 struct btrfs_fs_info *fs_info;
550 /* data allocations are done in sectorsize units */
553 /* node allocations are done in nodesize units */
556 /* leaf allocations are done in leafsize units */
559 /* leaf allocations are done in leafsize units */
568 u64 last_inode_alloc;
570 /* the dirty list is only used by non-reference counted roots */
571 struct list_head dirty_list;
575 * inode items have the data typically returned from stat and store other
576 * info about object characteristics. There is one for every file and dir in
579 #define BTRFS_INODE_ITEM_KEY 1
580 #define BTRFS_INODE_REF_KEY 2
581 #define BTRFS_XATTR_ITEM_KEY 8
582 #define BTRFS_ORPHAN_ITEM_KEY 9
584 /* reserve 3-15 close to the inode for later flexibility */
587 * dir items are the name -> inode pointers in a directory. There is one
588 * for every name in a directory.
590 #define BTRFS_DIR_ITEM_KEY 16
591 #define BTRFS_DIR_INDEX_KEY 17
593 * extent data is for file data
595 #define BTRFS_EXTENT_DATA_KEY 18
597 * csum items have the checksums for data in the extents
599 #define BTRFS_CSUM_ITEM_KEY 19
601 /* reserve 20-31 for other file stuff */
604 * root items point to tree roots. There are typically in the root
605 * tree used by the super block to find all the other trees
607 #define BTRFS_ROOT_ITEM_KEY 32
609 * extent items are in the extent map tree. These record which blocks
610 * are used, and how many references there are to each block
612 #define BTRFS_EXTENT_ITEM_KEY 33
613 #define BTRFS_EXTENT_REF_KEY 34
616 * block groups give us hints into the extent allocation trees. Which
617 * blocks are free etc etc
619 #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
621 #define BTRFS_DEV_EXTENT_KEY 75
622 #define BTRFS_DEV_ITEM_KEY 76
623 #define BTRFS_CHUNK_ITEM_KEY 77
626 * string items are for debugging. They just store a short string of
629 #define BTRFS_STRING_ITEM_KEY 253
633 #define BTRFS_INODE_NODATASUM (1 << 0)
634 #define BTRFS_INODE_NODATACOW (1 << 1)
635 #define BTRFS_INODE_READONLY (1 << 2)
637 #define read_eb_member(eb, ptr, type, member, result) ( \
638 read_extent_buffer(eb, (char *)(result), \
639 ((unsigned long)(ptr)) + \
640 offsetof(type, member), \
641 sizeof(((type *)0)->member)))
643 #define write_eb_member(eb, ptr, type, member, result) ( \
644 write_extent_buffer(eb, (char *)(result), \
645 ((unsigned long)(ptr)) + \
646 offsetof(type, member), \
647 sizeof(((type *)0)->member)))
649 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
650 static inline u##bits btrfs_##name(struct extent_buffer *eb) \
652 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
653 return le##bits##_to_cpu(h->member); \
655 static inline void btrfs_set_##name(struct extent_buffer *eb, \
658 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
659 h->member = cpu_to_le##bits(val); \
662 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
663 static inline u##bits btrfs_##name(struct extent_buffer *eb, \
666 unsigned long offset = (unsigned long)s; \
667 type *p = (type *) (eb->data + offset); \
668 return le##bits##_to_cpu(p->member); \
670 static inline void btrfs_set_##name(struct extent_buffer *eb, \
671 type *s, u##bits val) \
673 unsigned long offset = (unsigned long)s; \
674 type *p = (type *) (eb->data + offset); \
675 p->member = cpu_to_le##bits(val); \
678 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
679 static inline u##bits btrfs_##name(type *s) \
681 return le##bits##_to_cpu(s->member); \
683 static inline void btrfs_set_##name(type *s, u##bits val) \
685 s->member = cpu_to_le##bits(val); \
688 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
689 BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
690 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
691 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
692 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
693 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
694 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
695 BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
696 BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
697 BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
699 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
700 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
702 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
704 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
706 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
708 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
710 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
711 BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
713 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
715 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
718 static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
720 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
723 BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
724 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
725 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
726 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
727 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
728 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
729 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
730 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
731 BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
732 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
733 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
735 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
737 return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
740 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
741 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
742 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
744 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
746 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
748 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
750 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
751 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
753 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
755 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
756 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
758 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
761 unsigned long offset = (unsigned long)c;
762 offset += offsetof(struct btrfs_chunk, stripe);
763 offset += nr * sizeof(struct btrfs_stripe);
764 return (struct btrfs_stripe *)offset;
767 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
769 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
772 static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
773 struct btrfs_chunk *c, int nr)
775 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
778 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
779 struct btrfs_chunk *c, int nr,
782 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
785 static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
786 struct btrfs_chunk *c, int nr)
788 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
791 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
792 struct btrfs_chunk *c, int nr,
795 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
798 /* struct btrfs_block_group_item */
799 BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
801 BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
803 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
804 struct btrfs_block_group_item, chunk_objectid, 64);
806 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
807 struct btrfs_block_group_item, chunk_objectid, 64);
808 BTRFS_SETGET_FUNCS(disk_block_group_flags,
809 struct btrfs_block_group_item, flags, 64);
810 BTRFS_SETGET_STACK_FUNCS(block_group_flags,
811 struct btrfs_block_group_item, flags, 64);
813 /* struct btrfs_inode_ref */
814 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
815 BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
817 /* struct btrfs_inode_item */
818 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
819 BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
820 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
821 BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
822 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
823 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
824 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
825 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
826 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
827 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
828 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
829 BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
832 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
833 struct btrfs_inode_item, generation, 64);
834 BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
835 struct btrfs_inode_item, size, 64);
836 BTRFS_SETGET_STACK_FUNCS(stack_inode_nblocks,
837 struct btrfs_inode_item, nblocks, 64);
838 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
839 struct btrfs_inode_item, block_group, 64);
840 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
841 struct btrfs_inode_item, nlink, 32);
842 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
843 struct btrfs_inode_item, uid, 32);
844 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
845 struct btrfs_inode_item, gid, 32);
846 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
847 struct btrfs_inode_item, mode, 32);
848 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
849 struct btrfs_inode_item, rdev, 64);
850 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
851 struct btrfs_inode_item, flags, 16);
852 BTRFS_SETGET_STACK_FUNCS(stack_inode_compat_flags,
853 struct btrfs_inode_item, compat_flags, 16);
855 static inline struct btrfs_timespec *
856 btrfs_inode_atime(struct btrfs_inode_item *inode_item)
858 unsigned long ptr = (unsigned long)inode_item;
859 ptr += offsetof(struct btrfs_inode_item, atime);
860 return (struct btrfs_timespec *)ptr;
863 static inline struct btrfs_timespec *
864 btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
866 unsigned long ptr = (unsigned long)inode_item;
867 ptr += offsetof(struct btrfs_inode_item, mtime);
868 return (struct btrfs_timespec *)ptr;
871 static inline struct btrfs_timespec *
872 btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
874 unsigned long ptr = (unsigned long)inode_item;
875 ptr += offsetof(struct btrfs_inode_item, ctime);
876 return (struct btrfs_timespec *)ptr;
879 static inline struct btrfs_timespec *
880 btrfs_inode_otime(struct btrfs_inode_item *inode_item)
882 unsigned long ptr = (unsigned long)inode_item;
883 ptr += offsetof(struct btrfs_inode_item, otime);
884 return (struct btrfs_timespec *)ptr;
887 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
888 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
889 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
891 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
894 /* struct btrfs_dev_extent */
895 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
897 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
899 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
901 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
903 static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
905 unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
906 return (u8 *)((unsigned long)dev + ptr);
909 /* struct btrfs_extent_item */
910 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
912 /* struct btrfs_extent_ref */
913 BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
914 BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
915 BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
916 BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
918 BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
919 BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
921 BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
923 BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64);
925 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
928 /* struct btrfs_node */
929 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
930 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
932 static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
935 ptr = offsetof(struct btrfs_node, ptrs) +
936 sizeof(struct btrfs_key_ptr) * nr;
937 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
940 static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
944 ptr = offsetof(struct btrfs_node, ptrs) +
945 sizeof(struct btrfs_key_ptr) * nr;
946 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
949 static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
952 ptr = offsetof(struct btrfs_node, ptrs) +
953 sizeof(struct btrfs_key_ptr) * nr;
954 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
957 static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
961 ptr = offsetof(struct btrfs_node, ptrs) +
962 sizeof(struct btrfs_key_ptr) * nr;
963 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
966 static inline unsigned long btrfs_node_key_ptr_offset(int nr)
968 return offsetof(struct btrfs_node, ptrs) +
969 sizeof(struct btrfs_key_ptr) * nr;
972 static inline void btrfs_node_key(struct extent_buffer *eb,
973 struct btrfs_disk_key *disk_key, int nr)
976 ptr = btrfs_node_key_ptr_offset(nr);
977 read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
978 struct btrfs_key_ptr, key, disk_key);
981 static inline void btrfs_set_node_key(struct extent_buffer *eb,
982 struct btrfs_disk_key *disk_key, int nr)
985 ptr = btrfs_node_key_ptr_offset(nr);
986 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
987 struct btrfs_key_ptr, key, disk_key);
990 /* struct btrfs_item */
991 BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
992 BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
994 static inline unsigned long btrfs_item_nr_offset(int nr)
996 return offsetof(struct btrfs_leaf, items) +
997 sizeof(struct btrfs_item) * nr;
1000 static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
1003 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
1006 static inline u32 btrfs_item_end(struct extent_buffer *eb,
1007 struct btrfs_item *item)
1009 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
1012 static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
1014 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
1017 static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
1019 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
1022 static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
1024 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
1027 static inline void btrfs_item_key(struct extent_buffer *eb,
1028 struct btrfs_disk_key *disk_key, int nr)
1030 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1031 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
1034 static inline void btrfs_set_item_key(struct extent_buffer *eb,
1035 struct btrfs_disk_key *disk_key, int nr)
1037 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1038 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
1041 /* struct btrfs_dir_item */
1042 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
1043 BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
1044 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1045 BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
1047 static inline void btrfs_dir_item_key(struct extent_buffer *eb,
1048 struct btrfs_dir_item *item,
1049 struct btrfs_disk_key *key)
1051 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
1054 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
1055 struct btrfs_dir_item *item,
1056 struct btrfs_disk_key *key)
1058 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
1061 /* struct btrfs_disk_key */
1062 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
1064 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
1065 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
1067 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
1068 struct btrfs_disk_key *disk)
1070 cpu->offset = le64_to_cpu(disk->offset);
1071 cpu->type = disk->type;
1072 cpu->objectid = le64_to_cpu(disk->objectid);
1075 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
1076 struct btrfs_key *cpu)
1078 disk->offset = cpu_to_le64(cpu->offset);
1079 disk->type = cpu->type;
1080 disk->objectid = cpu_to_le64(cpu->objectid);
1083 static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
1084 struct btrfs_key *key, int nr)
1086 struct btrfs_disk_key disk_key;
1087 btrfs_node_key(eb, &disk_key, nr);
1088 btrfs_disk_key_to_cpu(key, &disk_key);
1091 static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
1092 struct btrfs_key *key, int nr)
1094 struct btrfs_disk_key disk_key;
1095 btrfs_item_key(eb, &disk_key, nr);
1096 btrfs_disk_key_to_cpu(key, &disk_key);
1099 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
1100 struct btrfs_dir_item *item,
1101 struct btrfs_key *key)
1103 struct btrfs_disk_key disk_key;
1104 btrfs_dir_item_key(eb, item, &disk_key);
1105 btrfs_disk_key_to_cpu(key, &disk_key);
1109 static inline u8 btrfs_key_type(struct btrfs_key *key)
1114 static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
1119 /* struct btrfs_header */
1120 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
1121 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
1123 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
1124 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
1125 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
1126 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
1128 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
1130 return (btrfs_header_flags(eb) & flag) == flag;
1133 static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
1135 u64 flags = btrfs_header_flags(eb);
1136 btrfs_set_header_flags(eb, flags | flag);
1137 return (flags & flag) == flag;
1140 static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
1142 u64 flags = btrfs_header_flags(eb);
1143 btrfs_set_header_flags(eb, flags & ~flag);
1144 return (flags & flag) == flag;
1147 static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
1149 unsigned long ptr = offsetof(struct btrfs_header, fsid);
1153 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
1155 unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
1159 static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1161 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1165 static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
1167 unsigned long ptr = offsetof(struct btrfs_header, csum);
1171 static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
1176 static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
1181 static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
1186 static inline int btrfs_is_leaf(struct extent_buffer *eb)
1188 return (btrfs_header_level(eb) == 0);
1191 /* struct btrfs_root_item */
1192 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
1193 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
1194 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
1196 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
1197 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
1198 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
1199 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
1200 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
1201 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
1202 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
1204 /* struct btrfs_super_block */
1205 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
1206 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
1208 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
1209 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
1210 struct btrfs_super_block, sys_chunk_array_size, 32);
1211 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
1213 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
1215 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
1216 chunk_root_level, 8);
1217 BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
1219 BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
1221 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
1223 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
1225 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
1227 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
1229 BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
1231 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
1233 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
1234 root_dir_objectid, 64);
1235 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
1238 static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
1240 return offsetof(struct btrfs_leaf, items);
1243 /* struct btrfs_file_extent_item */
1244 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
1246 static inline unsigned long btrfs_file_extent_inline_start(struct
1247 btrfs_file_extent_item *e)
1249 unsigned long offset = (unsigned long)e;
1250 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
1254 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
1256 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
1259 static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
1260 struct btrfs_item *e)
1262 unsigned long offset;
1263 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
1264 return btrfs_item_size(eb, e) - offset;
1267 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
1269 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
1271 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
1272 disk_num_bytes, 64);
1273 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
1275 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
1278 static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
1280 return root->leafsize;
1281 return root->nodesize;
1284 /* helper function to cast into the data area of the leaf. */
1285 #define btrfs_item_ptr(leaf, slot, type) \
1286 ((type *)(btrfs_leaf_data(leaf) + \
1287 btrfs_item_offset_nr(leaf, slot)))
1289 #define btrfs_item_ptr_offset(leaf, slot) \
1290 ((unsigned long)(btrfs_leaf_data(leaf) + \
1291 btrfs_item_offset_nr(leaf, slot)))
1294 u32 btrfs_count_snapshots_in_path(struct btrfs_root *root,
1295 struct btrfs_path *count_path,
1297 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
1298 struct btrfs_root *root);
1299 int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
1300 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
1301 btrfs_fs_info *info,
1303 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1304 struct btrfs_block_group_cache
1305 *hint, u64 search_start,
1306 int data, int owner);
1307 int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1308 struct btrfs_root *root, u64 owner_objectid);
1309 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1310 struct btrfs_root *root, u32 size,
1312 u64 hint, u64 empty_size);
1313 struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1314 struct btrfs_root *root,
1322 int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans,
1323 struct btrfs_root *root, u64 new_size);
1324 int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
1325 int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
1326 struct btrfs_root *root,
1327 struct btrfs_path *path, u64 bytenr,
1328 u64 root_objectid, u64 ref_generation,
1329 u64 owner, u64 owner_offset);
1330 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1331 struct btrfs_root *root,
1332 u64 num_bytes, u64 root_objectid, u64 ref_generation,
1333 u64 owner, u64 owner_offset,
1334 u64 empty_size, u64 hint_byte,
1335 u64 search_end, struct btrfs_key *ins, int data);
1336 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1337 struct extent_buffer *buf);
1338 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1339 *root, u64 bytenr, u64 num_bytes,
1340 u64 root_objectid, u64 ref_generation,
1341 u64 owner_objectid, u64 owner_offset, int pin);
1342 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1343 struct btrfs_root *root,
1344 struct extent_io_tree *unpin);
1345 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1346 struct btrfs_root *root,
1347 u64 bytenr, u64 num_bytes,
1348 u64 root_objectid, u64 ref_generation,
1349 u64 owner, u64 owner_offset);
1350 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1351 struct btrfs_root *root);
1352 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1353 int btrfs_read_block_groups(struct btrfs_root *root);
1354 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1355 struct btrfs_root *root, u64 bytes_used,
1356 u64 type, u64 chunk_objectid, u64 chunk_offset,
1358 int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
1359 struct btrfs_root *root);
1360 u64 btrfs_hash_extent_ref(u64 root_objectid, u64 ref_generation,
1361 u64 owner, u64 owner_offset);
1362 int btrfs_update_block_group(struct btrfs_trans_handle *trans,
1363 struct btrfs_root *root, u64 bytenr, u64 num,
1364 int alloc, int mark_free);
1366 int btrfs_previous_item(struct btrfs_root *root,
1367 struct btrfs_path *path, u64 min_objectid,
1369 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1370 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1371 struct btrfs_root *root, struct extent_buffer *buf,
1372 struct extent_buffer *parent, int parent_slot,
1373 struct extent_buffer **cow_ret);
1374 int __btrfs_cow_block(struct btrfs_trans_handle *trans,
1375 struct btrfs_root *root,
1376 struct extent_buffer *buf,
1377 struct extent_buffer *parent, int parent_slot,
1378 struct extent_buffer **cow_ret,
1379 u64 search_start, u64 empty_size);
1380 int btrfs_copy_root(struct btrfs_trans_handle *trans,
1381 struct btrfs_root *root,
1382 struct extent_buffer *buf,
1383 struct extent_buffer **cow_ret, u64 new_root_objectid);
1384 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1385 *root, struct btrfs_path *path, u32 data_size);
1386 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1387 struct btrfs_root *root,
1388 struct btrfs_path *path,
1389 u32 new_size, int from_end);
1390 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1391 *root, struct btrfs_key *key, struct btrfs_path *p, int
1393 int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1394 struct btrfs_root *root, struct extent_buffer *parent,
1395 int start_slot, int cache_only, u64 *last_ret,
1396 struct btrfs_key *progress);
1397 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1398 struct btrfs_path *btrfs_alloc_path(void);
1399 void btrfs_free_path(struct btrfs_path *p);
1400 void btrfs_init_path(struct btrfs_path *p);
1401 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1402 struct btrfs_path *path, int slot, int nr);
1404 static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
1405 struct btrfs_root *root,
1406 struct btrfs_path *path)
1408 return btrfs_del_items(trans, root, path, path->slots[0], 1);
1411 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1412 *root, struct btrfs_key *key, void *data, u32 data_size);
1413 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
1414 struct btrfs_root *root,
1415 struct btrfs_path *path,
1416 struct btrfs_key *cpu_key, u32 *data_size, int nr);
1418 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
1419 struct btrfs_root *root,
1420 struct btrfs_path *path,
1421 struct btrfs_key *key,
1424 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
1427 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1428 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
1429 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
1430 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1435 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1436 struct btrfs_key *key);
1437 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1438 *root, struct btrfs_key *key, struct btrfs_root_item
1440 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1441 *root, struct btrfs_key *key, struct btrfs_root_item
1443 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1444 btrfs_root_item *item, struct btrfs_key *key);
1445 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1446 struct btrfs_root *latest_root);
1448 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1449 *root, const char *name, int name_len, u64 dir,
1450 struct btrfs_key *location, u8 type);
1451 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1452 struct btrfs_root *root,
1453 struct btrfs_path *path, u64 dir,
1454 const char *name, int name_len,
1456 struct btrfs_dir_item *
1457 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1458 struct btrfs_root *root,
1459 struct btrfs_path *path, u64 dir,
1460 u64 objectid, const char *name, int name_len,
1462 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1463 struct btrfs_path *path,
1464 const char *name, int name_len);
1465 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1466 struct btrfs_root *root,
1467 struct btrfs_path *path,
1468 struct btrfs_dir_item *di);
1469 int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
1470 struct btrfs_root *root, const char *name,
1471 u16 name_len, const void *data, u16 data_len,
1473 struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
1474 struct btrfs_root *root,
1475 struct btrfs_path *path, u64 dir,
1476 const char *name, u16 name_len,
1479 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1480 struct btrfs_root *fs_root,
1481 u64 dirid, u64 *objectid);
1482 int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1485 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
1486 struct btrfs_root *root,
1487 const char *name, int name_len,
1488 u64 inode_objectid, u64 ref_objectid, u64 index);
1489 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
1490 struct btrfs_root *root,
1491 const char *name, int name_len,
1492 u64 inode_objectid, u64 ref_objectid);
1493 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1494 struct btrfs_root *root,
1495 struct btrfs_path *path, u64 objectid);
1496 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1497 *root, u64 objectid, struct btrfs_inode_item
1499 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1500 *root, struct btrfs_path *path,
1501 struct btrfs_key *location, int mod);
1504 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1505 struct btrfs_root *root,
1506 u64 objectid, u64 pos, u64 offset,
1509 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
1510 struct btrfs_root *root, u64 objectid,
1511 u64 offset, char *buffer, size_t size);
1512 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1513 struct btrfs_root *root,
1514 struct btrfs_path *path, u64 objectid,
1515 u64 bytenr, int mod);
1516 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1517 struct btrfs_root *root,
1518 struct btrfs_inode_item *inode,
1519 u64 objectid, u64 offset,
1520 char *data, size_t len);
1521 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1522 struct btrfs_root *root,
1523 struct btrfs_path *path,
1524 u64 objectid, u64 offset,
1526 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1527 struct btrfs_root *root, struct btrfs_path *path,