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 "_BDRfS_M"
32 #define BTRFS_MAX_LEVEL 8
34 /* holds pointers to all of the tree roots */
35 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
37 /* stores information about which extents are in use, and reference counts */
38 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
41 * chunk tree stores translations from logical -> physical block numbering
42 * the super block points to the chunk tree
44 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
47 * stores information about which areas of a given device are in use.
48 * one per device. The tree of tree roots points to the device tree
50 #define BTRFS_DEV_TREE_OBJECTID 4ULL
52 /* one per subvolume, storing files and directories */
53 #define BTRFS_FS_TREE_OBJECTID 5ULL
55 /* directory objectid inside the root tree */
56 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
58 /* oprhan objectid for tracking unlinked/truncated files */
59 #define BTRFS_ORPHAN_OBJECTID -5ULL
61 /* does write ahead logging to speed up fsyncs */
62 #define BTRFS_TREE_LOG_OBJECTID -6ULL
63 #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
66 #define BTRFS_TREE_RELOC_OBJECTID -8ULL
67 #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
69 /* dummy objectid represents multiple objectids */
70 #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
73 * All files have objectids in this range.
75 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
76 #define BTRFS_LAST_FREE_OBJECTID -256ULL
77 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
82 * the device items go into the chunk tree. The key is in the form
83 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
85 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
88 * we can actually store much bigger names, but lets not confuse the rest
91 #define BTRFS_NAME_LEN 255
93 /* 32 bytes in various csum fields */
94 #define BTRFS_CSUM_SIZE 32
95 /* four bytes for CRC32 */
96 #define BTRFS_CRC32_SIZE 4
97 #define BTRFS_EMPTY_DIR_SIZE 0
99 #define BTRFS_FT_UNKNOWN 0
100 #define BTRFS_FT_REG_FILE 1
101 #define BTRFS_FT_DIR 2
102 #define BTRFS_FT_CHRDEV 3
103 #define BTRFS_FT_BLKDEV 4
104 #define BTRFS_FT_FIFO 5
105 #define BTRFS_FT_SOCK 6
106 #define BTRFS_FT_SYMLINK 7
107 #define BTRFS_FT_XATTR 8
108 #define BTRFS_FT_MAX 9
111 * the key defines the order in the tree, and so it also defines (optimal)
112 * block layout. objectid corresonds to the inode number. The flags
113 * tells us things about the object, and is a kind of stream selector.
114 * so for a given inode, keys with flags of 1 might refer to the inode
115 * data, flags of 2 may point to file data in the btree and flags == 3
116 * may point to extents.
118 * offset is the starting byte offset for this key in the stream.
120 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
121 * in cpu native order. Otherwise they are identical and their sizes
122 * should be the same (ie both packed)
124 struct btrfs_disk_key {
128 } __attribute__ ((__packed__));
134 } __attribute__ ((__packed__));
136 struct btrfs_mapping_tree {
137 struct cache_tree cache_tree;
140 #define BTRFS_UUID_SIZE 16
141 struct btrfs_dev_item {
142 /* the internal btrfs device id */
145 /* size of the device */
151 /* optimal io alignment for this device */
154 /* optimal io width for this device */
157 /* minimal io size for this device */
160 /* type and info about this device */
163 /* expected generation for this device */
166 /* grouping information for allocation decisions */
169 /* seek speed 0-100 where 100 is fastest */
172 /* bandwidth 0-100 where 100 is fastest */
175 /* btrfs generated uuid for this device */
176 u8 uuid[BTRFS_UUID_SIZE];
178 /* uuid of FS who owns this device */
179 u8 fsid[BTRFS_UUID_SIZE];
180 } __attribute__ ((__packed__));
182 struct btrfs_stripe {
185 u8 dev_uuid[BTRFS_UUID_SIZE];
186 } __attribute__ ((__packed__));
189 /* size of this chunk in bytes */
192 /* objectid of the root referencing this chunk */
198 /* optimal io alignment for this chunk */
201 /* optimal io width for this chunk */
204 /* minimal io size for this chunk */
207 /* 2^16 stripes is quite a lot, a second limit is the size of a single
212 /* sub stripes only matter for raid10 */
214 struct btrfs_stripe stripe;
215 /* additional stripes go here */
216 } __attribute__ ((__packed__));
218 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
220 BUG_ON(num_stripes == 0);
221 return sizeof(struct btrfs_chunk) +
222 sizeof(struct btrfs_stripe) * (num_stripes - 1);
225 #define BTRFS_FSID_SIZE 16
226 #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
229 * every tree block (leaf or node) starts with this header.
231 struct btrfs_header {
232 /* these first four must match the super block */
233 u8 csum[BTRFS_CSUM_SIZE];
234 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
235 __le64 bytenr; /* which block this node is supposed to live in */
238 /* allowed to be different from the super from here on down */
239 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
244 } __attribute__ ((__packed__));
246 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
247 sizeof(struct btrfs_header)) / \
248 sizeof(struct btrfs_key_ptr))
249 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
250 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
251 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
252 sizeof(struct btrfs_item) - \
253 sizeof(struct btrfs_file_extent_item))
255 #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
258 * this is a very generous portion of the super block, giving us
259 * room to translate 14 chunks with 3 stripes each.
261 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
262 #define BTRFS_LABEL_SIZE 256
265 * the super block basically lists the main trees of the FS
266 * it currently lacks any block count etc etc
268 struct btrfs_super_block {
269 u8 csum[BTRFS_CSUM_SIZE];
270 /* the first 3 fields must match struct btrfs_header */
271 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
272 __le64 bytenr; /* this block number */
275 /* allowed to be different from the btrfs_header from here own down */
283 __le64 root_dir_objectid;
289 __le32 sys_chunk_array_size;
290 __le64 chunk_root_generation;
294 struct btrfs_dev_item dev_item;
295 char label[BTRFS_LABEL_SIZE];
296 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
297 } __attribute__ ((__packed__));
300 * A leaf is full of items. offset and size tell us where to find
301 * the item in the leaf (relative to the start of the data area)
304 struct btrfs_disk_key key;
307 } __attribute__ ((__packed__));
310 * leaves have an item area and a data area:
311 * [item0, item1....itemN] [free space] [dataN...data1, data0]
313 * The data is separate from the items to get the keys closer together
317 struct btrfs_header header;
318 struct btrfs_item items[];
319 } __attribute__ ((__packed__));
322 * all non-leaf blocks are nodes, they hold only keys and pointers to
325 struct btrfs_key_ptr {
326 struct btrfs_disk_key key;
329 } __attribute__ ((__packed__));
332 struct btrfs_header header;
333 struct btrfs_key_ptr ptrs[];
334 } __attribute__ ((__packed__));
337 * btrfs_paths remember the path taken from the root down to the leaf.
338 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
339 * to any other levels that are present.
341 * The slots array records the index of the item or block pointer
342 * used while walking the tree.
345 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
346 int slots[BTRFS_MAX_LEVEL];
352 * items in the extent btree are used to record the objectid of the
353 * owner of the block and the number of references
355 struct btrfs_extent_item {
357 } __attribute__ ((__packed__));
359 struct btrfs_extent_ref {
364 } __attribute__ ((__packed__));
366 /* dev extents record free space on individual devices. The owner
367 * field points back to the chunk allocation mapping tree that allocated
368 * the extent. The chunk tree uuid field is a way to double check the owner
370 struct btrfs_dev_extent {
372 __le64 chunk_objectid;
375 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
376 } __attribute__ ((__packed__));
378 struct btrfs_inode_ref {
382 } __attribute__ ((__packed__));
384 struct btrfs_timespec {
387 } __attribute__ ((__packed__));
390 BTRFS_COMPRESS_NONE = 0,
391 BTRFS_COMPRESS_ZLIB = 1,
392 BTRFS_COMPRESS_LAST = 2,
393 } btrfs_compression_type;
395 /* we don't understand any encryption methods right now */
397 BTRFS_ENCRYPTION_NONE = 0,
398 BTRFS_ENCRYPTION_LAST = 1,
399 } btrfs_encryption_type;
401 struct btrfs_inode_item {
402 /* nfs style generation number */
404 /* transid that last touched this inode */
417 struct btrfs_timespec atime;
418 struct btrfs_timespec ctime;
419 struct btrfs_timespec mtime;
420 struct btrfs_timespec otime;
421 } __attribute__ ((__packed__));
423 struct btrfs_dir_item {
424 struct btrfs_disk_key location;
429 } __attribute__ ((__packed__));
431 struct btrfs_root_item {
432 struct btrfs_inode_item inode;
438 __le64 last_snapshot;
441 struct btrfs_disk_key drop_progress;
444 } __attribute__ ((__packed__));
446 #define BTRFS_FILE_EXTENT_INLINE 0
447 #define BTRFS_FILE_EXTENT_REG 1
448 #define BTRFS_FILE_EXTENT_PREALLOC 2
450 struct btrfs_file_extent_item {
452 * transaction id that created this extent
456 * max number of bytes to hold this extent in ram
457 * when we split a compressed extent we can't know how big
458 * each of the resulting pieces will be. So, this is
459 * an upper limit on the size of the extent in ram instead of
465 * 32 bits for the various ways we might encode the data,
466 * including compression and encryption. If any of these
467 * are set to something a given disk format doesn't understand
468 * it is treated like an incompat flag for reading and writing,
473 __le16 other_encoding; /* spare for later use */
475 /* are we inline data or a real extent? */
479 * disk space consumed by the extent, checksum blocks are included
483 __le64 disk_num_bytes;
485 * the logical offset in file blocks (no csums)
486 * this extent record is for. This allows a file extent to point
487 * into the middle of an existing extent on disk, sharing it
488 * between two snapshots (useful if some bytes in the middle of the
489 * extent have changed
493 * the logical number of file blocks (no csums included)
497 } __attribute__ ((__packed__));
499 struct btrfs_csum_item {
501 } __attribute__ ((__packed__));
503 /* tag for the radix tree of block groups in ram */
504 #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
505 #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
506 #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
507 #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
508 #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
509 #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
510 #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
512 struct btrfs_block_group_item {
514 __le64 chunk_objectid;
516 } __attribute__ ((__packed__));
518 struct btrfs_space_info {
524 struct list_head list;
527 struct btrfs_block_group_cache {
528 struct cache_extent cache;
529 struct btrfs_key key;
530 struct btrfs_block_group_item item;
531 struct btrfs_space_info *space_info;
538 struct btrfs_extent_ops {
539 int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
540 u64 hint_byte, struct btrfs_key *ins);
541 int (*free_extent)(struct btrfs_root *root, u64 bytenr,
546 struct btrfs_fs_devices;
547 struct btrfs_fs_info {
548 u8 fsid[BTRFS_FSID_SIZE];
549 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
550 struct btrfs_root *fs_root;
551 struct btrfs_root *extent_root;
552 struct btrfs_root *tree_root;
553 struct btrfs_root *chunk_root;
554 struct btrfs_root *dev_root;
556 /* the log root tree is a directory of all the other log roots */
557 struct btrfs_root *log_root_tree;
559 struct extent_io_tree extent_cache;
560 struct extent_io_tree free_space_cache;
561 struct extent_io_tree block_group_cache;
562 struct extent_io_tree pinned_extents;
563 struct extent_io_tree pending_del;
564 struct extent_io_tree extent_ins;
566 /* logical->physical extent mapping */
567 struct btrfs_mapping_tree mapping_tree;
570 u64 last_trans_committed;
572 u64 avail_data_alloc_bits;
573 u64 avail_metadata_alloc_bits;
574 u64 avail_system_alloc_bits;
575 u64 data_alloc_profile;
576 u64 metadata_alloc_profile;
577 u64 system_alloc_profile;
580 struct btrfs_trans_handle *running_transaction;
581 struct btrfs_super_block super_copy;
582 struct extent_buffer *sb_buffer;
583 struct mutex fs_mutex;
586 struct btrfs_extent_ops *extent_ops;
587 struct list_head dirty_cowonly_roots;
589 struct btrfs_fs_devices *fs_devices;
590 struct list_head space_info;
596 * in ram representation of the tree. extent_root is used for all allocations
597 * and for the extent tree extent_root root.
600 struct extent_buffer *node;
601 struct extent_buffer *commit_root;
602 struct btrfs_root_item root_item;
603 struct btrfs_key root_key;
604 struct btrfs_fs_info *fs_info;
608 /* data allocations are done in sectorsize units */
611 /* node allocations are done in nodesize units */
614 /* leaf allocations are done in leafsize units */
617 /* leaf allocations are done in leafsize units */
626 u64 last_inode_alloc;
628 /* the dirty list is only used by non-reference counted roots */
629 struct list_head dirty_list;
633 * inode items have the data typically returned from stat and store other
634 * info about object characteristics. There is one for every file and dir in
637 #define BTRFS_INODE_ITEM_KEY 1
638 #define BTRFS_INODE_REF_KEY 2
639 #define BTRFS_XATTR_ITEM_KEY 8
640 #define BTRFS_ORPHAN_ITEM_KEY 9
642 /* reserve 3-15 close to the inode for later flexibility */
645 * dir items are the name -> inode pointers in a directory. There is one
646 * for every name in a directory.
648 #define BTRFS_DIR_ITEM_KEY 16
649 #define BTRFS_DIR_INDEX_KEY 17
651 * extent data is for file data
653 #define BTRFS_EXTENT_DATA_KEY 18
655 * csum items have the checksums for data in the extents
657 #define BTRFS_CSUM_ITEM_KEY 19
659 /* reserve 20-31 for other file stuff */
662 * root items point to tree roots. There are typically in the root
663 * tree used by the super block to find all the other trees
665 #define BTRFS_ROOT_ITEM_KEY 32
667 * extent items are in the extent map tree. These record which blocks
668 * are used, and how many references there are to each block
670 #define BTRFS_EXTENT_ITEM_KEY 33
671 #define BTRFS_EXTENT_REF_KEY 34
674 * block groups give us hints into the extent allocation trees. Which
675 * blocks are free etc etc
677 #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
679 #define BTRFS_DEV_EXTENT_KEY 75
680 #define BTRFS_DEV_ITEM_KEY 76
681 #define BTRFS_CHUNK_ITEM_KEY 77
684 * string items are for debugging. They just store a short string of
687 #define BTRFS_STRING_ITEM_KEY 253
691 #define BTRFS_INODE_NODATASUM (1 << 0)
692 #define BTRFS_INODE_NODATACOW (1 << 1)
693 #define BTRFS_INODE_READONLY (1 << 2)
695 #define read_eb_member(eb, ptr, type, member, result) ( \
696 read_extent_buffer(eb, (char *)(result), \
697 ((unsigned long)(ptr)) + \
698 offsetof(type, member), \
699 sizeof(((type *)0)->member)))
701 #define write_eb_member(eb, ptr, type, member, result) ( \
702 write_extent_buffer(eb, (char *)(result), \
703 ((unsigned long)(ptr)) + \
704 offsetof(type, member), \
705 sizeof(((type *)0)->member)))
707 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
708 static inline u##bits btrfs_##name(struct extent_buffer *eb) \
710 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
711 return le##bits##_to_cpu(h->member); \
713 static inline void btrfs_set_##name(struct extent_buffer *eb, \
716 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
717 h->member = cpu_to_le##bits(val); \
720 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
721 static inline u##bits btrfs_##name(struct extent_buffer *eb, \
724 unsigned long offset = (unsigned long)s; \
725 type *p = (type *) (eb->data + offset); \
726 return le##bits##_to_cpu(p->member); \
728 static inline void btrfs_set_##name(struct extent_buffer *eb, \
729 type *s, u##bits val) \
731 unsigned long offset = (unsigned long)s; \
732 type *p = (type *) (eb->data + offset); \
733 p->member = cpu_to_le##bits(val); \
736 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
737 static inline u##bits btrfs_##name(type *s) \
739 return le##bits##_to_cpu(s->member); \
741 static inline void btrfs_set_##name(type *s, u##bits val) \
743 s->member = cpu_to_le##bits(val); \
746 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
747 BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
748 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
749 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
750 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
751 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
752 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
753 BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
754 BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
755 BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
756 BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
758 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
759 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
761 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
763 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
765 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
767 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
769 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
770 BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
772 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
774 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
776 BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
779 static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
781 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
784 static inline char *btrfs_device_fsid(struct btrfs_dev_item *d)
786 return (char *)d + offsetof(struct btrfs_dev_item, fsid);
789 BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
790 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
791 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
792 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
793 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
794 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
795 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
796 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
797 BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
798 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
799 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
801 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
803 return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
806 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
807 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
808 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
810 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
812 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
814 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
816 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
817 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
819 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
821 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
822 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
824 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
827 unsigned long offset = (unsigned long)c;
828 offset += offsetof(struct btrfs_chunk, stripe);
829 offset += nr * sizeof(struct btrfs_stripe);
830 return (struct btrfs_stripe *)offset;
833 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
835 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
838 static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
839 struct btrfs_chunk *c, int nr)
841 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
844 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
845 struct btrfs_chunk *c, int nr,
848 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
851 static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
852 struct btrfs_chunk *c, int nr)
854 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
857 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
858 struct btrfs_chunk *c, int nr,
861 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
864 /* struct btrfs_block_group_item */
865 BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
867 BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
869 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
870 struct btrfs_block_group_item, chunk_objectid, 64);
872 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
873 struct btrfs_block_group_item, chunk_objectid, 64);
874 BTRFS_SETGET_FUNCS(disk_block_group_flags,
875 struct btrfs_block_group_item, flags, 64);
876 BTRFS_SETGET_STACK_FUNCS(block_group_flags,
877 struct btrfs_block_group_item, flags, 64);
879 /* struct btrfs_inode_ref */
880 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
881 BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
883 /* struct btrfs_inode_item */
884 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
885 BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
886 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
887 BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
888 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
889 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
890 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
891 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
892 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
893 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
894 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
895 BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
898 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
899 struct btrfs_inode_item, generation, 64);
900 BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
901 struct btrfs_inode_item, size, 64);
902 BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes,
903 struct btrfs_inode_item, nbytes, 64);
904 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
905 struct btrfs_inode_item, block_group, 64);
906 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
907 struct btrfs_inode_item, nlink, 32);
908 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
909 struct btrfs_inode_item, uid, 32);
910 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
911 struct btrfs_inode_item, gid, 32);
912 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
913 struct btrfs_inode_item, mode, 32);
914 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
915 struct btrfs_inode_item, rdev, 64);
916 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
917 struct btrfs_inode_item, flags, 16);
918 BTRFS_SETGET_STACK_FUNCS(stack_inode_compat_flags,
919 struct btrfs_inode_item, compat_flags, 16);
921 static inline struct btrfs_timespec *
922 btrfs_inode_atime(struct btrfs_inode_item *inode_item)
924 unsigned long ptr = (unsigned long)inode_item;
925 ptr += offsetof(struct btrfs_inode_item, atime);
926 return (struct btrfs_timespec *)ptr;
929 static inline struct btrfs_timespec *
930 btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
932 unsigned long ptr = (unsigned long)inode_item;
933 ptr += offsetof(struct btrfs_inode_item, mtime);
934 return (struct btrfs_timespec *)ptr;
937 static inline struct btrfs_timespec *
938 btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
940 unsigned long ptr = (unsigned long)inode_item;
941 ptr += offsetof(struct btrfs_inode_item, ctime);
942 return (struct btrfs_timespec *)ptr;
945 static inline struct btrfs_timespec *
946 btrfs_inode_otime(struct btrfs_inode_item *inode_item)
948 unsigned long ptr = (unsigned long)inode_item;
949 ptr += offsetof(struct btrfs_inode_item, otime);
950 return (struct btrfs_timespec *)ptr;
953 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
954 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
955 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
957 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
960 /* struct btrfs_dev_extent */
961 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
963 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
965 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
967 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
969 static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
971 unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
972 return (u8 *)((unsigned long)dev + ptr);
975 /* struct btrfs_extent_ref */
976 BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
977 BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
978 BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
979 BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32);
981 BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
982 BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
984 BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
986 BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref,
989 /* struct btrfs_extent_item */
990 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
991 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
994 /* struct btrfs_node */
995 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
996 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
998 static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
1001 ptr = offsetof(struct btrfs_node, ptrs) +
1002 sizeof(struct btrfs_key_ptr) * nr;
1003 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
1006 static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
1010 ptr = offsetof(struct btrfs_node, ptrs) +
1011 sizeof(struct btrfs_key_ptr) * nr;
1012 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
1015 static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
1018 ptr = offsetof(struct btrfs_node, ptrs) +
1019 sizeof(struct btrfs_key_ptr) * nr;
1020 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
1023 static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
1027 ptr = offsetof(struct btrfs_node, ptrs) +
1028 sizeof(struct btrfs_key_ptr) * nr;
1029 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
1032 static inline unsigned long btrfs_node_key_ptr_offset(int nr)
1034 return offsetof(struct btrfs_node, ptrs) +
1035 sizeof(struct btrfs_key_ptr) * nr;
1038 static inline void btrfs_node_key(struct extent_buffer *eb,
1039 struct btrfs_disk_key *disk_key, int nr)
1042 ptr = btrfs_node_key_ptr_offset(nr);
1043 read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1044 struct btrfs_key_ptr, key, disk_key);
1047 static inline void btrfs_set_node_key(struct extent_buffer *eb,
1048 struct btrfs_disk_key *disk_key, int nr)
1051 ptr = btrfs_node_key_ptr_offset(nr);
1052 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
1053 struct btrfs_key_ptr, key, disk_key);
1056 /* struct btrfs_item */
1057 BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
1058 BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
1060 static inline unsigned long btrfs_item_nr_offset(int nr)
1062 return offsetof(struct btrfs_leaf, items) +
1063 sizeof(struct btrfs_item) * nr;
1066 static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
1069 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
1072 static inline u32 btrfs_item_end(struct extent_buffer *eb,
1073 struct btrfs_item *item)
1075 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
1078 static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
1080 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
1083 static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
1085 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
1088 static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
1090 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
1093 static inline void btrfs_item_key(struct extent_buffer *eb,
1094 struct btrfs_disk_key *disk_key, int nr)
1096 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1097 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
1100 static inline void btrfs_set_item_key(struct extent_buffer *eb,
1101 struct btrfs_disk_key *disk_key, int nr)
1103 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1104 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
1107 /* struct btrfs_dir_item */
1108 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
1109 BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
1110 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1111 BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
1113 static inline void btrfs_dir_item_key(struct extent_buffer *eb,
1114 struct btrfs_dir_item *item,
1115 struct btrfs_disk_key *key)
1117 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
1120 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
1121 struct btrfs_dir_item *item,
1122 struct btrfs_disk_key *key)
1124 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
1127 /* struct btrfs_disk_key */
1128 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
1130 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
1131 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
1133 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
1134 struct btrfs_disk_key *disk)
1136 cpu->offset = le64_to_cpu(disk->offset);
1137 cpu->type = disk->type;
1138 cpu->objectid = le64_to_cpu(disk->objectid);
1141 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
1142 struct btrfs_key *cpu)
1144 disk->offset = cpu_to_le64(cpu->offset);
1145 disk->type = cpu->type;
1146 disk->objectid = cpu_to_le64(cpu->objectid);
1149 static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
1150 struct btrfs_key *key, int nr)
1152 struct btrfs_disk_key disk_key;
1153 btrfs_node_key(eb, &disk_key, nr);
1154 btrfs_disk_key_to_cpu(key, &disk_key);
1157 static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
1158 struct btrfs_key *key, int nr)
1160 struct btrfs_disk_key disk_key;
1161 btrfs_item_key(eb, &disk_key, nr);
1162 btrfs_disk_key_to_cpu(key, &disk_key);
1165 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
1166 struct btrfs_dir_item *item,
1167 struct btrfs_key *key)
1169 struct btrfs_disk_key disk_key;
1170 btrfs_dir_item_key(eb, item, &disk_key);
1171 btrfs_disk_key_to_cpu(key, &disk_key);
1175 static inline u8 btrfs_key_type(struct btrfs_key *key)
1180 static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
1185 /* struct btrfs_header */
1186 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
1187 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
1189 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
1190 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
1191 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
1192 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
1194 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
1196 return (btrfs_header_flags(eb) & flag) == flag;
1199 static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
1201 u64 flags = btrfs_header_flags(eb);
1202 btrfs_set_header_flags(eb, flags | flag);
1203 return (flags & flag) == flag;
1206 static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
1208 u64 flags = btrfs_header_flags(eb);
1209 btrfs_set_header_flags(eb, flags & ~flag);
1210 return (flags & flag) == flag;
1213 static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
1215 unsigned long ptr = offsetof(struct btrfs_header, fsid);
1219 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
1221 unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
1225 static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1227 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1231 static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
1233 unsigned long ptr = offsetof(struct btrfs_header, csum);
1237 static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
1242 static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
1247 static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
1252 static inline int btrfs_is_leaf(struct extent_buffer *eb)
1254 return (btrfs_header_level(eb) == 0);
1257 /* struct btrfs_root_item */
1258 BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
1260 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
1261 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
1262 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
1264 BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
1266 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
1267 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
1268 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
1269 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
1270 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
1271 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
1272 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
1273 BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
1277 /* struct btrfs_super_block */
1278 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
1279 BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
1280 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
1282 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
1283 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
1284 struct btrfs_super_block, sys_chunk_array_size, 32);
1285 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
1286 struct btrfs_super_block, chunk_root_generation, 64);
1287 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
1289 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
1291 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
1292 chunk_root_level, 8);
1293 BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
1295 BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
1297 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
1299 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
1301 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
1303 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
1305 BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
1307 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
1309 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
1310 root_dir_objectid, 64);
1311 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
1314 static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
1316 return offsetof(struct btrfs_leaf, items);
1319 /* struct btrfs_file_extent_item */
1320 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
1322 static inline unsigned long btrfs_file_extent_inline_start(struct
1323 btrfs_file_extent_item *e)
1325 unsigned long offset = (unsigned long)e;
1326 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
1330 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
1332 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
1335 static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
1336 struct btrfs_item *e)
1338 unsigned long offset;
1339 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
1340 return btrfs_item_size(eb, e) - offset;
1343 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
1345 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
1347 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
1348 disk_num_bytes, 64);
1349 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
1351 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
1353 BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
1355 BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
1357 BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
1359 BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
1360 other_encoding, 16);
1362 static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
1364 return root->leafsize;
1365 return root->nodesize;
1368 /* helper function to cast into the data area of the leaf. */
1369 #define btrfs_item_ptr(leaf, slot, type) \
1370 ((type *)(btrfs_leaf_data(leaf) + \
1371 btrfs_item_offset_nr(leaf, slot)))
1373 #define btrfs_item_ptr_offset(leaf, slot) \
1374 ((unsigned long)(btrfs_leaf_data(leaf) + \
1375 btrfs_item_offset_nr(leaf, slot)))
1378 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
1379 struct btrfs_root *root);
1380 int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
1381 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
1382 btrfs_fs_info *info,
1384 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1385 struct btrfs_block_group_cache
1386 *hint, u64 search_start,
1387 int data, int owner);
1388 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1389 struct btrfs_root *root,
1390 u32 blocksize, u64 parent,
1396 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1397 struct btrfs_root *root,
1398 u64 num_bytes, u64 parent,
1399 u64 root_objectid, u64 ref_generation,
1400 u64 owner, u64 empty_size, u64 hint_byte,
1401 u64 search_end, struct btrfs_key *ins, int data);
1402 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1403 struct extent_buffer *orig_buf, struct extent_buffer *buf,
1405 int btrfs_update_ref(struct btrfs_trans_handle *trans,
1406 struct btrfs_root *root, struct extent_buffer *orig_buf,
1407 struct extent_buffer *buf, int start_slot, int nr);
1408 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1409 *root, u64 bytenr, u64 num_bytes, u64 parent,
1410 u64 root_objectid, u64 ref_generation,
1411 u64 owner_objectid, int pin);
1412 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1413 struct btrfs_root *root,
1414 struct extent_io_tree *unpin);
1415 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1416 struct btrfs_root *root,
1417 u64 bytenr, u64 num_bytes, u64 parent,
1418 u64 root_objectid, u64 ref_generation,
1419 u64 owner_objectid);
1420 int btrfs_update_extent_ref(struct btrfs_trans_handle *trans,
1421 struct btrfs_root *root, u64 bytenr,
1422 u64 orig_parent, u64 parent,
1423 u64 root_objectid, u64 ref_generation,
1424 u64 owner_objectid);
1425 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1426 struct btrfs_root *root);
1427 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1428 int btrfs_read_block_groups(struct btrfs_root *root);
1429 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1430 struct btrfs_root *root, u64 bytes_used,
1431 u64 type, u64 chunk_objectid, u64 chunk_offset,
1433 int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
1434 struct btrfs_root *root);
1435 int btrfs_update_block_group(struct btrfs_trans_handle *trans,
1436 struct btrfs_root *root, u64 bytenr, u64 num,
1437 int alloc, int mark_free);
1439 int btrfs_previous_item(struct btrfs_root *root,
1440 struct btrfs_path *path, u64 min_objectid,
1442 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1443 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1444 struct btrfs_root *root, struct extent_buffer *buf,
1445 struct extent_buffer *parent, int parent_slot,
1446 struct extent_buffer **cow_ret);
1447 int __btrfs_cow_block(struct btrfs_trans_handle *trans,
1448 struct btrfs_root *root,
1449 struct extent_buffer *buf,
1450 struct extent_buffer *parent, int parent_slot,
1451 struct extent_buffer **cow_ret,
1452 u64 search_start, u64 empty_size);
1453 int btrfs_copy_root(struct btrfs_trans_handle *trans,
1454 struct btrfs_root *root,
1455 struct extent_buffer *buf,
1456 struct extent_buffer **cow_ret, u64 new_root_objectid);
1457 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1458 *root, struct btrfs_path *path, u32 data_size);
1459 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1460 struct btrfs_root *root,
1461 struct btrfs_path *path,
1462 u32 new_size, int from_end);
1463 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1464 *root, struct btrfs_key *key, struct btrfs_path *p, int
1466 int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1467 struct btrfs_root *root, struct extent_buffer *parent,
1468 int start_slot, int cache_only, u64 *last_ret,
1469 struct btrfs_key *progress);
1470 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1471 struct btrfs_path *btrfs_alloc_path(void);
1472 void btrfs_free_path(struct btrfs_path *p);
1473 void btrfs_init_path(struct btrfs_path *p);
1474 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1475 struct btrfs_path *path, int slot, int nr);
1477 static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
1478 struct btrfs_root *root,
1479 struct btrfs_path *path)
1481 return btrfs_del_items(trans, root, path, path->slots[0], 1);
1484 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1485 *root, struct btrfs_key *key, void *data, u32 data_size);
1486 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
1487 struct btrfs_root *root,
1488 struct btrfs_path *path,
1489 struct btrfs_key *cpu_key, u32 *data_size, int nr);
1491 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
1492 struct btrfs_root *root,
1493 struct btrfs_path *path,
1494 struct btrfs_key *key,
1497 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
1500 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1501 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
1502 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
1503 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1505 int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
1506 struct btrfs_root *root, struct btrfs_path *path,
1507 struct btrfs_key *new_key);
1510 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1511 struct btrfs_key *key);
1512 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1513 *root, struct btrfs_key *key, struct btrfs_root_item
1515 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1516 *root, struct btrfs_key *key, struct btrfs_root_item
1518 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1519 btrfs_root_item *item, struct btrfs_key *key);
1520 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1521 struct btrfs_root *latest_root);
1523 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1524 *root, const char *name, int name_len, u64 dir,
1525 struct btrfs_key *location, u8 type);
1526 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1527 struct btrfs_root *root,
1528 struct btrfs_path *path, u64 dir,
1529 const char *name, int name_len,
1531 struct btrfs_dir_item *
1532 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1533 struct btrfs_root *root,
1534 struct btrfs_path *path, u64 dir,
1535 u64 objectid, const char *name, int name_len,
1537 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1538 struct btrfs_path *path,
1539 const char *name, int name_len);
1540 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1541 struct btrfs_root *root,
1542 struct btrfs_path *path,
1543 struct btrfs_dir_item *di);
1544 int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
1545 struct btrfs_root *root, const char *name,
1546 u16 name_len, const void *data, u16 data_len,
1548 struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
1549 struct btrfs_root *root,
1550 struct btrfs_path *path, u64 dir,
1551 const char *name, u16 name_len,
1554 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1555 struct btrfs_root *fs_root,
1556 u64 dirid, u64 *objectid);
1557 int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1560 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
1561 struct btrfs_root *root,
1562 const char *name, int name_len,
1563 u64 inode_objectid, u64 ref_objectid, u64 index);
1564 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
1565 struct btrfs_root *root,
1566 const char *name, int name_len,
1567 u64 inode_objectid, u64 ref_objectid);
1568 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1569 struct btrfs_root *root,
1570 struct btrfs_path *path, u64 objectid);
1571 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1572 *root, u64 objectid, struct btrfs_inode_item
1574 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1575 *root, struct btrfs_path *path,
1576 struct btrfs_key *location, int mod);
1579 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1580 struct btrfs_root *root,
1581 u64 objectid, u64 pos, u64 offset,
1584 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
1585 struct btrfs_root *root, u64 objectid,
1586 u64 offset, char *buffer, size_t size);
1587 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1588 struct btrfs_root *root,
1589 struct btrfs_path *path, u64 objectid,
1590 u64 bytenr, int mod);
1591 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1592 struct btrfs_root *root,
1593 struct btrfs_inode_item *inode,
1594 u64 objectid, u64 offset,
1595 char *data, size_t len);
1596 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1597 struct btrfs_root *root,
1598 struct btrfs_path *path,
1599 u64 objectid, u64 offset,
1601 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1602 struct btrfs_root *root, struct btrfs_path *path,