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