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