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