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