Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 2 | /* |
| 3 | * From linux/fs/btrfs/ctree.h |
| 4 | * Copyright (C) 2007,2008 Oracle. All rights reserved. |
| 5 | * |
Marek Behún | 61143f7 | 2022-06-01 17:17:06 +0200 | [diff] [blame] | 6 | * Modified in 2017 by Marek Behún, CZ.NIC, kabel@kernel.org |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef __BTRFS_CTREE_H__ |
| 10 | #define __BTRFS_CTREE_H__ |
| 11 | |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 12 | #include <compiler.h> |
Qu Wenruo | 9a9be5e | 2020-06-24 18:02:52 +0200 | [diff] [blame] | 13 | #include <linux/rbtree.h> |
Qu Wenruo | b1f0067 | 2020-06-24 18:02:54 +0200 | [diff] [blame] | 14 | #include <linux/bug.h> |
Pali Rohár | c4bbbed | 2022-04-07 14:51:03 +0200 | [diff] [blame] | 15 | #include <asm/unaligned.h> |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 16 | #include <u-boot/crc.h> |
Qu Wenruo | 3b4b40c | 2020-06-24 18:02:47 +0200 | [diff] [blame] | 17 | #include "kernel-shared/btrfs_tree.h" |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 18 | #include "crypto/hash.h" |
Qu Wenruo | 4aebb99 | 2020-06-24 18:02:49 +0200 | [diff] [blame] | 19 | #include "compat.h" |
Qu Wenruo | 9a9be5e | 2020-06-24 18:02:52 +0200 | [diff] [blame] | 20 | #include "extent-io.h" |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 21 | |
| 22 | #define BTRFS_MAX_MIRRORS 3 |
| 23 | |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 24 | /* |
| 25 | * the max metadata block size. This limit is somewhat artificial, |
| 26 | * but the memmove costs go through the roof for larger blocks. |
| 27 | */ |
| 28 | #define BTRFS_MAX_METADATA_BLOCKSIZE 65536 |
| 29 | |
| 30 | /* |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 31 | * Theoretical limit is larger, but we keep this down to a sane |
| 32 | * value. That should limit greatly the possibility of collisions on |
| 33 | * inode ref items. |
| 34 | */ |
| 35 | #define BTRFS_LINK_MAX 65535U |
| 36 | |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 37 | /* four bytes for CRC32 */ |
| 38 | #define BTRFS_EMPTY_DIR_SIZE 0 |
| 39 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 40 | struct btrfs_mapping_tree { |
| 41 | struct cache_tree cache_tree; |
| 42 | }; |
| 43 | |
| 44 | static inline unsigned long btrfs_chunk_item_size(int num_stripes) |
| 45 | { |
| 46 | BUG_ON(num_stripes == 0); |
| 47 | return sizeof(struct btrfs_chunk) + |
| 48 | sizeof(struct btrfs_stripe) * (num_stripes - 1); |
| 49 | } |
| 50 | |
| 51 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) |
| 52 | #define BTRFS_LEAF_DATA_SIZE(fs_info) \ |
| 53 | (__BTRFS_LEAF_DATA_SIZE(fs_info->nodesize)) |
Qu Wenruo | 29c26ae | 2020-06-24 18:02:59 +0200 | [diff] [blame] | 54 | |
| 55 | struct btrfs_path { |
| 56 | struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; |
| 57 | int slots[BTRFS_MAX_LEVEL]; |
| 58 | |
| 59 | /* keep some upper locks as we walk down */ |
| 60 | u8 lowest_level; |
| 61 | }; |
| 62 | |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 63 | /* ioprio of readahead is set to idle */ |
| 64 | #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) |
| 65 | |
| 66 | #define BTRFS_DIRTY_METADATA_THRESH SZ_32M |
| 67 | |
| 68 | #define BTRFS_MAX_EXTENT_SIZE SZ_128M |
| 69 | |
Qu Wenruo | 75b0817 | 2020-06-24 18:02:55 +0200 | [diff] [blame] | 70 | enum btrfs_tree_block_status { |
| 71 | BTRFS_TREE_BLOCK_CLEAN, |
| 72 | BTRFS_TREE_BLOCK_INVALID_NRITEMS, |
| 73 | BTRFS_TREE_BLOCK_INVALID_PARENT_KEY, |
| 74 | BTRFS_TREE_BLOCK_BAD_KEY_ORDER, |
| 75 | BTRFS_TREE_BLOCK_INVALID_LEVEL, |
| 76 | BTRFS_TREE_BLOCK_INVALID_FREE_SPACE, |
| 77 | BTRFS_TREE_BLOCK_INVALID_OFFSETS, |
| 78 | }; |
| 79 | |
Qu Wenruo | bccee8b | 2020-06-24 18:02:58 +0200 | [diff] [blame] | 80 | struct btrfs_root { |
| 81 | struct extent_buffer *node; |
| 82 | struct btrfs_root_item root_item; |
| 83 | struct btrfs_key root_key; |
| 84 | struct btrfs_fs_info *fs_info; |
| 85 | u64 objectid; |
| 86 | u64 last_trans; |
| 87 | |
| 88 | int ref_cows; |
| 89 | int track_dirty; |
| 90 | |
| 91 | u32 type; |
| 92 | u64 last_inode_alloc; |
| 93 | |
| 94 | struct rb_node rb_node; |
| 95 | }; |
| 96 | |
Qu Wenruo | 29c26ae | 2020-06-24 18:02:59 +0200 | [diff] [blame] | 97 | struct btrfs_trans_handle; |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 98 | struct btrfs_device; |
| 99 | struct btrfs_fs_devices; |
| 100 | struct btrfs_fs_info { |
| 101 | u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; |
| 102 | u8 *new_chunk_tree_uuid; |
| 103 | struct btrfs_root *fs_root; |
| 104 | struct btrfs_root *tree_root; |
| 105 | struct btrfs_root *chunk_root; |
| 106 | struct btrfs_root *csum_root; |
| 107 | |
| 108 | struct rb_root fs_root_tree; |
| 109 | |
| 110 | struct extent_io_tree extent_cache; |
| 111 | |
| 112 | /* logical->physical extent mapping */ |
| 113 | struct btrfs_mapping_tree mapping_tree; |
| 114 | |
| 115 | u64 last_trans_committed; |
| 116 | |
| 117 | struct btrfs_super_block *super_copy; |
| 118 | |
| 119 | struct btrfs_fs_devices *fs_devices; |
| 120 | |
| 121 | /* Cached block sizes */ |
| 122 | u32 nodesize; |
| 123 | u32 sectorsize; |
| 124 | u32 stripesize; |
| 125 | }; |
| 126 | |
Qu Wenruo | 75b0817 | 2020-06-24 18:02:55 +0200 | [diff] [blame] | 127 | static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info) |
| 128 | { |
| 129 | return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item); |
| 130 | } |
| 131 | |
| 132 | static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info) |
| 133 | { |
| 134 | return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr); |
| 135 | } |
| 136 | |
| 137 | static inline u32 BTRFS_NODEPTRS_PER_EXTENT_BUFFER(const struct extent_buffer *eb) |
| 138 | { |
| 139 | BUG_ON(eb->fs_info && eb->fs_info->nodesize != eb->len); |
| 140 | return __BTRFS_LEAF_DATA_SIZE(eb->len) / sizeof(struct btrfs_key_ptr); |
| 141 | } |
| 142 | |
| 143 | #define BTRFS_FILE_EXTENT_INLINE_DATA_START \ |
| 144 | (offsetof(struct btrfs_file_extent_item, disk_bytenr)) |
| 145 | static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info) |
| 146 | { |
| 147 | return BTRFS_MAX_ITEM_SIZE(info) - |
| 148 | BTRFS_FILE_EXTENT_INLINE_DATA_START; |
| 149 | } |
| 150 | |
| 151 | static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) |
| 152 | { |
| 153 | return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item); |
| 154 | } |
| 155 | |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 156 | /* |
| 157 | * File system states |
| 158 | */ |
| 159 | #define BTRFS_FS_STATE_ERROR 0 |
| 160 | #define BTRFS_FS_STATE_REMOUNTING 1 |
| 161 | #define BTRFS_FS_STATE_TRANS_ABORTED 2 |
| 162 | #define BTRFS_FS_STATE_DEV_REPLACING 3 |
| 163 | #define BTRFS_FS_STATE_DUMMY_FS_INFO 4 |
| 164 | |
Qu Wenruo | 9a9be5e | 2020-06-24 18:02:52 +0200 | [diff] [blame] | 165 | #define read_eb_member(eb, ptr, type, member, result) ( \ |
| 166 | read_extent_buffer(eb, (char *)(result), \ |
| 167 | ((unsigned long)(ptr)) + \ |
| 168 | offsetof(type, member), \ |
| 169 | sizeof(((type *)0)->member))) |
| 170 | |
| 171 | #define write_eb_member(eb, ptr, type, member, result) ( \ |
| 172 | write_extent_buffer(eb, (char *)(result), \ |
| 173 | ((unsigned long)(ptr)) + \ |
| 174 | offsetof(type, member), \ |
| 175 | sizeof(((type *)0)->member))) |
| 176 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 177 | #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ |
| 178 | static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ |
| 179 | { \ |
| 180 | const struct btrfs_header *h = (struct btrfs_header *)eb->data; \ |
| 181 | return le##bits##_to_cpu(h->member); \ |
| 182 | } \ |
| 183 | static inline void btrfs_set_##name(struct extent_buffer *eb, \ |
| 184 | u##bits val) \ |
| 185 | { \ |
| 186 | struct btrfs_header *h = (struct btrfs_header *)eb->data; \ |
| 187 | h->member = cpu_to_le##bits(val); \ |
| 188 | } |
| 189 | |
| 190 | #define BTRFS_SETGET_FUNCS(name, type, member, bits) \ |
| 191 | static inline u##bits btrfs_##name(const struct extent_buffer *eb, \ |
| 192 | const type *s) \ |
| 193 | { \ |
| 194 | unsigned long offset = (unsigned long)s; \ |
| 195 | const type *p = (type *) (eb->data + offset); \ |
| 196 | return get_unaligned_le##bits(&p->member); \ |
| 197 | } \ |
| 198 | static inline void btrfs_set_##name(struct extent_buffer *eb, \ |
| 199 | type *s, u##bits val) \ |
| 200 | { \ |
| 201 | unsigned long offset = (unsigned long)s; \ |
| 202 | type *p = (type *) (eb->data + offset); \ |
| 203 | put_unaligned_le##bits(val, &p->member); \ |
| 204 | } |
| 205 | |
Qu Wenruo | 4aebb99 | 2020-06-24 18:02:49 +0200 | [diff] [blame] | 206 | #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ |
| 207 | static inline u##bits btrfs_##name(const type *s) \ |
| 208 | { \ |
| 209 | return le##bits##_to_cpu(s->member); \ |
| 210 | } \ |
| 211 | static inline void btrfs_set_##name(type *s, u##bits val) \ |
| 212 | { \ |
| 213 | s->member = cpu_to_le##bits(val); \ |
| 214 | } |
| 215 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 216 | BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64); |
| 217 | BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64); |
| 218 | BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64); |
| 219 | BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32); |
| 220 | BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32); |
| 221 | BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item, |
| 222 | start_offset, 64); |
| 223 | BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32); |
| 224 | BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64); |
| 225 | BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32); |
| 226 | BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8); |
| 227 | BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8); |
| 228 | BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64); |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 229 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 230 | BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64); |
| 231 | BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item, |
| 232 | total_bytes, 64); |
| 233 | BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item, |
| 234 | bytes_used, 64); |
| 235 | BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item, |
| 236 | io_align, 32); |
| 237 | BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item, |
| 238 | io_width, 32); |
| 239 | BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item, |
| 240 | sector_size, 32); |
| 241 | BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64); |
| 242 | BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item, |
| 243 | dev_group, 32); |
| 244 | BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item, |
| 245 | seek_speed, 8); |
| 246 | BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item, |
| 247 | bandwidth, 8); |
| 248 | BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item, |
| 249 | generation, 64); |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 250 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 251 | static inline char *btrfs_device_uuid(struct btrfs_dev_item *d) |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 252 | { |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 253 | return (char *)d + offsetof(struct btrfs_dev_item, uuid); |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 256 | static inline char *btrfs_device_fsid(struct btrfs_dev_item *d) |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 257 | { |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 258 | return (char *)d + offsetof(struct btrfs_dev_item, fsid); |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 261 | BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64); |
| 262 | BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64); |
| 263 | BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64); |
| 264 | BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32); |
| 265 | BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32); |
| 266 | BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32); |
| 267 | BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64); |
| 268 | BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16); |
| 269 | BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16); |
| 270 | BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64); |
| 271 | BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64); |
| 272 | |
| 273 | static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s) |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 274 | { |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 275 | return (char *)s + offsetof(struct btrfs_stripe, dev_uuid); |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 276 | } |
| 277 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 278 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64); |
| 279 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64); |
| 280 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk, |
| 281 | stripe_len, 64); |
| 282 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk, |
| 283 | io_align, 32); |
| 284 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk, |
| 285 | io_width, 32); |
| 286 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk, |
| 287 | sector_size, 32); |
| 288 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64); |
| 289 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk, |
| 290 | num_stripes, 16); |
| 291 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk, |
| 292 | sub_stripes, 16); |
| 293 | BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64); |
| 294 | BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64); |
| 295 | |
| 296 | static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c, |
| 297 | int nr) |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 298 | { |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 299 | unsigned long offset = (unsigned long)c; |
| 300 | offset += offsetof(struct btrfs_chunk, stripe); |
| 301 | offset += nr * sizeof(struct btrfs_stripe); |
| 302 | return (struct btrfs_stripe *)offset; |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 303 | } |
| 304 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 305 | static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr) |
| 306 | { |
| 307 | return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr)); |
| 308 | } |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 309 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 310 | static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb, |
| 311 | struct btrfs_chunk *c, int nr) |
| 312 | { |
| 313 | return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr)); |
| 314 | } |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 315 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 316 | static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb, |
| 317 | struct btrfs_chunk *c, int nr, |
| 318 | u64 val) |
| 319 | { |
| 320 | btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val); |
| 321 | } |
| 322 | |
| 323 | static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb, |
| 324 | struct btrfs_chunk *c, int nr) |
| 325 | { |
| 326 | return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr)); |
| 327 | } |
| 328 | |
| 329 | static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb, |
| 330 | struct btrfs_chunk *c, int nr, |
| 331 | u64 val) |
| 332 | { |
| 333 | btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val); |
| 334 | } |
| 335 | |
| 336 | /* struct btrfs_block_group_item */ |
| 337 | BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, |
| 338 | used, 64); |
| 339 | BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item, |
| 340 | used, 64); |
| 341 | BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid, |
| 342 | struct btrfs_block_group_item, chunk_objectid, 64); |
| 343 | |
| 344 | BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid, |
| 345 | struct btrfs_block_group_item, chunk_objectid, 64); |
| 346 | BTRFS_SETGET_FUNCS(disk_block_group_flags, |
| 347 | struct btrfs_block_group_item, flags, 64); |
| 348 | BTRFS_SETGET_STACK_FUNCS(block_group_flags, |
| 349 | struct btrfs_block_group_item, flags, 64); |
| 350 | |
| 351 | /* struct btrfs_free_space_info */ |
| 352 | BTRFS_SETGET_FUNCS(free_space_extent_count, struct btrfs_free_space_info, |
| 353 | extent_count, 32); |
| 354 | BTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32); |
| 355 | |
| 356 | /* struct btrfs_inode_ref */ |
| 357 | BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); |
| 358 | BTRFS_SETGET_STACK_FUNCS(stack_inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); |
| 359 | BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64); |
| 360 | |
| 361 | /* struct btrfs_inode_extref */ |
| 362 | BTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref, |
| 363 | parent_objectid, 64); |
| 364 | BTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref, |
| 365 | name_len, 16); |
| 366 | BTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64); |
| 367 | |
| 368 | /* struct btrfs_inode_item */ |
| 369 | BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); |
| 370 | BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64); |
| 371 | BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64); |
| 372 | BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); |
| 373 | BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64); |
| 374 | BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); |
| 375 | BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); |
| 376 | BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); |
| 377 | BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32); |
| 378 | BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32); |
| 379 | BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64); |
| 380 | BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64); |
| 381 | |
| 382 | BTRFS_SETGET_STACK_FUNCS(stack_inode_generation, |
| 383 | struct btrfs_inode_item, generation, 64); |
| 384 | BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, |
| 385 | struct btrfs_inode_item, sequence, 64); |
| 386 | BTRFS_SETGET_STACK_FUNCS(stack_inode_transid, |
| 387 | struct btrfs_inode_item, transid, 64); |
| 388 | BTRFS_SETGET_STACK_FUNCS(stack_inode_size, |
| 389 | struct btrfs_inode_item, size, 64); |
| 390 | BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, |
| 391 | struct btrfs_inode_item, nbytes, 64); |
| 392 | BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, |
| 393 | struct btrfs_inode_item, block_group, 64); |
| 394 | BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, |
| 395 | struct btrfs_inode_item, nlink, 32); |
| 396 | BTRFS_SETGET_STACK_FUNCS(stack_inode_uid, |
| 397 | struct btrfs_inode_item, uid, 32); |
| 398 | BTRFS_SETGET_STACK_FUNCS(stack_inode_gid, |
| 399 | struct btrfs_inode_item, gid, 32); |
| 400 | BTRFS_SETGET_STACK_FUNCS(stack_inode_mode, |
| 401 | struct btrfs_inode_item, mode, 32); |
| 402 | BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, |
| 403 | struct btrfs_inode_item, rdev, 64); |
| 404 | BTRFS_SETGET_STACK_FUNCS(stack_inode_flags, |
| 405 | struct btrfs_inode_item, flags, 64); |
| 406 | |
| 407 | static inline struct btrfs_timespec * |
| 408 | btrfs_inode_atime(struct btrfs_inode_item *inode_item) |
| 409 | { |
| 410 | unsigned long ptr = (unsigned long)inode_item; |
| 411 | ptr += offsetof(struct btrfs_inode_item, atime); |
| 412 | return (struct btrfs_timespec *)ptr; |
| 413 | } |
| 414 | |
| 415 | static inline struct btrfs_timespec * |
| 416 | btrfs_inode_mtime(struct btrfs_inode_item *inode_item) |
| 417 | { |
| 418 | unsigned long ptr = (unsigned long)inode_item; |
| 419 | ptr += offsetof(struct btrfs_inode_item, mtime); |
| 420 | return (struct btrfs_timespec *)ptr; |
| 421 | } |
| 422 | |
| 423 | static inline struct btrfs_timespec * |
| 424 | btrfs_inode_ctime(struct btrfs_inode_item *inode_item) |
| 425 | { |
| 426 | unsigned long ptr = (unsigned long)inode_item; |
| 427 | ptr += offsetof(struct btrfs_inode_item, ctime); |
| 428 | return (struct btrfs_timespec *)ptr; |
| 429 | } |
| 430 | |
| 431 | static inline struct btrfs_timespec * |
| 432 | btrfs_inode_otime(struct btrfs_inode_item *inode_item) |
| 433 | { |
| 434 | unsigned long ptr = (unsigned long)inode_item; |
| 435 | ptr += offsetof(struct btrfs_inode_item, otime); |
| 436 | return (struct btrfs_timespec *)ptr; |
| 437 | } |
| 438 | |
| 439 | BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); |
| 440 | BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); |
| 441 | BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, |
| 442 | sec, 64); |
| 443 | BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, |
| 444 | nsec, 32); |
| 445 | |
| 446 | /* struct btrfs_dev_extent */ |
| 447 | BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, |
| 448 | chunk_tree, 64); |
| 449 | BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent, |
| 450 | chunk_objectid, 64); |
| 451 | BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent, |
| 452 | chunk_offset, 64); |
| 453 | BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); |
| 454 | |
| 455 | BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_length, struct btrfs_dev_extent, |
| 456 | length, 64); |
| 457 | |
| 458 | static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev) |
| 459 | { |
| 460 | unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid); |
| 461 | return (u8 *)((unsigned long)dev + ptr); |
| 462 | } |
| 463 | |
| 464 | |
| 465 | /* struct btrfs_extent_item */ |
| 466 | BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); |
| 467 | BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item, refs, 64); |
| 468 | BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, |
| 469 | generation, 64); |
| 470 | BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64); |
| 471 | BTRFS_SETGET_STACK_FUNCS(stack_extent_flags, struct btrfs_extent_item, flags, 64); |
| 472 | |
| 473 | BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32); |
| 474 | |
| 475 | BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8); |
| 476 | |
| 477 | static inline void btrfs_tree_block_key(struct extent_buffer *eb, |
| 478 | struct btrfs_tree_block_info *item, |
| 479 | struct btrfs_disk_key *key) |
| 480 | { |
| 481 | read_eb_member(eb, item, struct btrfs_tree_block_info, key, key); |
| 482 | } |
| 483 | |
| 484 | static inline void btrfs_set_tree_block_key(struct extent_buffer *eb, |
| 485 | struct btrfs_tree_block_info *item, |
| 486 | struct btrfs_disk_key *key) |
| 487 | { |
| 488 | write_eb_member(eb, item, struct btrfs_tree_block_info, key, key); |
| 489 | } |
| 490 | |
| 491 | BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref, |
| 492 | root, 64); |
| 493 | BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref, |
| 494 | objectid, 64); |
| 495 | BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref, |
| 496 | offset, 64); |
| 497 | BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref, |
| 498 | count, 32); |
| 499 | |
| 500 | BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref, |
| 501 | count, 32); |
| 502 | |
| 503 | BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref, |
| 504 | type, 8); |
| 505 | BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref, |
| 506 | offset, 64); |
| 507 | BTRFS_SETGET_STACK_FUNCS(stack_extent_inline_ref_type, |
| 508 | struct btrfs_extent_inline_ref, type, 8); |
| 509 | BTRFS_SETGET_STACK_FUNCS(stack_extent_inline_ref_offset, |
| 510 | struct btrfs_extent_inline_ref, offset, 64); |
| 511 | |
| 512 | static inline u32 btrfs_extent_inline_ref_size(int type) |
| 513 | { |
| 514 | if (type == BTRFS_TREE_BLOCK_REF_KEY || |
| 515 | type == BTRFS_SHARED_BLOCK_REF_KEY) |
| 516 | return sizeof(struct btrfs_extent_inline_ref); |
| 517 | if (type == BTRFS_SHARED_DATA_REF_KEY) |
| 518 | return sizeof(struct btrfs_shared_data_ref) + |
| 519 | sizeof(struct btrfs_extent_inline_ref); |
| 520 | if (type == BTRFS_EXTENT_DATA_REF_KEY) |
| 521 | return sizeof(struct btrfs_extent_data_ref) + |
| 522 | offsetof(struct btrfs_extent_inline_ref, offset); |
| 523 | BUG(); |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | BTRFS_SETGET_FUNCS(ref_root_v0, struct btrfs_extent_ref_v0, root, 64); |
| 528 | BTRFS_SETGET_FUNCS(ref_generation_v0, struct btrfs_extent_ref_v0, |
| 529 | generation, 64); |
| 530 | BTRFS_SETGET_FUNCS(ref_objectid_v0, struct btrfs_extent_ref_v0, objectid, 64); |
| 531 | BTRFS_SETGET_FUNCS(ref_count_v0, struct btrfs_extent_ref_v0, count, 32); |
| 532 | |
| 533 | /* struct btrfs_node */ |
| 534 | BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); |
| 535 | BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); |
| 536 | |
| 537 | static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr) |
| 538 | { |
| 539 | unsigned long ptr; |
| 540 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 541 | sizeof(struct btrfs_key_ptr) * nr; |
| 542 | return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); |
| 543 | } |
| 544 | |
| 545 | static inline void btrfs_set_node_blockptr(struct extent_buffer *eb, |
| 546 | int nr, u64 val) |
| 547 | { |
| 548 | unsigned long ptr; |
| 549 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 550 | sizeof(struct btrfs_key_ptr) * nr; |
| 551 | btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); |
| 552 | } |
| 553 | |
| 554 | static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr) |
| 555 | { |
| 556 | unsigned long ptr; |
| 557 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 558 | sizeof(struct btrfs_key_ptr) * nr; |
| 559 | return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); |
| 560 | } |
| 561 | |
| 562 | static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb, |
| 563 | int nr, u64 val) |
| 564 | { |
| 565 | unsigned long ptr; |
| 566 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 567 | sizeof(struct btrfs_key_ptr) * nr; |
| 568 | btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val); |
| 569 | } |
| 570 | |
| 571 | static inline unsigned long btrfs_node_key_ptr_offset(int nr) |
| 572 | { |
| 573 | return offsetof(struct btrfs_node, ptrs) + |
| 574 | sizeof(struct btrfs_key_ptr) * nr; |
| 575 | } |
| 576 | |
| 577 | static inline void btrfs_node_key(struct extent_buffer *eb, |
| 578 | struct btrfs_disk_key *disk_key, int nr) |
| 579 | { |
| 580 | unsigned long ptr; |
| 581 | ptr = btrfs_node_key_ptr_offset(nr); |
| 582 | read_eb_member(eb, (struct btrfs_key_ptr *)ptr, |
| 583 | struct btrfs_key_ptr, key, disk_key); |
| 584 | } |
| 585 | |
| 586 | static inline void btrfs_set_node_key(struct extent_buffer *eb, |
| 587 | struct btrfs_disk_key *disk_key, int nr) |
| 588 | { |
| 589 | unsigned long ptr; |
| 590 | ptr = btrfs_node_key_ptr_offset(nr); |
| 591 | write_eb_member(eb, (struct btrfs_key_ptr *)ptr, |
| 592 | struct btrfs_key_ptr, key, disk_key); |
| 593 | } |
| 594 | |
| 595 | /* struct btrfs_item */ |
| 596 | BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32); |
| 597 | BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32); |
| 598 | |
| 599 | static inline unsigned long btrfs_item_nr_offset(int nr) |
| 600 | { |
| 601 | return offsetof(struct btrfs_leaf, items) + |
| 602 | sizeof(struct btrfs_item) * nr; |
| 603 | } |
| 604 | |
| 605 | static inline struct btrfs_item *btrfs_item_nr(int nr) |
| 606 | { |
| 607 | return (struct btrfs_item *)btrfs_item_nr_offset(nr); |
| 608 | } |
| 609 | |
| 610 | static inline u32 btrfs_item_end(struct extent_buffer *eb, |
| 611 | struct btrfs_item *item) |
| 612 | { |
| 613 | return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item); |
| 614 | } |
| 615 | |
| 616 | static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr) |
| 617 | { |
| 618 | return btrfs_item_end(eb, btrfs_item_nr(nr)); |
| 619 | } |
| 620 | |
| 621 | static inline u32 btrfs_item_offset_nr(const struct extent_buffer *eb, int nr) |
| 622 | { |
| 623 | return btrfs_item_offset(eb, btrfs_item_nr(nr)); |
| 624 | } |
| 625 | |
| 626 | static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr) |
| 627 | { |
| 628 | return btrfs_item_size(eb, btrfs_item_nr(nr)); |
| 629 | } |
| 630 | |
| 631 | static inline void btrfs_item_key(struct extent_buffer *eb, |
| 632 | struct btrfs_disk_key *disk_key, int nr) |
| 633 | { |
| 634 | struct btrfs_item *item = btrfs_item_nr(nr); |
| 635 | read_eb_member(eb, item, struct btrfs_item, key, disk_key); |
| 636 | } |
| 637 | |
| 638 | static inline void btrfs_set_item_key(struct extent_buffer *eb, |
| 639 | struct btrfs_disk_key *disk_key, int nr) |
| 640 | { |
| 641 | struct btrfs_item *item = btrfs_item_nr(nr); |
| 642 | write_eb_member(eb, item, struct btrfs_item, key, disk_key); |
| 643 | } |
| 644 | |
| 645 | BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64); |
| 646 | |
| 647 | /* |
| 648 | * struct btrfs_root_ref |
| 649 | */ |
| 650 | BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64); |
| 651 | BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64); |
| 652 | BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16); |
| 653 | |
| 654 | BTRFS_SETGET_STACK_FUNCS(stack_root_ref_dirid, struct btrfs_root_ref, dirid, 64); |
| 655 | BTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence, struct btrfs_root_ref, sequence, 64); |
| 656 | BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_len, 16); |
| 657 | |
| 658 | /* struct btrfs_dir_item */ |
| 659 | BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); |
| 660 | BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8); |
| 661 | BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); |
| 662 | BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64); |
| 663 | |
| 664 | BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, data_len, 16); |
| 665 | BTRFS_SETGET_STACK_FUNCS(stack_dir_type, struct btrfs_dir_item, type, 8); |
| 666 | BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16); |
| 667 | BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, transid, 64); |
| 668 | |
| 669 | static inline void btrfs_dir_item_key(struct extent_buffer *eb, |
| 670 | struct btrfs_dir_item *item, |
| 671 | struct btrfs_disk_key *key) |
| 672 | { |
| 673 | read_eb_member(eb, item, struct btrfs_dir_item, location, key); |
| 674 | } |
| 675 | |
| 676 | static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, |
| 677 | struct btrfs_dir_item *item, |
| 678 | struct btrfs_disk_key *key) |
| 679 | { |
| 680 | write_eb_member(eb, item, struct btrfs_dir_item, location, key); |
| 681 | } |
| 682 | |
| 683 | /* struct btrfs_free_space_header */ |
| 684 | BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header, |
| 685 | num_entries, 64); |
| 686 | BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header, |
| 687 | num_bitmaps, 64); |
| 688 | BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, |
| 689 | generation, 64); |
| 690 | |
| 691 | static inline void btrfs_free_space_key(struct extent_buffer *eb, |
| 692 | struct btrfs_free_space_header *h, |
| 693 | struct btrfs_disk_key *key) |
| 694 | { |
| 695 | read_eb_member(eb, h, struct btrfs_free_space_header, location, key); |
| 696 | } |
| 697 | |
| 698 | static inline void btrfs_set_free_space_key(struct extent_buffer *eb, |
| 699 | struct btrfs_free_space_header *h, |
| 700 | struct btrfs_disk_key *key) |
| 701 | { |
| 702 | write_eb_member(eb, h, struct btrfs_free_space_header, location, key); |
| 703 | } |
| 704 | |
| 705 | /* struct btrfs_disk_key */ |
| 706 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, |
| 707 | objectid, 64); |
| 708 | BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); |
| 709 | BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); |
| 710 | |
| 711 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
| 712 | struct btrfs_disk_key *disk) |
| 713 | { |
| 714 | cpu->offset = le64_to_cpu(disk->offset); |
| 715 | cpu->type = disk->type; |
| 716 | cpu->objectid = le64_to_cpu(disk->objectid); |
| 717 | } |
| 718 | |
| 719 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, |
| 720 | const struct btrfs_key *cpu) |
| 721 | { |
| 722 | disk->offset = cpu_to_le64(cpu->offset); |
| 723 | disk->type = cpu->type; |
| 724 | disk->objectid = cpu_to_le64(cpu->objectid); |
| 725 | } |
| 726 | |
| 727 | static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb, |
| 728 | struct btrfs_key *key, int nr) |
| 729 | { |
| 730 | struct btrfs_disk_key disk_key; |
| 731 | btrfs_node_key(eb, &disk_key, nr); |
| 732 | btrfs_disk_key_to_cpu(key, &disk_key); |
| 733 | } |
| 734 | |
| 735 | static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb, |
| 736 | struct btrfs_key *key, int nr) |
| 737 | { |
| 738 | struct btrfs_disk_key disk_key; |
| 739 | btrfs_item_key(eb, &disk_key, nr); |
| 740 | btrfs_disk_key_to_cpu(key, &disk_key); |
| 741 | } |
| 742 | |
| 743 | static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb, |
| 744 | struct btrfs_dir_item *item, |
| 745 | struct btrfs_key *key) |
| 746 | { |
| 747 | struct btrfs_disk_key disk_key; |
| 748 | btrfs_dir_item_key(eb, item, &disk_key); |
| 749 | btrfs_disk_key_to_cpu(key, &disk_key); |
| 750 | } |
| 751 | |
| 752 | /* struct btrfs_header */ |
| 753 | BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); |
| 754 | BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, |
| 755 | generation, 64); |
| 756 | BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); |
| 757 | BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); |
| 758 | BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); |
| 759 | BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); |
| 760 | BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); |
| 761 | BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, nritems, |
| 762 | 32); |
| 763 | BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); |
| 764 | BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, |
| 765 | generation, 64); |
| 766 | |
| 767 | static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag) |
| 768 | { |
| 769 | return (btrfs_header_flags(eb) & flag) == flag; |
| 770 | } |
| 771 | |
| 772 | static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag) |
| 773 | { |
| 774 | u64 flags = btrfs_header_flags(eb); |
| 775 | btrfs_set_header_flags(eb, flags | flag); |
| 776 | return (flags & flag) == flag; |
| 777 | } |
| 778 | |
| 779 | static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag) |
| 780 | { |
| 781 | u64 flags = btrfs_header_flags(eb); |
| 782 | btrfs_set_header_flags(eb, flags & ~flag); |
| 783 | return (flags & flag) == flag; |
| 784 | } |
| 785 | |
| 786 | static inline int btrfs_header_backref_rev(struct extent_buffer *eb) |
| 787 | { |
| 788 | u64 flags = btrfs_header_flags(eb); |
| 789 | return flags >> BTRFS_BACKREF_REV_SHIFT; |
| 790 | } |
| 791 | |
| 792 | static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb, |
| 793 | int rev) |
| 794 | { |
| 795 | u64 flags = btrfs_header_flags(eb); |
| 796 | flags &= ~BTRFS_BACKREF_REV_MASK; |
| 797 | flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT; |
| 798 | btrfs_set_header_flags(eb, flags); |
| 799 | } |
| 800 | |
| 801 | static inline unsigned long btrfs_header_fsid(void) |
| 802 | { |
| 803 | return offsetof(struct btrfs_header, fsid); |
| 804 | } |
| 805 | |
| 806 | static inline unsigned long btrfs_header_chunk_tree_uuid(struct extent_buffer *eb) |
| 807 | { |
| 808 | return offsetof(struct btrfs_header, chunk_tree_uuid); |
| 809 | } |
| 810 | |
| 811 | static inline u8 *btrfs_header_csum(struct extent_buffer *eb) |
| 812 | { |
| 813 | unsigned long ptr = offsetof(struct btrfs_header, csum); |
| 814 | return (u8 *)ptr; |
| 815 | } |
| 816 | |
| 817 | static inline int btrfs_is_leaf(struct extent_buffer *eb) |
| 818 | { |
| 819 | return (btrfs_header_level(eb) == 0); |
| 820 | } |
| 821 | |
| 822 | /* struct btrfs_root_item */ |
| 823 | BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item, |
| 824 | generation, 64); |
| 825 | BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); |
| 826 | BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); |
| 827 | BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); |
| 828 | |
| 829 | BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item, |
| 830 | generation, 64); |
| 831 | BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); |
| 832 | BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); |
| 833 | BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); |
| 834 | BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); |
| 835 | BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64); |
| 836 | BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); |
| 837 | BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); |
| 838 | BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item, |
| 839 | last_snapshot, 64); |
| 840 | BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item, |
| 841 | generation_v2, 64); |
| 842 | BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item, |
| 843 | ctransid, 64); |
| 844 | BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item, |
| 845 | otransid, 64); |
| 846 | BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item, |
| 847 | stransid, 64); |
| 848 | BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, |
| 849 | rtransid, 64); |
| 850 | |
| 851 | static inline struct btrfs_timespec* btrfs_root_ctime( |
| 852 | struct btrfs_root_item *root_item) |
| 853 | { |
| 854 | unsigned long ptr = (unsigned long)root_item; |
| 855 | ptr += offsetof(struct btrfs_root_item, ctime); |
| 856 | return (struct btrfs_timespec *)ptr; |
| 857 | } |
| 858 | |
| 859 | static inline struct btrfs_timespec* btrfs_root_otime( |
| 860 | struct btrfs_root_item *root_item) |
| 861 | { |
| 862 | unsigned long ptr = (unsigned long)root_item; |
| 863 | ptr += offsetof(struct btrfs_root_item, otime); |
| 864 | return (struct btrfs_timespec *)ptr; |
| 865 | } |
| 866 | |
| 867 | static inline struct btrfs_timespec* btrfs_root_stime( |
| 868 | struct btrfs_root_item *root_item) |
| 869 | { |
| 870 | unsigned long ptr = (unsigned long)root_item; |
| 871 | ptr += offsetof(struct btrfs_root_item, stime); |
| 872 | return (struct btrfs_timespec *)ptr; |
| 873 | } |
| 874 | |
| 875 | static inline struct btrfs_timespec* btrfs_root_rtime( |
| 876 | struct btrfs_root_item *root_item) |
| 877 | { |
| 878 | unsigned long ptr = (unsigned long)root_item; |
| 879 | ptr += offsetof(struct btrfs_root_item, rtime); |
| 880 | return (struct btrfs_timespec *)ptr; |
| 881 | } |
| 882 | |
| 883 | /* struct btrfs_root_backup */ |
| 884 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup, |
| 885 | tree_root, 64); |
| 886 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup, |
| 887 | tree_root_gen, 64); |
| 888 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup, |
| 889 | tree_root_level, 8); |
| 890 | |
| 891 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup, |
| 892 | chunk_root, 64); |
| 893 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup, |
| 894 | chunk_root_gen, 64); |
| 895 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup, |
| 896 | chunk_root_level, 8); |
| 897 | |
| 898 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup, |
| 899 | extent_root, 64); |
| 900 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup, |
| 901 | extent_root_gen, 64); |
| 902 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup, |
| 903 | extent_root_level, 8); |
| 904 | |
| 905 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup, |
| 906 | fs_root, 64); |
| 907 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup, |
| 908 | fs_root_gen, 64); |
| 909 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup, |
| 910 | fs_root_level, 8); |
| 911 | |
| 912 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup, |
| 913 | dev_root, 64); |
| 914 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup, |
| 915 | dev_root_gen, 64); |
| 916 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup, |
| 917 | dev_root_level, 8); |
| 918 | |
| 919 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup, |
| 920 | csum_root, 64); |
| 921 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup, |
| 922 | csum_root_gen, 64); |
| 923 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup, |
| 924 | csum_root_level, 8); |
| 925 | BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup, |
| 926 | total_bytes, 64); |
| 927 | BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup, |
| 928 | bytes_used, 64); |
| 929 | BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup, |
| 930 | num_devices, 64); |
Qu Wenruo | 4aebb99 | 2020-06-24 18:02:49 +0200 | [diff] [blame] | 931 | |
| 932 | /* struct btrfs_super_block */ |
| 933 | |
| 934 | BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); |
| 935 | BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64); |
| 936 | BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, |
| 937 | generation, 64); |
| 938 | BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); |
| 939 | BTRFS_SETGET_STACK_FUNCS(super_sys_array_size, |
| 940 | struct btrfs_super_block, sys_chunk_array_size, 32); |
| 941 | BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation, |
| 942 | struct btrfs_super_block, chunk_root_generation, 64); |
| 943 | BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, |
| 944 | root_level, 8); |
| 945 | BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block, |
| 946 | chunk_root, 64); |
| 947 | BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block, |
| 948 | chunk_root_level, 8); |
| 949 | BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, |
| 950 | log_root, 64); |
| 951 | BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block, |
| 952 | log_root_transid, 64); |
| 953 | BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block, |
| 954 | log_root_level, 8); |
| 955 | BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, |
| 956 | total_bytes, 64); |
| 957 | BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, |
| 958 | bytes_used, 64); |
| 959 | BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, |
| 960 | sectorsize, 32); |
| 961 | BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, |
| 962 | nodesize, 32); |
| 963 | BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, |
| 964 | stripesize, 32); |
| 965 | BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, |
| 966 | root_dir_objectid, 64); |
| 967 | BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, |
| 968 | num_devices, 64); |
| 969 | BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, |
| 970 | compat_flags, 64); |
| 971 | BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, |
| 972 | compat_ro_flags, 64); |
| 973 | BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, |
| 974 | incompat_flags, 64); |
| 975 | BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, |
| 976 | csum_type, 16); |
| 977 | BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, |
| 978 | cache_generation, 64); |
| 979 | BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, |
| 980 | uuid_tree_generation, 64); |
| 981 | BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64); |
| 982 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 983 | static inline unsigned long btrfs_leaf_data(struct extent_buffer *l) |
| 984 | { |
| 985 | return offsetof(struct btrfs_leaf, items); |
| 986 | } |
| 987 | |
| 988 | /* struct btrfs_file_extent_item */ |
| 989 | BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); |
| 990 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, type, 8); |
| 991 | |
| 992 | static inline unsigned long btrfs_file_extent_inline_start(struct |
| 993 | btrfs_file_extent_item *e) |
| 994 | { |
| 995 | unsigned long offset = (unsigned long)e; |
| 996 | offset += offsetof(struct btrfs_file_extent_item, disk_bytenr); |
| 997 | return offset; |
| 998 | } |
| 999 | |
| 1000 | static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) |
| 1001 | { |
| 1002 | return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize; |
| 1003 | } |
| 1004 | |
| 1005 | BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, |
| 1006 | disk_bytenr, 64); |
| 1007 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, struct btrfs_file_extent_item, |
| 1008 | disk_bytenr, 64); |
| 1009 | BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, |
| 1010 | generation, 64); |
| 1011 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation, struct btrfs_file_extent_item, |
| 1012 | generation, 64); |
| 1013 | BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, |
| 1014 | disk_num_bytes, 64); |
| 1015 | BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, |
| 1016 | offset, 64); |
| 1017 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset, struct btrfs_file_extent_item, |
| 1018 | offset, 64); |
| 1019 | BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, |
| 1020 | num_bytes, 64); |
| 1021 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes, struct btrfs_file_extent_item, |
| 1022 | num_bytes, 64); |
| 1023 | BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item, |
| 1024 | ram_bytes, 64); |
| 1025 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes, struct btrfs_file_extent_item, |
| 1026 | ram_bytes, 64); |
| 1027 | BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item, |
| 1028 | compression, 8); |
| 1029 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, struct btrfs_file_extent_item, |
| 1030 | compression, 8); |
| 1031 | BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, |
| 1032 | encryption, 8); |
| 1033 | BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, |
| 1034 | other_encoding, 16); |
| 1035 | |
| 1036 | /* btrfs_qgroup_status_item */ |
| 1037 | BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, |
| 1038 | version, 64); |
| 1039 | BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, |
| 1040 | generation, 64); |
| 1041 | BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item, |
| 1042 | flags, 64); |
| 1043 | BTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item, |
| 1044 | rescan, 64); |
| 1045 | |
| 1046 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_status_version, |
| 1047 | struct btrfs_qgroup_status_item, version, 64); |
| 1048 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_status_generation, |
| 1049 | struct btrfs_qgroup_status_item, generation, 64); |
| 1050 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_status_flags, |
| 1051 | struct btrfs_qgroup_status_item, flags, 64); |
| 1052 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_status_rescan, |
| 1053 | struct btrfs_qgroup_status_item, rescan, 64); |
| 1054 | |
| 1055 | /* btrfs_qgroup_info_item */ |
| 1056 | BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item, |
| 1057 | generation, 64); |
| 1058 | BTRFS_SETGET_FUNCS(qgroup_info_referenced, struct btrfs_qgroup_info_item, |
| 1059 | rfer, 64); |
| 1060 | BTRFS_SETGET_FUNCS(qgroup_info_referenced_compressed, |
| 1061 | struct btrfs_qgroup_info_item, rfer_cmpr, 64); |
| 1062 | BTRFS_SETGET_FUNCS(qgroup_info_exclusive, struct btrfs_qgroup_info_item, |
| 1063 | excl, 64); |
| 1064 | BTRFS_SETGET_FUNCS(qgroup_info_exclusive_compressed, |
| 1065 | struct btrfs_qgroup_info_item, excl_cmpr, 64); |
| 1066 | |
| 1067 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation, |
| 1068 | struct btrfs_qgroup_info_item, generation, 64); |
| 1069 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_referenced, |
| 1070 | struct btrfs_qgroup_info_item, rfer, 64); |
| 1071 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_referenced_compressed, |
| 1072 | struct btrfs_qgroup_info_item, rfer_cmpr, 64); |
| 1073 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_exclusive, |
| 1074 | struct btrfs_qgroup_info_item, excl, 64); |
| 1075 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_exclusive_compressed, |
| 1076 | struct btrfs_qgroup_info_item, excl_cmpr, 64); |
| 1077 | |
| 1078 | /* btrfs_qgroup_limit_item */ |
| 1079 | BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, |
| 1080 | flags, 64); |
| 1081 | BTRFS_SETGET_FUNCS(qgroup_limit_max_referenced, struct btrfs_qgroup_limit_item, |
| 1082 | max_rfer, 64); |
| 1083 | BTRFS_SETGET_FUNCS(qgroup_limit_max_exclusive, struct btrfs_qgroup_limit_item, |
| 1084 | max_excl, 64); |
| 1085 | BTRFS_SETGET_FUNCS(qgroup_limit_rsv_referenced, struct btrfs_qgroup_limit_item, |
| 1086 | rsv_rfer, 64); |
| 1087 | BTRFS_SETGET_FUNCS(qgroup_limit_rsv_exclusive, struct btrfs_qgroup_limit_item, |
| 1088 | rsv_excl, 64); |
| 1089 | |
| 1090 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_flags, |
| 1091 | struct btrfs_qgroup_limit_item, flags, 64); |
| 1092 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_referenced, |
| 1093 | struct btrfs_qgroup_limit_item, max_rfer, 64); |
| 1094 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_exclusive, |
| 1095 | struct btrfs_qgroup_limit_item, max_excl, 64); |
| 1096 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_referenced, |
| 1097 | struct btrfs_qgroup_limit_item, rsv_rfer, 64); |
| 1098 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_exclusive, |
| 1099 | struct btrfs_qgroup_limit_item, rsv_excl, 64); |
| 1100 | |
| 1101 | /* btrfs_balance_item */ |
| 1102 | BTRFS_SETGET_FUNCS(balance_item_flags, struct btrfs_balance_item, flags, 64); |
| 1103 | |
| 1104 | static inline struct btrfs_disk_balance_args* btrfs_balance_item_data( |
| 1105 | struct extent_buffer *eb, struct btrfs_balance_item *bi) |
| 1106 | { |
| 1107 | unsigned long offset = (unsigned long)bi; |
| 1108 | struct btrfs_balance_item *p; |
| 1109 | p = (struct btrfs_balance_item *)(eb->data + offset); |
| 1110 | return &p->data; |
| 1111 | } |
| 1112 | |
| 1113 | static inline struct btrfs_disk_balance_args* btrfs_balance_item_meta( |
| 1114 | struct extent_buffer *eb, struct btrfs_balance_item *bi) |
| 1115 | { |
| 1116 | unsigned long offset = (unsigned long)bi; |
| 1117 | struct btrfs_balance_item *p; |
| 1118 | p = (struct btrfs_balance_item *)(eb->data + offset); |
| 1119 | return &p->meta; |
| 1120 | } |
| 1121 | |
| 1122 | static inline struct btrfs_disk_balance_args* btrfs_balance_item_sys( |
| 1123 | struct extent_buffer *eb, struct btrfs_balance_item *bi) |
| 1124 | { |
| 1125 | unsigned long offset = (unsigned long)bi; |
| 1126 | struct btrfs_balance_item *p; |
| 1127 | p = (struct btrfs_balance_item *)(eb->data + offset); |
| 1128 | return &p->sys; |
| 1129 | } |
| 1130 | |
| 1131 | static inline u64 btrfs_dev_stats_value(const struct extent_buffer *eb, |
| 1132 | const struct btrfs_dev_stats_item *ptr, |
| 1133 | int index) |
| 1134 | { |
| 1135 | u64 val; |
| 1136 | |
| 1137 | read_extent_buffer(eb, &val, |
| 1138 | offsetof(struct btrfs_dev_stats_item, values) + |
| 1139 | ((unsigned long)ptr) + (index * sizeof(u64)), |
| 1140 | sizeof(val)); |
| 1141 | return val; |
| 1142 | } |
| 1143 | |
| 1144 | /* |
| 1145 | * this returns the number of bytes used by the item on disk, minus the |
| 1146 | * size of any extent headers. If a file is compressed on disk, this is |
| 1147 | * the compressed size |
| 1148 | */ |
| 1149 | static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb, |
| 1150 | struct btrfs_item *e) |
| 1151 | { |
| 1152 | unsigned long offset; |
| 1153 | offset = offsetof(struct btrfs_file_extent_item, disk_bytenr); |
| 1154 | return btrfs_item_size(eb, e) - offset; |
| 1155 | } |
| 1156 | |
| 1157 | #define btrfs_fs_incompat(fs_info, opt) \ |
| 1158 | __btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt) |
| 1159 | |
| 1160 | static inline bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag) |
| 1161 | { |
| 1162 | struct btrfs_super_block *disk_super; |
| 1163 | disk_super = fs_info->super_copy; |
| 1164 | return !!(btrfs_super_incompat_flags(disk_super) & flag); |
| 1165 | } |
| 1166 | |
| 1167 | #define btrfs_fs_compat_ro(fs_info, opt) \ |
| 1168 | __btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) |
| 1169 | |
| 1170 | static inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag) |
| 1171 | { |
| 1172 | struct btrfs_super_block *disk_super; |
| 1173 | disk_super = fs_info->super_copy; |
| 1174 | return !!(btrfs_super_compat_ro_flags(disk_super) & flag); |
| 1175 | } |
| 1176 | |
| 1177 | /* helper function to cast into the data area of the leaf. */ |
| 1178 | #define btrfs_item_ptr(leaf, slot, type) \ |
| 1179 | ((type *)(btrfs_leaf_data(leaf) + \ |
| 1180 | btrfs_item_offset_nr(leaf, slot))) |
| 1181 | |
| 1182 | #define btrfs_item_ptr_offset(leaf, slot) \ |
| 1183 | ((unsigned long)(btrfs_leaf_data(leaf) + \ |
| 1184 | btrfs_item_offset_nr(leaf, slot))) |
| 1185 | |
| 1186 | static inline u64 btrfs_name_hash(const char *name, int len) |
| 1187 | { |
| 1188 | return (u64)crc32c((u32)~1, (u8 *)name, len); |
| 1189 | } |
| 1190 | |
| 1191 | /* |
| 1192 | * Figure the key offset of an extended inode ref |
| 1193 | */ |
| 1194 | static inline u64 btrfs_extref_hash(u64 parent_objectid, const char *name, |
| 1195 | int len) |
| 1196 | { |
| 1197 | return crc32(parent_objectid, (u8 *)name, len); |
| 1198 | } |
| 1199 | |
| 1200 | union btrfs_tree_node { |
| 1201 | struct btrfs_header header; |
| 1202 | struct btrfs_leaf leaf; |
| 1203 | struct btrfs_node node; |
| 1204 | }; |
| 1205 | |
Qu Wenruo | be35942 | 2020-06-24 18:02:53 +0200 | [diff] [blame] | 1206 | #define btrfs_path_item_ptr(p,t) \ |
| 1207 | ((t *) btrfs_path_leaf_data((p))) |
| 1208 | |
| 1209 | u16 btrfs_super_csum_size(const struct btrfs_super_block *s); |
| 1210 | const char *btrfs_super_csum_name(u16 csum_type); |
| 1211 | u16 btrfs_csum_type_size(u16 csum_type); |
| 1212 | size_t btrfs_super_num_csums(void); |
| 1213 | |
Qu Wenruo | f06bfcf | 2020-06-24 18:03:01 +0200 | [diff] [blame] | 1214 | /* root-tree.c */ |
| 1215 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, |
| 1216 | struct btrfs_root_item *item, struct btrfs_key *key); |
| 1217 | |
Qu Wenruo | cafffc5 | 2020-06-24 18:03:02 +0200 | [diff] [blame] | 1218 | /* dir-item.c */ |
| 1219 | struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, |
| 1220 | struct btrfs_root *root, |
| 1221 | struct btrfs_path *path, u64 dir, |
| 1222 | const char *name, int name_len, |
| 1223 | int mod); |
Qu Wenruo | 325dd1f | 2020-06-24 18:03:06 +0200 | [diff] [blame] | 1224 | typedef int (*btrfs_iter_dir_callback_t)(struct btrfs_root *root, |
| 1225 | struct extent_buffer *eb, |
| 1226 | struct btrfs_dir_item *di); |
| 1227 | int btrfs_iter_dir(struct btrfs_root *root, u64 ino, |
| 1228 | btrfs_iter_dir_callback_t callback); |
Qu Wenruo | c921aa2 | 2020-06-24 18:03:05 +0200 | [diff] [blame] | 1229 | /* inode.c */ |
| 1230 | int btrfs_lookup_path(struct btrfs_root *root, u64 ino, const char *filename, |
| 1231 | struct btrfs_root **root_ret, u64 *ino_ret, |
| 1232 | u8 *type_ret, int symlink_limit); |
Qu Wenruo | a26a6be | 2020-06-24 18:03:09 +0200 | [diff] [blame] | 1233 | int btrfs_read_extent_inline(struct btrfs_path *path, |
| 1234 | struct btrfs_file_extent_item *fi, char *dest); |
| 1235 | int btrfs_read_extent_reg(struct btrfs_path *path, |
| 1236 | struct btrfs_file_extent_item *fi, u64 offset, |
| 1237 | int len, char *dest); |
Qu Wenruo | cafffc5 | 2020-06-24 18:03:02 +0200 | [diff] [blame] | 1238 | |
Qu Wenruo | 75b0817 | 2020-06-24 18:02:55 +0200 | [diff] [blame] | 1239 | /* ctree.c */ |
| 1240 | int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); |
| 1241 | enum btrfs_tree_block_status |
| 1242 | btrfs_check_node(struct btrfs_fs_info *fs_info, |
| 1243 | struct btrfs_disk_key *parent_key, struct extent_buffer *buf); |
| 1244 | enum btrfs_tree_block_status |
| 1245 | btrfs_check_leaf(struct btrfs_fs_info *fs_info, |
| 1246 | struct btrfs_disk_key *parent_key, struct extent_buffer *buf); |
Qu Wenruo | 29c26ae | 2020-06-24 18:02:59 +0200 | [diff] [blame] | 1247 | struct extent_buffer *read_node_slot(struct btrfs_fs_info *fs_info, |
| 1248 | struct extent_buffer *parent, int slot); |
| 1249 | int btrfs_previous_item(struct btrfs_root *root, |
| 1250 | struct btrfs_path *path, u64 min_objectid, |
| 1251 | int type); |
| 1252 | int btrfs_next_sibling_tree_block(struct btrfs_fs_info *fs_info, |
| 1253 | struct btrfs_path *path); |
| 1254 | /* |
| 1255 | * Walk up the tree as far as necessary to find the next leaf. |
| 1256 | * |
| 1257 | * returns 0 if it found something or 1 if there are no greater leaves. |
| 1258 | * returns < 0 on io errors. |
| 1259 | */ |
| 1260 | static inline int btrfs_next_leaf(struct btrfs_root *root, |
| 1261 | struct btrfs_path *path) |
| 1262 | { |
| 1263 | path->lowest_level = 0; |
| 1264 | return btrfs_next_sibling_tree_block(root->fs_info, path); |
| 1265 | } |
| 1266 | |
| 1267 | static inline int btrfs_next_item(struct btrfs_root *root, |
| 1268 | struct btrfs_path *p) |
| 1269 | { |
| 1270 | ++p->slots[0]; |
| 1271 | if (p->slots[0] >= btrfs_header_nritems(p->nodes[0])) |
| 1272 | return btrfs_next_leaf(root, p); |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
| 1276 | int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); |
Qu Wenruo | 75b0817 | 2020-06-24 18:02:55 +0200 | [diff] [blame] | 1277 | int btrfs_leaf_free_space(struct extent_buffer *leaf); |
Qu Wenruo | 29c26ae | 2020-06-24 18:02:59 +0200 | [diff] [blame] | 1278 | int btrfs_search_slot(struct btrfs_trans_handle *trans, |
| 1279 | struct btrfs_root *root, const struct btrfs_key *key, |
| 1280 | struct btrfs_path *p, int ins_len, int cow); |
| 1281 | int btrfs_search_slot_for_read(struct btrfs_root *root, |
| 1282 | const struct btrfs_key *key, |
| 1283 | struct btrfs_path *p, int find_higher, |
| 1284 | int return_any); |
| 1285 | void btrfs_release_path(struct btrfs_path *p); |
| 1286 | struct btrfs_path *btrfs_alloc_path(void); |
| 1287 | void btrfs_free_path(struct btrfs_path *p); |
| 1288 | static inline void btrfs_init_path(struct btrfs_path *p) |
| 1289 | { |
| 1290 | memset(p, 0, sizeof(*p)); |
| 1291 | } |
| 1292 | int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, |
| 1293 | int *slot); |
| 1294 | int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *found_path, |
| 1295 | u64 iobjectid, u64 ioff, u8 key_type, |
| 1296 | struct btrfs_key *found_key); |
Marek Behún | d4a704a | 2017-09-03 17:00:26 +0200 | [diff] [blame] | 1297 | #endif /* __BTRFS_CTREE_H__ */ |