| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | |
| 3 | #ifndef BTRFS_ACCESSORS_H |
| 4 | #define BTRFS_ACCESSORS_H |
| 5 | |
| 6 | #include <linux/unaligned.h> |
| 7 | #include <linux/stddef.h> |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/align.h> |
| 10 | #include <linux/build_bug.h> |
| 11 | #include <linux/compiler.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <uapi/linux/btrfs_tree.h> |
| 15 | #include "fs.h" |
| 16 | #include "extent_io.h" |
| 17 | |
| 18 | struct extent_buffer; |
| 19 | |
| 20 | /* |
| 21 | * Some macros to generate set/get functions for the struct fields. This |
| 22 | * assumes there is a lefoo_to_cpu for every type, so lets make a simple one |
| 23 | * for u8: |
| 24 | */ |
| 25 | #define le8_to_cpu(v) (v) |
| 26 | #define cpu_to_le8(v) (v) |
| 27 | #define __le8 u8 |
| 28 | |
| 29 | static inline u8 get_unaligned_le8(const void *p) |
| 30 | { |
| 31 | return *(const u8 *)p; |
| 32 | } |
| 33 | |
| 34 | static inline void put_unaligned_le8(u8 val, void *p) |
| 35 | { |
| 36 | *(u8 *)p = val; |
| 37 | } |
| 38 | |
| 39 | #define read_eb_member(eb, ptr, type, member, result) (\ |
| 40 | read_extent_buffer(eb, (char *)(result), \ |
| 41 | ((unsigned long)(ptr)) + \ |
| 42 | offsetof(type, member), \ |
| 43 | sizeof_field(type, member))) |
| 44 | |
| 45 | #define write_eb_member(eb, ptr, type, member, source) ( \ |
| 46 | write_extent_buffer(eb, (const char *)(source), \ |
| 47 | ((unsigned long)(ptr)) + \ |
| 48 | offsetof(type, member), \ |
| 49 | sizeof_field(type, member))) |
| 50 | |
| 51 | #define DECLARE_BTRFS_SETGET_BITS(bits) \ |
| 52 | u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ |
| 53 | const void *ptr, unsigned long off); \ |
| 54 | void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \ |
| 55 | unsigned long off, u##bits val); |
| 56 | |
| 57 | DECLARE_BTRFS_SETGET_BITS(8) |
| 58 | DECLARE_BTRFS_SETGET_BITS(16) |
| 59 | DECLARE_BTRFS_SETGET_BITS(32) |
| 60 | DECLARE_BTRFS_SETGET_BITS(64) |
| 61 | |
| 62 | #define BTRFS_SETGET_FUNCS(name, type, member, bits) \ |
| 63 | static inline u##bits btrfs_##name(const struct extent_buffer *eb, \ |
| 64 | const type *s) \ |
| 65 | { \ |
| 66 | static_assert(sizeof(u##bits) == sizeof_field(type, member)); \ |
| 67 | return btrfs_get_##bits(eb, s, offsetof(type, member)); \ |
| 68 | } \ |
| 69 | static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \ |
| 70 | u##bits val) \ |
| 71 | { \ |
| 72 | static_assert(sizeof(u##bits) == sizeof_field(type, member)); \ |
| 73 | btrfs_set_##bits(eb, s, offsetof(type, member), val); \ |
| 74 | } |
| 75 | |
| 76 | #define (name, type, member, bits) \ |
| 77 | static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ |
| 78 | { \ |
| 79 | const type *p = folio_address(eb->folios[0]) + \ |
| 80 | offset_in_page(eb->start); \ |
| 81 | return get_unaligned_le##bits(&p->member); \ |
| 82 | } \ |
| 83 | static inline void btrfs_set_##name(const struct extent_buffer *eb, \ |
| 84 | u##bits val) \ |
| 85 | { \ |
| 86 | type *p = folio_address(eb->folios[0]) + offset_in_page(eb->start); \ |
| 87 | put_unaligned_le##bits(val, &p->member); \ |
| 88 | } |
| 89 | |
| 90 | #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ |
| 91 | static inline u##bits btrfs_##name(const type *s) \ |
| 92 | { \ |
| 93 | return get_unaligned_le##bits(&s->member); \ |
| 94 | } \ |
| 95 | static inline void btrfs_set_##name(type *s, u##bits val) \ |
| 96 | { \ |
| 97 | put_unaligned_le##bits(val, &s->member); \ |
| 98 | } |
| 99 | |
| 100 | static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb, |
| 101 | struct btrfs_dev_item *s) |
| 102 | { |
| 103 | static_assert(sizeof(u64) == sizeof_field(struct btrfs_dev_item, total_bytes)); |
| 104 | return btrfs_get_64(eb, ptr: s, offsetof(struct btrfs_dev_item, total_bytes)); |
| 105 | } |
| 106 | static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb, |
| 107 | struct btrfs_dev_item *s, |
| 108 | u64 val) |
| 109 | { |
| 110 | static_assert(sizeof(u64) == sizeof_field(struct btrfs_dev_item, total_bytes)); |
| 111 | WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize)); |
| 112 | btrfs_set_64(eb, ptr: s, offsetof(struct btrfs_dev_item, total_bytes), val); |
| 113 | } |
| 114 | |
| 115 | BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64); |
| 116 | BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64); |
| 117 | BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32); |
| 118 | BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32); |
| 119 | BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item, start_offset, 64); |
| 120 | BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32); |
| 121 | BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64); |
| 122 | BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32); |
| 123 | BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8); |
| 124 | BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8); |
| 125 | BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64); |
| 126 | |
| 127 | BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64); |
| 128 | BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item, |
| 129 | total_bytes, 64); |
| 130 | BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item, |
| 131 | bytes_used, 64); |
| 132 | BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item, |
| 133 | io_align, 32); |
| 134 | BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item, |
| 135 | io_width, 32); |
| 136 | BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item, |
| 137 | sector_size, 32); |
| 138 | BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64); |
| 139 | BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item, dev_group, 32); |
| 140 | BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item, |
| 141 | seek_speed, 8); |
| 142 | BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item, |
| 143 | bandwidth, 8); |
| 144 | BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item, |
| 145 | generation, 64); |
| 146 | |
| 147 | static inline unsigned long btrfs_device_uuid(struct btrfs_dev_item *d) |
| 148 | { |
| 149 | return (unsigned long)d + offsetof(struct btrfs_dev_item, uuid); |
| 150 | } |
| 151 | |
| 152 | static inline unsigned long btrfs_device_fsid(struct btrfs_dev_item *d) |
| 153 | { |
| 154 | return (unsigned long)d + offsetof(struct btrfs_dev_item, fsid); |
| 155 | } |
| 156 | |
| 157 | BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64); |
| 158 | BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64); |
| 159 | BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64); |
| 160 | BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32); |
| 161 | BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32); |
| 162 | BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32); |
| 163 | BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64); |
| 164 | BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16); |
| 165 | BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16); |
| 166 | BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64); |
| 167 | BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64); |
| 168 | |
| 169 | static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s) |
| 170 | { |
| 171 | return (char *)s + offsetof(struct btrfs_stripe, dev_uuid); |
| 172 | } |
| 173 | |
| 174 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64); |
| 175 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64); |
| 176 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk, |
| 177 | stripe_len, 64); |
| 178 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk, io_align, 32); |
| 179 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk, io_width, 32); |
| 180 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk, |
| 181 | sector_size, 32); |
| 182 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64); |
| 183 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk, |
| 184 | num_stripes, 16); |
| 185 | BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk, |
| 186 | sub_stripes, 16); |
| 187 | BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64); |
| 188 | BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64); |
| 189 | |
| 190 | static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c, int nr) |
| 191 | { |
| 192 | unsigned long offset = (unsigned long)c; |
| 193 | |
| 194 | offset += offsetof(struct btrfs_chunk, stripe); |
| 195 | offset += nr * sizeof(struct btrfs_stripe); |
| 196 | return (struct btrfs_stripe *)offset; |
| 197 | } |
| 198 | |
| 199 | static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr) |
| 200 | { |
| 201 | return btrfs_stripe_dev_uuid(s: btrfs_stripe_nr(c, nr)); |
| 202 | } |
| 203 | |
| 204 | static inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb, |
| 205 | struct btrfs_chunk *c, int nr) |
| 206 | { |
| 207 | return btrfs_stripe_offset(eb, s: btrfs_stripe_nr(c, nr)); |
| 208 | } |
| 209 | |
| 210 | static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb, |
| 211 | struct btrfs_chunk *c, int nr, |
| 212 | u64 val) |
| 213 | { |
| 214 | btrfs_set_stripe_offset(eb, s: btrfs_stripe_nr(c, nr), val); |
| 215 | } |
| 216 | |
| 217 | static inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb, |
| 218 | struct btrfs_chunk *c, int nr) |
| 219 | { |
| 220 | return btrfs_stripe_devid(eb, s: btrfs_stripe_nr(c, nr)); |
| 221 | } |
| 222 | |
| 223 | static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb, |
| 224 | struct btrfs_chunk *c, int nr, |
| 225 | u64 val) |
| 226 | { |
| 227 | btrfs_set_stripe_devid(eb, s: btrfs_stripe_nr(c, nr), val); |
| 228 | } |
| 229 | |
| 230 | /* struct btrfs_block_group_item */ |
| 231 | BTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item, |
| 232 | used, 64); |
| 233 | BTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item, used, 64); |
| 234 | BTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid, |
| 235 | struct btrfs_block_group_item, chunk_objectid, 64); |
| 236 | |
| 237 | BTRFS_SETGET_FUNCS(block_group_chunk_objectid, |
| 238 | struct btrfs_block_group_item, chunk_objectid, 64); |
| 239 | BTRFS_SETGET_FUNCS(block_group_flags, struct btrfs_block_group_item, flags, 64); |
| 240 | BTRFS_SETGET_STACK_FUNCS(stack_block_group_flags, |
| 241 | struct btrfs_block_group_item, flags, 64); |
| 242 | |
| 243 | /* struct btrfs_free_space_info */ |
| 244 | BTRFS_SETGET_FUNCS(free_space_extent_count, struct btrfs_free_space_info, |
| 245 | extent_count, 32); |
| 246 | BTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32); |
| 247 | |
| 248 | /* struct btrfs_inode_ref */ |
| 249 | BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); |
| 250 | BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64); |
| 251 | BTRFS_SETGET_STACK_FUNCS(stack_inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); |
| 252 | BTRFS_SETGET_STACK_FUNCS(stack_inode_ref_index, struct btrfs_inode_ref, index, 64); |
| 253 | |
| 254 | /* struct btrfs_inode_extref */ |
| 255 | BTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref, |
| 256 | parent_objectid, 64); |
| 257 | BTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref, |
| 258 | name_len, 16); |
| 259 | BTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64); |
| 260 | |
| 261 | /* struct btrfs_inode_item */ |
| 262 | BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); |
| 263 | BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64); |
| 264 | BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64); |
| 265 | BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); |
| 266 | BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64); |
| 267 | BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); |
| 268 | BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); |
| 269 | BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); |
| 270 | BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32); |
| 271 | BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32); |
| 272 | BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64); |
| 273 | BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64); |
| 274 | BTRFS_SETGET_STACK_FUNCS(stack_inode_generation, struct btrfs_inode_item, |
| 275 | generation, 64); |
| 276 | BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, struct btrfs_inode_item, |
| 277 | sequence, 64); |
| 278 | BTRFS_SETGET_STACK_FUNCS(stack_inode_transid, struct btrfs_inode_item, |
| 279 | transid, 64); |
| 280 | BTRFS_SETGET_STACK_FUNCS(stack_inode_size, struct btrfs_inode_item, size, 64); |
| 281 | BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, struct btrfs_inode_item, nbytes, 64); |
| 282 | BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, struct btrfs_inode_item, |
| 283 | block_group, 64); |
| 284 | BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, struct btrfs_inode_item, nlink, 32); |
| 285 | BTRFS_SETGET_STACK_FUNCS(stack_inode_uid, struct btrfs_inode_item, uid, 32); |
| 286 | BTRFS_SETGET_STACK_FUNCS(stack_inode_gid, struct btrfs_inode_item, gid, 32); |
| 287 | BTRFS_SETGET_STACK_FUNCS(stack_inode_mode, struct btrfs_inode_item, mode, 32); |
| 288 | BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, struct btrfs_inode_item, rdev, 64); |
| 289 | BTRFS_SETGET_STACK_FUNCS(stack_inode_flags, struct btrfs_inode_item, flags, 64); |
| 290 | BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); |
| 291 | BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); |
| 292 | BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64); |
| 293 | BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32); |
| 294 | |
| 295 | BTRFS_SETGET_FUNCS(raid_stride_devid, struct btrfs_raid_stride, devid, 64); |
| 296 | BTRFS_SETGET_FUNCS(raid_stride_physical, struct btrfs_raid_stride, physical, 64); |
| 297 | BTRFS_SETGET_STACK_FUNCS(stack_raid_stride_devid, struct btrfs_raid_stride, devid, 64); |
| 298 | BTRFS_SETGET_STACK_FUNCS(stack_raid_stride_physical, struct btrfs_raid_stride, physical, 64); |
| 299 | |
| 300 | /* struct btrfs_dev_extent */ |
| 301 | BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, chunk_tree, 64); |
| 302 | BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent, |
| 303 | chunk_objectid, 64); |
| 304 | BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent, |
| 305 | chunk_offset, 64); |
| 306 | BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); |
| 307 | BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_tree, struct btrfs_dev_extent, |
| 308 | chunk_tree, 64); |
| 309 | BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_objectid, struct btrfs_dev_extent, |
| 310 | chunk_objectid, 64); |
| 311 | BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_offset, struct btrfs_dev_extent, |
| 312 | chunk_offset, 64); |
| 313 | BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_length, struct btrfs_dev_extent, length, 64); |
| 314 | |
| 315 | BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); |
| 316 | BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, generation, 64); |
| 317 | BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64); |
| 318 | |
| 319 | BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8); |
| 320 | |
| 321 | static inline void btrfs_tree_block_key(const struct extent_buffer *eb, |
| 322 | struct btrfs_tree_block_info *item, |
| 323 | struct btrfs_disk_key *key) |
| 324 | { |
| 325 | read_eb_member(eb, item, struct btrfs_tree_block_info, key, key); |
| 326 | } |
| 327 | |
| 328 | static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb, |
| 329 | struct btrfs_tree_block_info *item, |
| 330 | const struct btrfs_disk_key *key) |
| 331 | { |
| 332 | write_eb_member(eb, item, struct btrfs_tree_block_info, key, key); |
| 333 | } |
| 334 | |
| 335 | BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref, root, 64); |
| 336 | BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref, |
| 337 | objectid, 64); |
| 338 | BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref, |
| 339 | offset, 64); |
| 340 | BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref, count, 32); |
| 341 | |
| 342 | BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref, count, 32); |
| 343 | |
| 344 | BTRFS_SETGET_FUNCS(extent_owner_ref_root_id, struct btrfs_extent_owner_ref, |
| 345 | root_id, 64); |
| 346 | |
| 347 | BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref, |
| 348 | type, 8); |
| 349 | BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref, |
| 350 | offset, 64); |
| 351 | |
| 352 | static inline u32 btrfs_extent_inline_ref_size(int type) |
| 353 | { |
| 354 | if (type == BTRFS_TREE_BLOCK_REF_KEY || |
| 355 | type == BTRFS_SHARED_BLOCK_REF_KEY) |
| 356 | return sizeof(struct btrfs_extent_inline_ref); |
| 357 | if (type == BTRFS_SHARED_DATA_REF_KEY) |
| 358 | return sizeof(struct btrfs_shared_data_ref) + |
| 359 | sizeof(struct btrfs_extent_inline_ref); |
| 360 | if (type == BTRFS_EXTENT_DATA_REF_KEY) |
| 361 | return sizeof(struct btrfs_extent_data_ref) + |
| 362 | offsetof(struct btrfs_extent_inline_ref, offset); |
| 363 | if (type == BTRFS_EXTENT_OWNER_REF_KEY) |
| 364 | return sizeof(struct btrfs_extent_inline_ref); |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | /* struct btrfs_node */ |
| 369 | BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); |
| 370 | BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); |
| 371 | BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr, blockptr, 64); |
| 372 | BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr, |
| 373 | generation, 64); |
| 374 | |
| 375 | static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr) |
| 376 | { |
| 377 | unsigned long ptr; |
| 378 | |
| 379 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 380 | sizeof(struct btrfs_key_ptr) * nr; |
| 381 | return btrfs_key_blockptr(eb, s: (struct btrfs_key_ptr *)ptr); |
| 382 | } |
| 383 | |
| 384 | static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb, |
| 385 | int nr, u64 val) |
| 386 | { |
| 387 | unsigned long ptr; |
| 388 | |
| 389 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 390 | sizeof(struct btrfs_key_ptr) * nr; |
| 391 | btrfs_set_key_blockptr(eb, s: (struct btrfs_key_ptr *)ptr, val); |
| 392 | } |
| 393 | |
| 394 | static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr) |
| 395 | { |
| 396 | unsigned long ptr; |
| 397 | |
| 398 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 399 | sizeof(struct btrfs_key_ptr) * nr; |
| 400 | return btrfs_key_generation(eb, s: (struct btrfs_key_ptr *)ptr); |
| 401 | } |
| 402 | |
| 403 | static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb, |
| 404 | int nr, u64 val) |
| 405 | { |
| 406 | unsigned long ptr; |
| 407 | |
| 408 | ptr = offsetof(struct btrfs_node, ptrs) + |
| 409 | sizeof(struct btrfs_key_ptr) * nr; |
| 410 | btrfs_set_key_generation(eb, s: (struct btrfs_key_ptr *)ptr, val); |
| 411 | } |
| 412 | |
| 413 | static inline unsigned long btrfs_node_key_ptr_offset(const struct extent_buffer *eb, int nr) |
| 414 | { |
| 415 | return offsetof(struct btrfs_node, ptrs) + |
| 416 | sizeof(struct btrfs_key_ptr) * nr; |
| 417 | } |
| 418 | |
| 419 | void btrfs_node_key(const struct extent_buffer *eb, |
| 420 | struct btrfs_disk_key *disk_key, int nr); |
| 421 | |
| 422 | static inline void btrfs_set_node_key(const struct extent_buffer *eb, |
| 423 | const struct btrfs_disk_key *disk_key, int nr) |
| 424 | { |
| 425 | unsigned long ptr; |
| 426 | |
| 427 | ptr = btrfs_node_key_ptr_offset(eb, nr); |
| 428 | write_eb_member(eb, (struct btrfs_key_ptr *)ptr, |
| 429 | struct btrfs_key_ptr, key, disk_key); |
| 430 | } |
| 431 | |
| 432 | /* struct btrfs_item */ |
| 433 | BTRFS_SETGET_FUNCS(raw_item_offset, struct btrfs_item, offset, 32); |
| 434 | BTRFS_SETGET_FUNCS(raw_item_size, struct btrfs_item, size, 32); |
| 435 | BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32); |
| 436 | BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32); |
| 437 | |
| 438 | static inline unsigned long btrfs_item_nr_offset(const struct extent_buffer *eb, int nr) |
| 439 | { |
| 440 | return offsetof(struct btrfs_leaf, items) + |
| 441 | sizeof(struct btrfs_item) * nr; |
| 442 | } |
| 443 | |
| 444 | static inline struct btrfs_item *btrfs_item_nr(const struct extent_buffer *eb, int nr) |
| 445 | { |
| 446 | return (struct btrfs_item *)btrfs_item_nr_offset(eb, nr); |
| 447 | } |
| 448 | |
| 449 | #define BTRFS_ITEM_SETGET_FUNCS(member) \ |
| 450 | static inline u32 btrfs_item_##member(const struct extent_buffer *eb, int slot) \ |
| 451 | { \ |
| 452 | return btrfs_raw_item_##member(eb, btrfs_item_nr(eb, slot)); \ |
| 453 | } \ |
| 454 | static inline void btrfs_set_item_##member(const struct extent_buffer *eb, \ |
| 455 | int slot, u32 val) \ |
| 456 | { \ |
| 457 | btrfs_set_raw_item_##member(eb, btrfs_item_nr(eb, slot), val); \ |
| 458 | } |
| 459 | |
| 460 | BTRFS_ITEM_SETGET_FUNCS(offset) |
| 461 | BTRFS_ITEM_SETGET_FUNCS(size); |
| 462 | |
| 463 | static inline u32 btrfs_item_data_end(const struct extent_buffer *eb, int nr) |
| 464 | { |
| 465 | return btrfs_item_offset(eb, slot: nr) + btrfs_item_size(eb, slot: nr); |
| 466 | } |
| 467 | |
| 468 | static inline void btrfs_item_key(const struct extent_buffer *eb, |
| 469 | struct btrfs_disk_key *disk_key, int nr) |
| 470 | { |
| 471 | struct btrfs_item *item = btrfs_item_nr(eb, nr); |
| 472 | |
| 473 | read_eb_member(eb, item, struct btrfs_item, key, disk_key); |
| 474 | } |
| 475 | |
| 476 | static inline void btrfs_set_item_key(struct extent_buffer *eb, |
| 477 | const struct btrfs_disk_key *disk_key, int nr) |
| 478 | { |
| 479 | struct btrfs_item *item = btrfs_item_nr(eb, nr); |
| 480 | |
| 481 | write_eb_member(eb, item, struct btrfs_item, key, disk_key); |
| 482 | } |
| 483 | |
| 484 | BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64); |
| 485 | |
| 486 | /* struct btrfs_root_ref */ |
| 487 | BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64); |
| 488 | BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64); |
| 489 | BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16); |
| 490 | BTRFS_SETGET_STACK_FUNCS(stack_root_ref_dirid, struct btrfs_root_ref, dirid, 64); |
| 491 | BTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence, struct btrfs_root_ref, sequence, 64); |
| 492 | BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_len, 16); |
| 493 | |
| 494 | /* struct btrfs_dir_item */ |
| 495 | BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); |
| 496 | BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, type, 8); |
| 497 | BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); |
| 498 | BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64); |
| 499 | BTRFS_SETGET_STACK_FUNCS(stack_dir_flags, struct btrfs_dir_item, type, 8); |
| 500 | BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, data_len, 16); |
| 501 | BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16); |
| 502 | BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, transid, 64); |
| 503 | |
| 504 | static inline u8 btrfs_dir_ftype(const struct extent_buffer *eb, |
| 505 | const struct btrfs_dir_item *item) |
| 506 | { |
| 507 | return btrfs_dir_flags_to_ftype(flags: btrfs_dir_flags(eb, s: item)); |
| 508 | } |
| 509 | |
| 510 | static inline u8 btrfs_stack_dir_ftype(const struct btrfs_dir_item *item) |
| 511 | { |
| 512 | return btrfs_dir_flags_to_ftype(flags: btrfs_stack_dir_flags(s: item)); |
| 513 | } |
| 514 | |
| 515 | static inline void btrfs_dir_item_key(const struct extent_buffer *eb, |
| 516 | const struct btrfs_dir_item *item, |
| 517 | struct btrfs_disk_key *key) |
| 518 | { |
| 519 | read_eb_member(eb, item, struct btrfs_dir_item, location, key); |
| 520 | } |
| 521 | |
| 522 | static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, |
| 523 | struct btrfs_dir_item *item, |
| 524 | const struct btrfs_disk_key *key) |
| 525 | { |
| 526 | write_eb_member(eb, item, struct btrfs_dir_item, location, key); |
| 527 | } |
| 528 | |
| 529 | BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header, |
| 530 | num_entries, 64); |
| 531 | BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header, |
| 532 | num_bitmaps, 64); |
| 533 | BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, |
| 534 | generation, 64); |
| 535 | |
| 536 | static inline void btrfs_free_space_key(const struct extent_buffer *eb, |
| 537 | const struct btrfs_free_space_header *h, |
| 538 | struct btrfs_disk_key *key) |
| 539 | { |
| 540 | read_eb_member(eb, h, struct btrfs_free_space_header, location, key); |
| 541 | } |
| 542 | |
| 543 | static inline void btrfs_set_free_space_key(struct extent_buffer *eb, |
| 544 | struct btrfs_free_space_header *h, |
| 545 | const struct btrfs_disk_key *key) |
| 546 | { |
| 547 | write_eb_member(eb, h, struct btrfs_free_space_header, location, key); |
| 548 | } |
| 549 | |
| 550 | /* struct btrfs_disk_key */ |
| 551 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, objectid, 64); |
| 552 | BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); |
| 553 | BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); |
| 554 | |
| 555 | #ifdef __LITTLE_ENDIAN |
| 556 | |
| 557 | /* |
| 558 | * Optimized helpers for little-endian architectures where CPU and on-disk |
| 559 | * structures have the same endianness and we can skip conversions. |
| 560 | */ |
| 561 | |
| 562 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key, |
| 563 | const struct btrfs_disk_key *disk_key) |
| 564 | { |
| 565 | memcpy(cpu_key, disk_key, sizeof(struct btrfs_key)); |
| 566 | } |
| 567 | |
| 568 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key, |
| 569 | const struct btrfs_key *cpu_key) |
| 570 | { |
| 571 | memcpy(disk_key, cpu_key, sizeof(struct btrfs_key)); |
| 572 | } |
| 573 | |
| 574 | static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, |
| 575 | struct btrfs_key *cpu_key, int nr) |
| 576 | { |
| 577 | struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; |
| 578 | |
| 579 | btrfs_node_key(eb, disk_key, nr); |
| 580 | } |
| 581 | |
| 582 | static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, |
| 583 | struct btrfs_key *cpu_key, int nr) |
| 584 | { |
| 585 | struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; |
| 586 | |
| 587 | btrfs_item_key(eb, disk_key, nr); |
| 588 | } |
| 589 | |
| 590 | static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, |
| 591 | const struct btrfs_dir_item *item, |
| 592 | struct btrfs_key *cpu_key) |
| 593 | { |
| 594 | struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; |
| 595 | |
| 596 | btrfs_dir_item_key(eb, item, key: disk_key); |
| 597 | } |
| 598 | |
| 599 | #else |
| 600 | |
| 601 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
| 602 | const struct btrfs_disk_key *disk) |
| 603 | { |
| 604 | cpu->offset = le64_to_cpu(disk->offset); |
| 605 | cpu->type = disk->type; |
| 606 | cpu->objectid = le64_to_cpu(disk->objectid); |
| 607 | } |
| 608 | |
| 609 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, |
| 610 | const struct btrfs_key *cpu) |
| 611 | { |
| 612 | disk->offset = cpu_to_le64(cpu->offset); |
| 613 | disk->type = cpu->type; |
| 614 | disk->objectid = cpu_to_le64(cpu->objectid); |
| 615 | } |
| 616 | |
| 617 | static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, |
| 618 | struct btrfs_key *key, int nr) |
| 619 | { |
| 620 | struct btrfs_disk_key disk_key; |
| 621 | |
| 622 | btrfs_node_key(eb, &disk_key, nr); |
| 623 | btrfs_disk_key_to_cpu(key, &disk_key); |
| 624 | } |
| 625 | |
| 626 | static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, |
| 627 | struct btrfs_key *key, int nr) |
| 628 | { |
| 629 | struct btrfs_disk_key disk_key; |
| 630 | |
| 631 | btrfs_item_key(eb, &disk_key, nr); |
| 632 | btrfs_disk_key_to_cpu(key, &disk_key); |
| 633 | } |
| 634 | |
| 635 | static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, |
| 636 | const struct btrfs_dir_item *item, |
| 637 | struct btrfs_key *key) |
| 638 | { |
| 639 | struct btrfs_disk_key disk_key; |
| 640 | |
| 641 | btrfs_dir_item_key(eb, item, &disk_key); |
| 642 | btrfs_disk_key_to_cpu(key, &disk_key); |
| 643 | } |
| 644 | |
| 645 | #endif |
| 646 | |
| 647 | /* struct btrfs_header */ |
| 648 | BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); |
| 649 | BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, generation, 64); |
| 650 | BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); |
| 651 | BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); |
| 652 | BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); |
| 653 | BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); |
| 654 | BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, |
| 655 | generation, 64); |
| 656 | BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); |
| 657 | BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, nritems, 32); |
| 658 | BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); |
| 659 | |
| 660 | static inline int (const struct extent_buffer *eb, u64 flag) |
| 661 | { |
| 662 | return (btrfs_header_flags(eb) & flag) == flag; |
| 663 | } |
| 664 | |
| 665 | static inline void (struct extent_buffer *eb, u64 flag) |
| 666 | { |
| 667 | u64 flags = btrfs_header_flags(eb); |
| 668 | |
| 669 | btrfs_set_header_flags(eb, val: flags | flag); |
| 670 | } |
| 671 | |
| 672 | static inline void (struct extent_buffer *eb, u64 flag) |
| 673 | { |
| 674 | u64 flags = btrfs_header_flags(eb); |
| 675 | |
| 676 | btrfs_set_header_flags(eb, val: flags & ~flag); |
| 677 | } |
| 678 | |
| 679 | static inline int (const struct extent_buffer *eb) |
| 680 | { |
| 681 | u64 flags = btrfs_header_flags(eb); |
| 682 | |
| 683 | return flags >> BTRFS_BACKREF_REV_SHIFT; |
| 684 | } |
| 685 | |
| 686 | static inline void (struct extent_buffer *eb, int rev) |
| 687 | { |
| 688 | u64 flags = btrfs_header_flags(eb); |
| 689 | |
| 690 | flags &= ~BTRFS_BACKREF_REV_MASK; |
| 691 | flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT; |
| 692 | btrfs_set_header_flags(eb, val: flags); |
| 693 | } |
| 694 | |
| 695 | static inline int btrfs_is_leaf(const struct extent_buffer *eb) |
| 696 | { |
| 697 | return btrfs_header_level(eb) == 0; |
| 698 | } |
| 699 | |
| 700 | /* struct btrfs_root_item */ |
| 701 | BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item, generation, 64); |
| 702 | BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); |
| 703 | BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); |
| 704 | BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); |
| 705 | |
| 706 | BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item, generation, 64); |
| 707 | BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); |
| 708 | BTRFS_SETGET_STACK_FUNCS(root_drop_level, struct btrfs_root_item, drop_level, 8); |
| 709 | BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); |
| 710 | BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); |
| 711 | BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); |
| 712 | BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64); |
| 713 | BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); |
| 714 | BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); |
| 715 | BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item, |
| 716 | last_snapshot, 64); |
| 717 | BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item, |
| 718 | generation_v2, 64); |
| 719 | BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item, ctransid, 64); |
| 720 | BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item, otransid, 64); |
| 721 | BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item, stransid, 64); |
| 722 | BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, rtransid, 64); |
| 723 | |
| 724 | /* struct btrfs_root_backup */ |
| 725 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup, |
| 726 | tree_root, 64); |
| 727 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup, |
| 728 | tree_root_gen, 64); |
| 729 | BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup, |
| 730 | tree_root_level, 8); |
| 731 | |
| 732 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup, |
| 733 | chunk_root, 64); |
| 734 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup, |
| 735 | chunk_root_gen, 64); |
| 736 | BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup, |
| 737 | chunk_root_level, 8); |
| 738 | |
| 739 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup, |
| 740 | extent_root, 64); |
| 741 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup, |
| 742 | extent_root_gen, 64); |
| 743 | BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup, |
| 744 | extent_root_level, 8); |
| 745 | |
| 746 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup, |
| 747 | fs_root, 64); |
| 748 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup, |
| 749 | fs_root_gen, 64); |
| 750 | BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup, |
| 751 | fs_root_level, 8); |
| 752 | |
| 753 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup, |
| 754 | dev_root, 64); |
| 755 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup, |
| 756 | dev_root_gen, 64); |
| 757 | BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup, |
| 758 | dev_root_level, 8); |
| 759 | |
| 760 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup, |
| 761 | csum_root, 64); |
| 762 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup, |
| 763 | csum_root_gen, 64); |
| 764 | BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup, |
| 765 | csum_root_level, 8); |
| 766 | BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup, |
| 767 | total_bytes, 64); |
| 768 | BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup, |
| 769 | bytes_used, 64); |
| 770 | BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup, |
| 771 | num_devices, 64); |
| 772 | |
| 773 | /* struct btrfs_balance_item */ |
| 774 | BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64); |
| 775 | |
| 776 | static inline void btrfs_balance_data(const struct extent_buffer *eb, |
| 777 | const struct btrfs_balance_item *bi, |
| 778 | struct btrfs_disk_balance_args *ba) |
| 779 | { |
| 780 | read_eb_member(eb, bi, struct btrfs_balance_item, data, ba); |
| 781 | } |
| 782 | |
| 783 | static inline void btrfs_set_balance_data(struct extent_buffer *eb, |
| 784 | struct btrfs_balance_item *bi, |
| 785 | const struct btrfs_disk_balance_args *ba) |
| 786 | { |
| 787 | write_eb_member(eb, bi, struct btrfs_balance_item, data, ba); |
| 788 | } |
| 789 | |
| 790 | static inline void btrfs_balance_meta(const struct extent_buffer *eb, |
| 791 | const struct btrfs_balance_item *bi, |
| 792 | struct btrfs_disk_balance_args *ba) |
| 793 | { |
| 794 | read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); |
| 795 | } |
| 796 | |
| 797 | static inline void btrfs_set_balance_meta(struct extent_buffer *eb, |
| 798 | struct btrfs_balance_item *bi, |
| 799 | const struct btrfs_disk_balance_args *ba) |
| 800 | { |
| 801 | write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); |
| 802 | } |
| 803 | |
| 804 | static inline void btrfs_balance_sys(const struct extent_buffer *eb, |
| 805 | const struct btrfs_balance_item *bi, |
| 806 | struct btrfs_disk_balance_args *ba) |
| 807 | { |
| 808 | read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); |
| 809 | } |
| 810 | |
| 811 | static inline void btrfs_set_balance_sys(struct extent_buffer *eb, |
| 812 | struct btrfs_balance_item *bi, |
| 813 | const struct btrfs_disk_balance_args *ba) |
| 814 | { |
| 815 | write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); |
| 816 | } |
| 817 | |
| 818 | /* struct btrfs_super_block */ |
| 819 | BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); |
| 820 | BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64); |
| 821 | BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, |
| 822 | generation, 64); |
| 823 | BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); |
| 824 | BTRFS_SETGET_STACK_FUNCS(super_sys_array_size, |
| 825 | struct btrfs_super_block, sys_chunk_array_size, 32); |
| 826 | BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation, |
| 827 | struct btrfs_super_block, chunk_root_generation, 64); |
| 828 | BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, |
| 829 | root_level, 8); |
| 830 | BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block, |
| 831 | chunk_root, 64); |
| 832 | BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block, |
| 833 | chunk_root_level, 8); |
| 834 | BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, log_root, 64); |
| 835 | BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block, |
| 836 | log_root_level, 8); |
| 837 | BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, |
| 838 | total_bytes, 64); |
| 839 | BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, |
| 840 | bytes_used, 64); |
| 841 | BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, |
| 842 | sectorsize, 32); |
| 843 | BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, |
| 844 | nodesize, 32); |
| 845 | BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, |
| 846 | stripesize, 32); |
| 847 | BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, |
| 848 | root_dir_objectid, 64); |
| 849 | BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, |
| 850 | num_devices, 64); |
| 851 | BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, |
| 852 | compat_flags, 64); |
| 853 | BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, |
| 854 | compat_ro_flags, 64); |
| 855 | BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, |
| 856 | incompat_flags, 64); |
| 857 | BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, |
| 858 | csum_type, 16); |
| 859 | BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, |
| 860 | cache_generation, 64); |
| 861 | BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64); |
| 862 | BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, |
| 863 | uuid_tree_generation, 64); |
| 864 | BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block, |
| 865 | nr_global_roots, 64); |
| 866 | |
| 867 | /* struct btrfs_file_extent_item */ |
| 868 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, |
| 869 | type, 8); |
| 870 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, |
| 871 | struct btrfs_file_extent_item, disk_bytenr, 64); |
| 872 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset, |
| 873 | struct btrfs_file_extent_item, offset, 64); |
| 874 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation, |
| 875 | struct btrfs_file_extent_item, generation, 64); |
| 876 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes, |
| 877 | struct btrfs_file_extent_item, num_bytes, 64); |
| 878 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes, |
| 879 | struct btrfs_file_extent_item, ram_bytes, 64); |
| 880 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes, |
| 881 | struct btrfs_file_extent_item, disk_num_bytes, 64); |
| 882 | BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, |
| 883 | struct btrfs_file_extent_item, compression, 8); |
| 884 | |
| 885 | |
| 886 | BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); |
| 887 | BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, |
| 888 | disk_bytenr, 64); |
| 889 | BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, |
| 890 | generation, 64); |
| 891 | BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, |
| 892 | disk_num_bytes, 64); |
| 893 | BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, |
| 894 | offset, 64); |
| 895 | BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, |
| 896 | num_bytes, 64); |
| 897 | BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item, |
| 898 | ram_bytes, 64); |
| 899 | BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item, |
| 900 | compression, 8); |
| 901 | BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, |
| 902 | encryption, 8); |
| 903 | BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, |
| 904 | other_encoding, 16); |
| 905 | |
| 906 | /* btrfs_qgroup_status_item */ |
| 907 | BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, |
| 908 | generation, 64); |
| 909 | BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, |
| 910 | version, 64); |
| 911 | BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item, |
| 912 | flags, 64); |
| 913 | BTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item, |
| 914 | rescan, 64); |
| 915 | BTRFS_SETGET_FUNCS(qgroup_status_enable_gen, struct btrfs_qgroup_status_item, |
| 916 | enable_gen, 64); |
| 917 | |
| 918 | /* btrfs_qgroup_info_item */ |
| 919 | BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item, |
| 920 | generation, 64); |
| 921 | BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64); |
| 922 | BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item, |
| 923 | rfer_cmpr, 64); |
| 924 | BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64); |
| 925 | BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item, |
| 926 | excl_cmpr, 64); |
| 927 | |
| 928 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation, |
| 929 | struct btrfs_qgroup_info_item, generation, 64); |
| 930 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item, |
| 931 | rfer, 64); |
| 932 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr, |
| 933 | struct btrfs_qgroup_info_item, rfer_cmpr, 64); |
| 934 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item, |
| 935 | excl, 64); |
| 936 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr, |
| 937 | struct btrfs_qgroup_info_item, excl_cmpr, 64); |
| 938 | |
| 939 | /* btrfs_qgroup_limit_item */ |
| 940 | BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, flags, 64); |
| 941 | BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item, |
| 942 | max_rfer, 64); |
| 943 | BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item, |
| 944 | max_excl, 64); |
| 945 | BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item, |
| 946 | rsv_rfer, 64); |
| 947 | BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item, |
| 948 | rsv_excl, 64); |
| 949 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_flags, |
| 950 | struct btrfs_qgroup_limit_item, flags, 64); |
| 951 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_rfer, |
| 952 | struct btrfs_qgroup_limit_item, max_rfer, 64); |
| 953 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_excl, |
| 954 | struct btrfs_qgroup_limit_item, max_excl, 64); |
| 955 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_rfer, |
| 956 | struct btrfs_qgroup_limit_item, rsv_rfer, 64); |
| 957 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_excl, |
| 958 | struct btrfs_qgroup_limit_item, rsv_excl, 64); |
| 959 | |
| 960 | /* btrfs_dev_replace_item */ |
| 961 | BTRFS_SETGET_FUNCS(dev_replace_src_devid, |
| 962 | struct btrfs_dev_replace_item, src_devid, 64); |
| 963 | BTRFS_SETGET_FUNCS(dev_replace_cont_reading_from_srcdev_mode, |
| 964 | struct btrfs_dev_replace_item, cont_reading_from_srcdev_mode, |
| 965 | 64); |
| 966 | BTRFS_SETGET_FUNCS(dev_replace_replace_state, struct btrfs_dev_replace_item, |
| 967 | replace_state, 64); |
| 968 | BTRFS_SETGET_FUNCS(dev_replace_time_started, struct btrfs_dev_replace_item, |
| 969 | time_started, 64); |
| 970 | BTRFS_SETGET_FUNCS(dev_replace_time_stopped, struct btrfs_dev_replace_item, |
| 971 | time_stopped, 64); |
| 972 | BTRFS_SETGET_FUNCS(dev_replace_num_write_errors, struct btrfs_dev_replace_item, |
| 973 | num_write_errors, 64); |
| 974 | BTRFS_SETGET_FUNCS(dev_replace_num_uncorrectable_read_errors, |
| 975 | struct btrfs_dev_replace_item, num_uncorrectable_read_errors, |
| 976 | 64); |
| 977 | BTRFS_SETGET_FUNCS(dev_replace_cursor_left, struct btrfs_dev_replace_item, |
| 978 | cursor_left, 64); |
| 979 | BTRFS_SETGET_FUNCS(dev_replace_cursor_right, struct btrfs_dev_replace_item, |
| 980 | cursor_right, 64); |
| 981 | |
| 982 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_src_devid, |
| 983 | struct btrfs_dev_replace_item, src_devid, 64); |
| 984 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cont_reading_from_srcdev_mode, |
| 985 | struct btrfs_dev_replace_item, |
| 986 | cont_reading_from_srcdev_mode, 64); |
| 987 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_replace_state, |
| 988 | struct btrfs_dev_replace_item, replace_state, 64); |
| 989 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_started, |
| 990 | struct btrfs_dev_replace_item, time_started, 64); |
| 991 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_stopped, |
| 992 | struct btrfs_dev_replace_item, time_stopped, 64); |
| 993 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_write_errors, |
| 994 | struct btrfs_dev_replace_item, num_write_errors, 64); |
| 995 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_uncorrectable_read_errors, |
| 996 | struct btrfs_dev_replace_item, |
| 997 | num_uncorrectable_read_errors, 64); |
| 998 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left, |
| 999 | struct btrfs_dev_replace_item, cursor_left, 64); |
| 1000 | BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right, |
| 1001 | struct btrfs_dev_replace_item, cursor_right, 64); |
| 1002 | |
| 1003 | /* btrfs_verity_descriptor_item */ |
| 1004 | BTRFS_SETGET_FUNCS(verity_descriptor_encryption, struct btrfs_verity_descriptor_item, |
| 1005 | encryption, 8); |
| 1006 | BTRFS_SETGET_FUNCS(verity_descriptor_size, struct btrfs_verity_descriptor_item, |
| 1007 | size, 64); |
| 1008 | BTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_encryption, |
| 1009 | struct btrfs_verity_descriptor_item, encryption, 8); |
| 1010 | BTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_size, |
| 1011 | struct btrfs_verity_descriptor_item, size, 64); |
| 1012 | |
| 1013 | /* Cast into the data area of the leaf. */ |
| 1014 | #define btrfs_item_ptr(leaf, slot, type) \ |
| 1015 | ((type *)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot))) |
| 1016 | |
| 1017 | #define btrfs_item_ptr_offset(leaf, slot) \ |
| 1018 | ((unsigned long)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot))) |
| 1019 | |
| 1020 | #endif |
| 1021 | |