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