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 "_BHRfS_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
57 /* holds checksums of all the data extents */
58 #define BTRFS_CSUM_TREE_OBJECTID 7ULL
61 /* oprhan objectid for tracking unlinked/truncated files */
62 #define BTRFS_ORPHAN_OBJECTID -5ULL
64 /* does write ahead logging to speed up fsyncs */
65 #define BTRFS_TREE_LOG_OBJECTID -6ULL
66 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
69 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
70 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
73 * extent checksums all have this objectid
74 * this allows them to share the logging tree
77 #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
79 /* dummy objectid represents multiple objectids */
80 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
83 * All files have objectids in this range.
85 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
86 #define BTRFS_LAST_FREE_OBJECTID -256ULL
87 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
92 * the device items go into the chunk tree. The key is in the form
93 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
95 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
98 * we can actually store much bigger names, but lets not confuse the rest
101 #define BTRFS_NAME_LEN 255
103 /* 32 bytes in various csum fields */
104 #define BTRFS_CSUM_SIZE 32
107 #define BTRFS_CSUM_TYPE_CRC32 0
111 #define BTRFS_CSUM_TYPE_CRC32 0
113 static int btrfs_csum_sizes[] = { 4, 0 };
115 /* four bytes for CRC32 */
116 #define BTRFS_CRC32_SIZE 4
117 #define BTRFS_EMPTY_DIR_SIZE 0
119 #define BTRFS_FT_UNKNOWN 0
120 #define BTRFS_FT_REG_FILE 1
121 #define BTRFS_FT_DIR 2
122 #define BTRFS_FT_CHRDEV 3
123 #define BTRFS_FT_BLKDEV 4
124 #define BTRFS_FT_FIFO 5
125 #define BTRFS_FT_SOCK 6
126 #define BTRFS_FT_SYMLINK 7
127 #define BTRFS_FT_XATTR 8
128 #define BTRFS_FT_MAX 9
131 * the key defines the order in the tree, and so it also defines (optimal)
132 * block layout. objectid corresonds to the inode number. The flags
133 * tells us things about the object, and is a kind of stream selector.
134 * so for a given inode, keys with flags of 1 might refer to the inode
135 * data, flags of 2 may point to file data in the btree and flags == 3
136 * may point to extents.
138 * offset is the starting byte offset for this key in the stream.
140 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
141 * in cpu native order. Otherwise they are identical and their sizes
142 * should be the same (ie both packed)
144 struct btrfs_disk_key {
148 } __attribute__ ((__packed__));
154 } __attribute__ ((__packed__));
156 struct btrfs_mapping_tree {
157 struct cache_tree cache_tree;
160 #define BTRFS_UUID_SIZE 16
161 struct btrfs_dev_item {
162 /* the internal btrfs device id */
165 /* size of the device */
171 /* optimal io alignment for this device */
174 /* optimal io width for this device */
177 /* minimal io size for this device */
180 /* type and info about this device */
183 /* expected generation for this device */
187 * starting byte of this partition on the device,
188 * to allowr for stripe alignment in the future
192 /* grouping information for allocation decisions */
195 /* seek speed 0-100 where 100 is fastest */
198 /* bandwidth 0-100 where 100 is fastest */
201 /* btrfs generated uuid for this device */
202 u8 uuid[BTRFS_UUID_SIZE];
204 /* uuid of FS who owns this device */
205 u8 fsid[BTRFS_UUID_SIZE];
206 } __attribute__ ((__packed__));
208 struct btrfs_stripe {
211 u8 dev_uuid[BTRFS_UUID_SIZE];
212 } __attribute__ ((__packed__));
215 /* size of this chunk in bytes */
218 /* objectid of the root referencing this chunk */
224 /* optimal io alignment for this chunk */
227 /* optimal io width for this chunk */
230 /* minimal io size for this chunk */
233 /* 2^16 stripes is quite a lot, a second limit is the size of a single
238 /* sub stripes only matter for raid10 */
240 struct btrfs_stripe stripe;
241 /* additional stripes go here */
242 } __attribute__ ((__packed__));
244 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
246 BUG_ON(num_stripes == 0);
247 return sizeof(struct btrfs_chunk) +
248 sizeof(struct btrfs_stripe) * (num_stripes - 1);
251 #define BTRFS_FSID_SIZE 16
252 #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
255 * every tree block (leaf or node) starts with this header.
257 struct btrfs_header {
258 /* these first four must match the super block */
259 u8 csum[BTRFS_CSUM_SIZE];
260 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
261 __le64 bytenr; /* which block this node is supposed to live in */
264 /* allowed to be different from the super from here on down */
265 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
270 } __attribute__ ((__packed__));
272 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
273 sizeof(struct btrfs_header)) / \
274 sizeof(struct btrfs_key_ptr))
275 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
276 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
277 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
278 sizeof(struct btrfs_item) - \
279 sizeof(struct btrfs_file_extent_item))
281 #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
282 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
285 * this is a very generous portion of the super block, giving us
286 * room to translate 14 chunks with 3 stripes each.
288 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
289 #define BTRFS_LABEL_SIZE 256
292 * the super block basically lists the main trees of the FS
293 * it currently lacks any block count etc etc
295 struct btrfs_super_block {
296 u8 csum[BTRFS_CSUM_SIZE];
297 /* the first 3 fields must match struct btrfs_header */
298 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
299 __le64 bytenr; /* this block number */
302 /* allowed to be different from the btrfs_header from here own down */
309 /* this will help find the new super based on the log root */
310 __le64 log_root_transid;
313 __le64 root_dir_objectid;
319 __le32 sys_chunk_array_size;
320 __le64 chunk_root_generation;
322 __le64 compat_ro_flags;
323 __le64 incompat_flags;
328 struct btrfs_dev_item dev_item;
330 char label[BTRFS_LABEL_SIZE];
332 /* future expansion */
334 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
335 } __attribute__ ((__packed__));
338 * Compat flags that we support. If any incompat flags are set other than the
339 * ones specified below then we will fail to mount
341 #define BTRFS_FEATURE_COMPAT_SUPP 0x0
342 #define BTRFS_FEATURE_COMPAT_RO_SUPP 0x0
343 #define BTRFS_FEATURE_INCOMPAT_SUPP 0x0
346 * A leaf is full of items. offset and size tell us where to find
347 * the item in the leaf (relative to the start of the data area)
350 struct btrfs_disk_key key;
353 } __attribute__ ((__packed__));
356 * leaves have an item area and a data area:
357 * [item0, item1....itemN] [free space] [dataN...data1, data0]
359 * The data is separate from the items to get the keys closer together
363 struct btrfs_header header;
364 struct btrfs_item items[];
365 } __attribute__ ((__packed__));
368 * all non-leaf blocks are nodes, they hold only keys and pointers to
371 struct btrfs_key_ptr {
372 struct btrfs_disk_key key;
375 } __attribute__ ((__packed__));
378 struct btrfs_header header;
379 struct btrfs_key_ptr ptrs[];
380 } __attribute__ ((__packed__));
383 * btrfs_paths remember the path taken from the root down to the leaf.
384 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
385 * to any other levels that are present.
387 * The slots array records the index of the item or block pointer
388 * used while walking the tree.
391 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
392 int slots[BTRFS_MAX_LEVEL];
398 * items in the extent btree are used to record the objectid of the
399 * owner of the block and the number of references
401 struct btrfs_extent_item {
403 } __attribute__ ((__packed__));
405 struct btrfs_extent_ref {
410 } __attribute__ ((__packed__));
412 /* dev extents record free space on individual devices. The owner
413 * field points back to the chunk allocation mapping tree that allocated
414 * the extent. The chunk tree uuid field is a way to double check the owner
416 struct btrfs_dev_extent {
418 __le64 chunk_objectid;
421 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
422 } __attribute__ ((__packed__));
424 struct btrfs_inode_ref {
428 } __attribute__ ((__packed__));
430 struct btrfs_timespec {
433 } __attribute__ ((__packed__));
436 BTRFS_COMPRESS_NONE = 0,
437 BTRFS_COMPRESS_ZLIB = 1,
438 BTRFS_COMPRESS_LAST = 2,
439 } btrfs_compression_type;
441 /* we don't understand any encryption methods right now */
443 BTRFS_ENCRYPTION_NONE = 0,
444 BTRFS_ENCRYPTION_LAST = 1,
445 } btrfs_encryption_type;
447 struct btrfs_inode_item {
448 /* nfs style generation number */
450 /* transid that last touched this inode */
462 /* modification sequence number for NFS */
466 * a little future expansion, for more than this we can
467 * just grow the inode item and version it
470 struct btrfs_timespec atime;
471 struct btrfs_timespec ctime;
472 struct btrfs_timespec mtime;
473 struct btrfs_timespec otime;
474 } __attribute__ ((__packed__));
476 struct btrfs_dir_item {
477 struct btrfs_disk_key location;
482 } __attribute__ ((__packed__));
484 struct btrfs_root_item {
485 struct btrfs_inode_item inode;
491 __le64 last_snapshot;
494 struct btrfs_disk_key drop_progress;
497 } __attribute__ ((__packed__));
500 * this is used for both forward and backward root refs
502 struct btrfs_root_ref {
506 } __attribute__ ((__packed__));
508 #define BTRFS_FILE_EXTENT_INLINE 0
509 #define BTRFS_FILE_EXTENT_REG 1
510 #define BTRFS_FILE_EXTENT_PREALLOC 2
512 struct btrfs_file_extent_item {
514 * transaction id that created this extent
518 * max number of bytes to hold this extent in ram
519 * when we split a compressed extent we can't know how big
520 * each of the resulting pieces will be. So, this is
521 * an upper limit on the size of the extent in ram instead of
527 * 32 bits for the various ways we might encode the data,
528 * including compression and encryption. If any of these
529 * are set to something a given disk format doesn't understand
530 * it is treated like an incompat flag for reading and writing,
535 __le16 other_encoding; /* spare for later use */
537 /* are we inline data or a real extent? */
541 * disk space consumed by the extent, checksum blocks are included
545 __le64 disk_num_bytes;
547 * the logical offset in file blocks (no csums)
548 * this extent record is for. This allows a file extent to point
549 * into the middle of an existing extent on disk, sharing it
550 * between two snapshots (useful if some bytes in the middle of the
551 * extent have changed
555 * the logical number of file blocks (no csums included)
559 } __attribute__ ((__packed__));
561 struct btrfs_csum_item {
563 } __attribute__ ((__packed__));
565 /* tag for the radix tree of block groups in ram */
566 #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
567 #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
568 #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
569 #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
570 #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
571 #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
572 #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
574 struct btrfs_block_group_item {
576 __le64 chunk_objectid;
578 } __attribute__ ((__packed__));
580 struct btrfs_space_info {
586 struct list_head list;
589 struct btrfs_block_group_cache {
590 struct cache_extent cache;
591 struct btrfs_key key;
592 struct btrfs_block_group_item item;
593 struct btrfs_space_info *space_info;
600 struct btrfs_extent_ops {
601 int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
602 u64 hint_byte, struct btrfs_key *ins);
603 int (*free_extent)(struct btrfs_root *root, u64 bytenr,
608 struct btrfs_fs_devices;
609 struct btrfs_fs_info {
610 u8 fsid[BTRFS_FSID_SIZE];
611 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
612 struct btrfs_root *fs_root;
613 struct btrfs_root *extent_root;
614 struct btrfs_root *tree_root;
615 struct btrfs_root *chunk_root;
616 struct btrfs_root *dev_root;
617 struct btrfs_root *csum_root;
619 /* the log root tree is a directory of all the other log roots */
620 struct btrfs_root *log_root_tree;
622 struct extent_io_tree extent_cache;
623 struct extent_io_tree free_space_cache;
624 struct extent_io_tree block_group_cache;
625 struct extent_io_tree pinned_extents;
626 struct extent_io_tree pending_del;
627 struct extent_io_tree extent_ins;
629 /* logical->physical extent mapping */
630 struct btrfs_mapping_tree mapping_tree;
633 u64 last_trans_committed;
635 u64 avail_data_alloc_bits;
636 u64 avail_metadata_alloc_bits;
637 u64 avail_system_alloc_bits;
638 u64 data_alloc_profile;
639 u64 metadata_alloc_profile;
640 u64 system_alloc_profile;
643 struct btrfs_trans_handle *running_transaction;
644 struct btrfs_super_block super_copy;
645 struct extent_buffer *sb_buffer;
646 struct mutex fs_mutex;
649 struct btrfs_extent_ops *extent_ops;
650 struct list_head dirty_cowonly_roots;
652 struct btrfs_fs_devices *fs_devices;
653 struct list_head space_info;
659 * in ram representation of the tree. extent_root is used for all allocations
660 * and for the extent tree extent_root root.
663 struct extent_buffer *node;
664 struct extent_buffer *commit_root;
665 struct btrfs_root_item root_item;
666 struct btrfs_key root_key;
667 struct btrfs_fs_info *fs_info;
671 /* data allocations are done in sectorsize units */
674 /* node allocations are done in nodesize units */
677 /* leaf allocations are done in leafsize units */
680 /* leaf allocations are done in leafsize units */
689 u64 last_inode_alloc;
691 /* the dirty list is only used by non-reference counted roots */
692 struct list_head dirty_list;
696 * inode items have the data typically returned from stat and store other
697 * info about object characteristics. There is one for every file and dir in
700 #define BTRFS_INODE_ITEM_KEY 1
701 #define BTRFS_INODE_REF_KEY 12
702 #define BTRFS_XATTR_ITEM_KEY 24
703 #define BTRFS_ORPHAN_ITEM_KEY 48
705 #define BTRFS_DIR_LOG_ITEM_KEY 60
706 #define BTRFS_DIR_LOG_INDEX_KEY 72
708 * dir items are the name -> inode pointers in a directory. There is one
709 * for every name in a directory.
711 #define BTRFS_DIR_ITEM_KEY 84
712 #define BTRFS_DIR_INDEX_KEY 96
715 * extent data is for file data
717 #define BTRFS_EXTENT_DATA_KEY 108
720 * csum items have the checksums for data in the extents
722 #define BTRFS_CSUM_ITEM_KEY 120
724 * extent csums are stored in a separate tree and hold csums for
725 * an entire extent on disk.
727 #define BTRFS_EXTENT_CSUM_KEY 128
730 * root items point to tree roots. There are typically in the root
731 * tree used by the super block to find all the other trees
733 #define BTRFS_ROOT_ITEM_KEY 132
736 * root backrefs tie subvols and snapshots to the directory entries that
739 #define BTRFS_ROOT_BACKREF_KEY 144
742 * root refs make a fast index for listing all of the snapshots and
743 * subvolumes referenced by a given root. They point directly to the
744 * directory item in the root that references the subvol
746 #define BTRFS_ROOT_REF_KEY 156
749 * extent items are in the extent map tree. These record which blocks
750 * are used, and how many references there are to each block
752 #define BTRFS_EXTENT_ITEM_KEY 168
753 #define BTRFS_EXTENT_REF_KEY 180
756 * block groups give us hints into the extent allocation trees. Which
757 * blocks are free etc etc
759 #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
761 #define BTRFS_DEV_EXTENT_KEY 204
762 #define BTRFS_DEV_ITEM_KEY 216
763 #define BTRFS_CHUNK_ITEM_KEY 228
766 * string items are for debugging. They just store a short string of
769 #define BTRFS_STRING_ITEM_KEY 253
773 #define BTRFS_INODE_NODATASUM (1 << 0)
774 #define BTRFS_INODE_NODATACOW (1 << 1)
775 #define BTRFS_INODE_READONLY (1 << 2)
777 #define read_eb_member(eb, ptr, type, member, result) ( \
778 read_extent_buffer(eb, (char *)(result), \
779 ((unsigned long)(ptr)) + \
780 offsetof(type, member), \
781 sizeof(((type *)0)->member)))
783 #define write_eb_member(eb, ptr, type, member, result) ( \
784 write_extent_buffer(eb, (char *)(result), \
785 ((unsigned long)(ptr)) + \
786 offsetof(type, member), \
787 sizeof(((type *)0)->member)))
789 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
790 static inline u##bits btrfs_##name(struct extent_buffer *eb) \
792 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
793 return le##bits##_to_cpu(h->member); \
795 static inline void btrfs_set_##name(struct extent_buffer *eb, \
798 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
799 h->member = cpu_to_le##bits(val); \
802 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
803 static inline u##bits btrfs_##name(struct extent_buffer *eb, \
806 unsigned long offset = (unsigned long)s; \
807 type *p = (type *) (eb->data + offset); \
808 return le##bits##_to_cpu(p->member); \
810 static inline void btrfs_set_##name(struct extent_buffer *eb, \
811 type *s, u##bits val) \
813 unsigned long offset = (unsigned long)s; \
814 type *p = (type *) (eb->data + offset); \
815 p->member = cpu_to_le##bits(val); \
818 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
819 static inline u##bits btrfs_##name(type *s) \
821 return le##bits##_to_cpu(s->member); \
823 static inline void btrfs_set_##name(type *s, u##bits val) \
825 s->member = cpu_to_le##bits(val); \
828 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
829 BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
830 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
831 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
832 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
833 BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item,
835 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
836 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
837 BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
838 BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
839 BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
840 BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
842 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
843 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
845 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
847 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
849 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
851 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
853 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
854 BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
856 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
858 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
860 BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
863 static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
865 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
868 static inline char *btrfs_device_fsid(struct btrfs_dev_item *d)
870 return (char *)d + offsetof(struct btrfs_dev_item, fsid);
873 BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
874 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
875 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
876 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
877 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
878 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
879 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
880 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
881 BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
882 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
883 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
885 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
887 return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
890 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
891 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
892 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
894 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
896 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
898 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
900 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
901 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
903 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
905 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
906 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
908 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
911 unsigned long offset = (unsigned long)c;
912 offset += offsetof(struct btrfs_chunk, stripe);
913 offset += nr * sizeof(struct btrfs_stripe);
914 return (struct btrfs_stripe *)offset;
917 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
919 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
922 static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
923 struct btrfs_chunk *c, int nr)
925 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
928 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
929 struct btrfs_chunk *c, int nr,
932 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
935 static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
936 struct btrfs_chunk *c, int nr)
938 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
941 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
942 struct btrfs_chunk *c, int nr,
945 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
948 /* struct btrfs_block_group_item */
949 BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
951 BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
953 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
954 struct btrfs_block_group_item, chunk_objectid, 64);
956 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
957 struct btrfs_block_group_item, chunk_objectid, 64);
958 BTRFS_SETGET_FUNCS(disk_block_group_flags,
959 struct btrfs_block_group_item, flags, 64);
960 BTRFS_SETGET_STACK_FUNCS(block_group_flags,
961 struct btrfs_block_group_item, flags, 64);
963 /* struct btrfs_inode_ref */
964 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
965 BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
967 /* struct btrfs_inode_item */
968 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
969 BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
970 BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
971 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
972 BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
973 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
974 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
975 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
976 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
977 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
978 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
979 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
981 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
982 struct btrfs_inode_item, generation, 64);
983 BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence,
984 struct btrfs_inode_item, generation, 64);
985 BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
986 struct btrfs_inode_item, size, 64);
987 BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes,
988 struct btrfs_inode_item, nbytes, 64);
989 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
990 struct btrfs_inode_item, block_group, 64);
991 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
992 struct btrfs_inode_item, nlink, 32);
993 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
994 struct btrfs_inode_item, uid, 32);
995 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
996 struct btrfs_inode_item, gid, 32);
997 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
998 struct btrfs_inode_item, mode, 32);
999 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
1000 struct btrfs_inode_item, rdev, 64);
1001 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
1002 struct btrfs_inode_item, flags, 64);
1004 static inline struct btrfs_timespec *
1005 btrfs_inode_atime(struct btrfs_inode_item *inode_item)
1007 unsigned long ptr = (unsigned long)inode_item;
1008 ptr += offsetof(struct btrfs_inode_item, atime);
1009 return (struct btrfs_timespec *)ptr;
1012 static inline struct btrfs_timespec *
1013 btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
1015 unsigned long ptr = (unsigned long)inode_item;
1016 ptr += offsetof(struct btrfs_inode_item, mtime);
1017 return (struct btrfs_timespec *)ptr;
1020 static inline struct btrfs_timespec *
1021 btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
1023 unsigned long ptr = (unsigned long)inode_item;
1024 ptr += offsetof(struct btrfs_inode_item, ctime);
1025 return (struct btrfs_timespec *)ptr;
1028 static inline struct btrfs_timespec *
1029 btrfs_inode_otime(struct btrfs_inode_item *inode_item)
1031 unsigned long ptr = (unsigned long)inode_item;
1032 ptr += offsetof(struct btrfs_inode_item, otime);
1033 return (struct btrfs_timespec *)ptr;
1036 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
1037 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
1038 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
1040 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
1043 /* struct btrfs_dev_extent */
1044 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
1046 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
1047 chunk_objectid, 64);
1048 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
1050 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
1052 static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
1054 unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
1055 return (u8 *)((unsigned long)dev + ptr);
1058 /* struct btrfs_extent_ref */
1059 BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
1060 BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
1061 BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
1062 BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32);
1064 BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
1065 BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
1067 BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
1069 BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref,
1072 /* struct btrfs_extent_item */
1073 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
1074 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
1077 /* struct btrfs_node */
1078 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
1079 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
1081 static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
1084 ptr = offsetof(struct btrfs_node, ptrs) +
1085 sizeof(struct btrfs_key_ptr) * nr;
1086 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
1089 static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
1093 ptr = offsetof(struct btrfs_node, ptrs) +
1094 sizeof(struct btrfs_key_ptr) * nr;
1095 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
1098 static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
1101 ptr = offsetof(struct btrfs_node, ptrs) +
1102 sizeof(struct btrfs_key_ptr) * nr;
1103 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
1106 static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
1110 ptr = offsetof(struct btrfs_node, ptrs) +
1111 sizeof(struct btrfs_key_ptr) * nr;
1112 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
1115 static inline unsigned long btrfs_node_key_ptr_offset(int nr)
1117 return offsetof(struct btrfs_node, ptrs) +
1118 sizeof(struct btrfs_key_ptr) * nr;
1121 static inline void btrfs_node_key(struct extent_buffer *eb,
1122 struct btrfs_disk_key *disk_key, int nr)
1125 ptr = btrfs_node_key_ptr_offset(nr);
1126 read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1127 struct btrfs_key_ptr, key, disk_key);
1130 static inline void btrfs_set_node_key(struct extent_buffer *eb,
1131 struct btrfs_disk_key *disk_key, int nr)
1134 ptr = btrfs_node_key_ptr_offset(nr);
1135 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1136 struct btrfs_key_ptr, key, disk_key);
1139 /* struct btrfs_item */
1140 BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
1141 BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
1143 static inline unsigned long btrfs_item_nr_offset(int nr)
1145 return offsetof(struct btrfs_leaf, items) +
1146 sizeof(struct btrfs_item) * nr;
1149 static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
1152 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
1155 static inline u32 btrfs_item_end(struct extent_buffer *eb,
1156 struct btrfs_item *item)
1158 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
1161 static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
1163 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
1166 static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
1168 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
1171 static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
1173 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
1176 static inline void btrfs_item_key(struct extent_buffer *eb,
1177 struct btrfs_disk_key *disk_key, int nr)
1179 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1180 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
1183 static inline void btrfs_set_item_key(struct extent_buffer *eb,
1184 struct btrfs_disk_key *disk_key, int nr)
1186 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1187 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
1191 * struct btrfs_root_ref
1193 BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
1194 BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
1195 BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
1197 /* struct btrfs_dir_item */
1198 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
1199 BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
1200 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1201 BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
1203 static inline void btrfs_dir_item_key(struct extent_buffer *eb,
1204 struct btrfs_dir_item *item,
1205 struct btrfs_disk_key *key)
1207 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
1210 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
1211 struct btrfs_dir_item *item,
1212 struct btrfs_disk_key *key)
1214 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
1217 /* struct btrfs_disk_key */
1218 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
1220 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
1221 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
1223 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
1224 struct btrfs_disk_key *disk)
1226 cpu->offset = le64_to_cpu(disk->offset);
1227 cpu->type = disk->type;
1228 cpu->objectid = le64_to_cpu(disk->objectid);
1231 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
1232 struct btrfs_key *cpu)
1234 disk->offset = cpu_to_le64(cpu->offset);
1235 disk->type = cpu->type;
1236 disk->objectid = cpu_to_le64(cpu->objectid);
1239 static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
1240 struct btrfs_key *key, int nr)
1242 struct btrfs_disk_key disk_key;
1243 btrfs_node_key(eb, &disk_key, nr);
1244 btrfs_disk_key_to_cpu(key, &disk_key);
1247 static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
1248 struct btrfs_key *key, int nr)
1250 struct btrfs_disk_key disk_key;
1251 btrfs_item_key(eb, &disk_key, nr);
1252 btrfs_disk_key_to_cpu(key, &disk_key);
1255 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
1256 struct btrfs_dir_item *item,
1257 struct btrfs_key *key)
1259 struct btrfs_disk_key disk_key;
1260 btrfs_dir_item_key(eb, item, &disk_key);
1261 btrfs_disk_key_to_cpu(key, &disk_key);
1265 static inline u8 btrfs_key_type(struct btrfs_key *key)
1270 static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
1275 /* struct btrfs_header */
1276 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
1277 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
1279 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
1280 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
1281 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
1282 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
1284 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
1286 return (btrfs_header_flags(eb) & flag) == flag;
1289 static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
1291 u64 flags = btrfs_header_flags(eb);
1292 btrfs_set_header_flags(eb, flags | flag);
1293 return (flags & flag) == flag;
1296 static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
1298 u64 flags = btrfs_header_flags(eb);
1299 btrfs_set_header_flags(eb, flags & ~flag);
1300 return (flags & flag) == flag;
1303 static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
1305 unsigned long ptr = offsetof(struct btrfs_header, fsid);
1309 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
1311 unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
1315 static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1317 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1321 static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
1323 unsigned long ptr = offsetof(struct btrfs_header, csum);
1327 static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
1332 static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
1337 static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
1342 static inline int btrfs_is_leaf(struct extent_buffer *eb)
1344 return (btrfs_header_level(eb) == 0);
1347 /* struct btrfs_root_item */
1348 BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
1350 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
1351 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
1352 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
1354 BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
1356 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
1357 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
1358 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
1359 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
1360 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
1361 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
1362 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
1363 BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
1367 /* struct btrfs_super_block */
1369 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
1370 BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
1371 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
1373 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
1374 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
1375 struct btrfs_super_block, sys_chunk_array_size, 32);
1376 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
1377 struct btrfs_super_block, chunk_root_generation, 64);
1378 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
1380 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
1382 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
1383 chunk_root_level, 8);
1384 BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
1386 BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
1387 log_root_transid, 64);
1388 BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
1390 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
1392 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
1394 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
1396 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
1398 BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
1400 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
1402 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
1403 root_dir_objectid, 64);
1404 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
1406 BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
1408 BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
1410 BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
1411 incompat_flags, 64);
1412 BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
1415 static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
1417 int t = btrfs_super_csum_type(s);
1418 BUG_ON(t >= ARRAY_SIZE(btrfs_csum_sizes));
1419 return btrfs_csum_sizes[t];
1422 static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
1424 return offsetof(struct btrfs_leaf, items);
1427 /* struct btrfs_file_extent_item */
1428 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
1430 static inline unsigned long btrfs_file_extent_inline_start(struct
1431 btrfs_file_extent_item *e)
1433 unsigned long offset = (unsigned long)e;
1434 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
1438 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
1440 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
1443 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
1445 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
1447 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
1448 disk_num_bytes, 64);
1449 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
1451 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
1453 BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
1455 BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
1457 BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
1459 BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
1460 other_encoding, 16);
1462 /* this returns the number of file bytes represented by the inline item.
1463 * If an item is compressed, this is the uncompressed size
1465 static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
1466 struct btrfs_file_extent_item *e)
1468 return btrfs_file_extent_ram_bytes(eb, e);
1472 * this returns the number of bytes used by the item on disk, minus the
1473 * size of any extent headers. If a file is compressed on disk, this is
1474 * the compressed size
1476 static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
1477 struct btrfs_item *e)
1479 unsigned long offset;
1480 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
1481 return btrfs_item_size(eb, e) - offset;
1484 static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
1486 return root->leafsize;
1487 return root->nodesize;
1490 /* helper function to cast into the data area of the leaf. */
1491 #define btrfs_item_ptr(leaf, slot, type) \
1492 ((type *)(btrfs_leaf_data(leaf) + \
1493 btrfs_item_offset_nr(leaf, slot)))
1495 #define btrfs_item_ptr_offset(leaf, slot) \
1496 ((unsigned long)(btrfs_leaf_data(leaf) + \
1497 btrfs_item_offset_nr(leaf, slot)))
1500 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
1501 struct btrfs_root *root);
1502 int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
1503 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
1504 btrfs_fs_info *info,
1506 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1507 struct btrfs_block_group_cache
1508 *hint, u64 search_start,
1509 int data, int owner);
1510 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1511 struct btrfs_root *root,
1512 u32 blocksize, u64 parent,
1518 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1519 struct btrfs_root *root,
1520 u64 num_bytes, u64 parent,
1521 u64 root_objectid, u64 ref_generation,
1522 u64 owner, u64 empty_size, u64 hint_byte,
1523 u64 search_end, struct btrfs_key *ins, int data);
1524 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1525 struct extent_buffer *orig_buf, struct extent_buffer *buf,
1527 int btrfs_update_ref(struct btrfs_trans_handle *trans,
1528 struct btrfs_root *root, struct extent_buffer *orig_buf,
1529 struct extent_buffer *buf, int start_slot, int nr);
1530 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1531 *root, u64 bytenr, u64 num_bytes, u64 parent,
1532 u64 root_objectid, u64 ref_generation,
1533 u64 owner_objectid, int pin);
1534 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1535 struct btrfs_root *root,
1536 struct extent_io_tree *unpin);
1537 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1538 struct btrfs_root *root,
1539 u64 bytenr, u64 num_bytes, u64 parent,
1540 u64 root_objectid, u64 ref_generation,
1541 u64 owner_objectid);
1542 int btrfs_update_extent_ref(struct btrfs_trans_handle *trans,
1543 struct btrfs_root *root, u64 bytenr,
1544 u64 orig_parent, u64 parent,
1545 u64 root_objectid, u64 ref_generation,
1546 u64 owner_objectid);
1547 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1548 struct btrfs_root *root);
1549 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1550 int btrfs_read_block_groups(struct btrfs_root *root);
1551 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1552 struct btrfs_root *root, u64 bytes_used,
1553 u64 type, u64 chunk_objectid, u64 chunk_offset,
1555 int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
1556 struct btrfs_root *root);
1557 int btrfs_update_block_group(struct btrfs_trans_handle *trans,
1558 struct btrfs_root *root, u64 bytenr, u64 num,
1559 int alloc, int mark_free);
1561 int btrfs_previous_item(struct btrfs_root *root,
1562 struct btrfs_path *path, u64 min_objectid,
1564 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1565 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1566 struct btrfs_root *root, struct extent_buffer *buf,
1567 struct extent_buffer *parent, int parent_slot,
1568 struct extent_buffer **cow_ret);
1569 int __btrfs_cow_block(struct btrfs_trans_handle *trans,
1570 struct btrfs_root *root,
1571 struct extent_buffer *buf,
1572 struct extent_buffer *parent, int parent_slot,
1573 struct extent_buffer **cow_ret,
1574 u64 search_start, u64 empty_size);
1575 int btrfs_copy_root(struct btrfs_trans_handle *trans,
1576 struct btrfs_root *root,
1577 struct extent_buffer *buf,
1578 struct extent_buffer **cow_ret, u64 new_root_objectid);
1579 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1580 *root, struct btrfs_path *path, u32 data_size);
1581 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1582 struct btrfs_root *root,
1583 struct btrfs_path *path,
1584 u32 new_size, int from_end);
1585 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1586 *root, struct btrfs_key *key, struct btrfs_path *p, int
1588 int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1589 struct btrfs_root *root, struct extent_buffer *parent,
1590 int start_slot, int cache_only, u64 *last_ret,
1591 struct btrfs_key *progress);
1592 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1593 struct btrfs_path *btrfs_alloc_path(void);
1594 void btrfs_free_path(struct btrfs_path *p);
1595 void btrfs_init_path(struct btrfs_path *p);
1596 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1597 struct btrfs_path *path, int slot, int nr);
1599 static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
1600 struct btrfs_root *root,
1601 struct btrfs_path *path)
1603 return btrfs_del_items(trans, root, path, path->slots[0], 1);
1606 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1607 *root, struct btrfs_key *key, void *data, u32 data_size);
1608 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
1609 struct btrfs_root *root,
1610 struct btrfs_path *path,
1611 struct btrfs_key *cpu_key, u32 *data_size, int nr);
1613 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
1614 struct btrfs_root *root,
1615 struct btrfs_path *path,
1616 struct btrfs_key *key,
1619 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
1622 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1623 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
1624 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
1625 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1627 int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
1628 struct btrfs_root *root, struct btrfs_path *path,
1629 struct btrfs_key *new_key);
1632 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1633 struct btrfs_key *key);
1634 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1635 *root, struct btrfs_key *key, struct btrfs_root_item
1637 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1638 *root, struct btrfs_key *key, struct btrfs_root_item
1640 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1641 btrfs_root_item *item, struct btrfs_key *key);
1642 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1643 struct btrfs_root *latest_root);
1645 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1646 *root, const char *name, int name_len, u64 dir,
1647 struct btrfs_key *location, u8 type);
1648 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1649 struct btrfs_root *root,
1650 struct btrfs_path *path, u64 dir,
1651 const char *name, int name_len,
1653 struct btrfs_dir_item *
1654 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1655 struct btrfs_root *root,
1656 struct btrfs_path *path, u64 dir,
1657 u64 objectid, const char *name, int name_len,
1659 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1660 struct btrfs_path *path,
1661 const char *name, int name_len);
1662 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1663 struct btrfs_root *root,
1664 struct btrfs_path *path,
1665 struct btrfs_dir_item *di);
1666 int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
1667 struct btrfs_root *root, const char *name,
1668 u16 name_len, const void *data, u16 data_len,
1670 struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
1671 struct btrfs_root *root,
1672 struct btrfs_path *path, u64 dir,
1673 const char *name, u16 name_len,
1676 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1677 struct btrfs_root *fs_root,
1678 u64 dirid, u64 *objectid);
1679 int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1682 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
1683 struct btrfs_root *root,
1684 const char *name, int name_len,
1685 u64 inode_objectid, u64 ref_objectid, u64 index);
1686 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
1687 struct btrfs_root *root,
1688 const char *name, int name_len,
1689 u64 inode_objectid, u64 ref_objectid);
1690 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1691 struct btrfs_root *root,
1692 struct btrfs_path *path, u64 objectid);
1693 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1694 *root, u64 objectid, struct btrfs_inode_item
1696 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1697 *root, struct btrfs_path *path,
1698 struct btrfs_key *location, int mod);
1701 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1702 struct btrfs_root *root,
1703 u64 objectid, u64 pos, u64 offset,
1706 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
1707 struct btrfs_root *root, u64 objectid,
1708 u64 offset, char *buffer, size_t size);
1709 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1710 struct btrfs_root *root,
1711 struct btrfs_path *path, u64 objectid,
1712 u64 bytenr, int mod);
1713 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1714 struct btrfs_root *root,
1715 struct btrfs_inode_item *inode,
1716 u64 objectid, u64 offset,
1717 char *data, size_t len);
1718 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1719 struct btrfs_root *root,
1720 struct btrfs_path *path,
1721 u64 objectid, u64 offset,
1723 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1724 struct btrfs_root *root, struct btrfs_path *path,