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