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