1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef BTRFS_ACCESSORS_H 4 #define BTRFS_ACCESSORS_H 5 6 struct btrfs_map_token { 7 struct extent_buffer *eb; 8 char *kaddr; 9 unsigned long offset; 10 }; 11 12 void btrfs_init_map_token(struct btrfs_map_token *token, struct extent_buffer *eb); 13 14 /* 15 * Some macros to generate set/get functions for the struct fields. This 16 * assumes there is a lefoo_to_cpu for every type, so lets make a simple one 17 * for u8: 18 */ 19 #define le8_to_cpu(v) (v) 20 #define cpu_to_le8(v) (v) 21 #define __le8 u8 22 23 static inline u8 get_unaligned_le8(const void *p) 24 { 25 return *(u8 *)p; 26 } 27 28 static inline void put_unaligned_le8(u8 val, void *p) 29 { 30 *(u8 *)p = val; 31 } 32 33 #define read_eb_member(eb, ptr, type, member, result) (\ 34 read_extent_buffer(eb, (char *)(result), \ 35 ((unsigned long)(ptr)) + \ 36 offsetof(type, member), \ 37 sizeof(((type *)0)->member))) 38 39 #define write_eb_member(eb, ptr, type, member, result) (\ 40 write_extent_buffer(eb, (char *)(result), \ 41 ((unsigned long)(ptr)) + \ 42 offsetof(type, member), \ 43 sizeof(((type *)0)->member))) 44 45 #define DECLARE_BTRFS_SETGET_BITS(bits) \ 46 u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \ 47 const void *ptr, unsigned long off); \ 48 void btrfs_set_token_##bits(struct btrfs_map_token *token, \ 49 const void *ptr, unsigned long off, \ 50 u##bits val); \ 51 u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ 52 const void *ptr, unsigned long off); \ 53 void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \ 54 unsigned long off, u##bits val); 55 56 DECLARE_BTRFS_SETGET_BITS(8) 57 DECLARE_BTRFS_SETGET_BITS(16) 58 DECLARE_BTRFS_SETGET_BITS(32) 59 DECLARE_BTRFS_SETGET_BITS(64) 60 61 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \ 62 static inline u##bits btrfs_##name(const struct extent_buffer *eb, \ 63 const type *s) \ 64 { \ 65 static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ 66 return btrfs_get_##bits(eb, s, offsetof(type, member)); \ 67 } \ 68 static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \ 69 u##bits val) \ 70 { \ 71 static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ 72 btrfs_set_##bits(eb, s, offsetof(type, member), val); \ 73 } \ 74 static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \ 75 const type *s) \ 76 { \ 77 static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ 78 return btrfs_get_token_##bits(token, s, offsetof(type, member));\ 79 } \ 80 static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\ 81 type *s, u##bits val) \ 82 { \ 83 static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ 84 btrfs_set_token_##bits(token, s, offsetof(type, member), val); \ 85 } 86 87 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ 88 static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ 89 { \ 90 const type *p = page_address(eb->pages[0]) + \ 91 offset_in_page(eb->start); \ 92 return get_unaligned_le##bits(&p->member); \ 93 } \ 94 static inline void btrfs_set_##name(const struct extent_buffer *eb, \ 95 u##bits val) \ 96 { \ 97 type *p = page_address(eb->pages[0]) + offset_in_page(eb->start); \ 98 put_unaligned_le##bits(val, &p->member); \ 99 } 100 101 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ 102 static inline u##bits btrfs_##name(const type *s) \ 103 { \ 104 return get_unaligned_le##bits(&s->member); \ 105 } \ 106 static inline void btrfs_set_##name(type *s, u##bits val) \ 107 { \ 108 put_unaligned_le##bits(val, &s->member); \ 109 } 110 111 static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb, 112 struct btrfs_dev_item *s) 113 { 114 static_assert(sizeof(u64) == 115 sizeof(((struct btrfs_dev_item *)0))->total_bytes); 116 return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item, 117 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) == 124 sizeof(((struct btrfs_dev_item *)0))->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 /* struct btrfs_dev_extent */ 310 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, chunk_tree, 64); 311 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent, 312 chunk_objectid, 64); 313 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent, 314 chunk_offset, 64); 315 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); 316 BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_tree, struct btrfs_dev_extent, 317 chunk_tree, 64); 318 BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_objectid, struct btrfs_dev_extent, 319 chunk_objectid, 64); 320 BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_offset, struct btrfs_dev_extent, 321 chunk_offset, 64); 322 BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_length, struct btrfs_dev_extent, length, 64); 323 324 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); 325 BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, generation, 64); 326 BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64); 327 328 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8); 329 330 static inline void btrfs_tree_block_key(const struct extent_buffer *eb, 331 struct btrfs_tree_block_info *item, 332 struct btrfs_disk_key *key) 333 { 334 read_eb_member(eb, item, struct btrfs_tree_block_info, key, key); 335 } 336 337 static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb, 338 struct btrfs_tree_block_info *item, 339 struct btrfs_disk_key *key) 340 { 341 write_eb_member(eb, item, struct btrfs_tree_block_info, key, key); 342 } 343 344 BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref, root, 64); 345 BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref, 346 objectid, 64); 347 BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref, 348 offset, 64); 349 BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref, count, 32); 350 351 BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref, count, 32); 352 353 BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref, 354 type, 8); 355 BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref, 356 offset, 64); 357 358 static inline u32 btrfs_extent_inline_ref_size(int type) 359 { 360 if (type == BTRFS_TREE_BLOCK_REF_KEY || 361 type == BTRFS_SHARED_BLOCK_REF_KEY) 362 return sizeof(struct btrfs_extent_inline_ref); 363 if (type == BTRFS_SHARED_DATA_REF_KEY) 364 return sizeof(struct btrfs_shared_data_ref) + 365 sizeof(struct btrfs_extent_inline_ref); 366 if (type == BTRFS_EXTENT_DATA_REF_KEY) 367 return sizeof(struct btrfs_extent_data_ref) + 368 offsetof(struct btrfs_extent_inline_ref, offset); 369 return 0; 370 } 371 372 /* struct btrfs_node */ 373 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); 374 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); 375 BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr, blockptr, 64); 376 BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr, 377 generation, 64); 378 379 static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr) 380 { 381 unsigned long ptr; 382 383 ptr = offsetof(struct btrfs_node, ptrs) + 384 sizeof(struct btrfs_key_ptr) * nr; 385 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); 386 } 387 388 static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb, 389 int nr, u64 val) 390 { 391 unsigned long ptr; 392 393 ptr = offsetof(struct btrfs_node, ptrs) + 394 sizeof(struct btrfs_key_ptr) * nr; 395 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); 396 } 397 398 static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr) 399 { 400 unsigned long ptr; 401 402 ptr = offsetof(struct btrfs_node, ptrs) + 403 sizeof(struct btrfs_key_ptr) * nr; 404 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); 405 } 406 407 static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb, 408 int nr, u64 val) 409 { 410 unsigned long ptr; 411 412 ptr = offsetof(struct btrfs_node, ptrs) + 413 sizeof(struct btrfs_key_ptr) * nr; 414 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val); 415 } 416 417 static inline unsigned long btrfs_node_key_ptr_offset(const struct extent_buffer *eb, int nr) 418 { 419 return offsetof(struct btrfs_node, ptrs) + 420 sizeof(struct btrfs_key_ptr) * nr; 421 } 422 423 void btrfs_node_key(const struct extent_buffer *eb, 424 struct btrfs_disk_key *disk_key, int nr); 425 426 static inline void btrfs_set_node_key(const struct extent_buffer *eb, 427 struct btrfs_disk_key *disk_key, int nr) 428 { 429 unsigned long ptr; 430 431 ptr = btrfs_node_key_ptr_offset(eb, nr); 432 write_eb_member(eb, (struct btrfs_key_ptr *)ptr, 433 struct btrfs_key_ptr, key, disk_key); 434 } 435 436 /* struct btrfs_item */ 437 BTRFS_SETGET_FUNCS(raw_item_offset, struct btrfs_item, offset, 32); 438 BTRFS_SETGET_FUNCS(raw_item_size, struct btrfs_item, size, 32); 439 BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32); 440 BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32); 441 442 static inline unsigned long btrfs_item_nr_offset(const struct extent_buffer *eb, int nr) 443 { 444 return offsetof(struct btrfs_leaf, items) + 445 sizeof(struct btrfs_item) * nr; 446 } 447 448 static inline struct btrfs_item *btrfs_item_nr(const struct extent_buffer *eb, int nr) 449 { 450 return (struct btrfs_item *)btrfs_item_nr_offset(eb, nr); 451 } 452 453 #define BTRFS_ITEM_SETGET_FUNCS(member) \ 454 static inline u32 btrfs_item_##member(const struct extent_buffer *eb, int slot) \ 455 { \ 456 return btrfs_raw_item_##member(eb, btrfs_item_nr(eb, slot)); \ 457 } \ 458 static inline void btrfs_set_item_##member(const struct extent_buffer *eb, \ 459 int slot, u32 val) \ 460 { \ 461 btrfs_set_raw_item_##member(eb, btrfs_item_nr(eb, slot), val); \ 462 } \ 463 static inline u32 btrfs_token_item_##member(struct btrfs_map_token *token, \ 464 int slot) \ 465 { \ 466 struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \ 467 return btrfs_token_raw_item_##member(token, item); \ 468 } \ 469 static inline void btrfs_set_token_item_##member(struct btrfs_map_token *token, \ 470 int slot, u32 val) \ 471 { \ 472 struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \ 473 btrfs_set_token_raw_item_##member(token, item, val); \ 474 } 475 476 BTRFS_ITEM_SETGET_FUNCS(offset) 477 BTRFS_ITEM_SETGET_FUNCS(size); 478 479 static inline u32 btrfs_item_data_end(const struct extent_buffer *eb, int nr) 480 { 481 return btrfs_item_offset(eb, nr) + btrfs_item_size(eb, nr); 482 } 483 484 static inline void btrfs_item_key(const struct extent_buffer *eb, 485 struct btrfs_disk_key *disk_key, int nr) 486 { 487 struct btrfs_item *item = btrfs_item_nr(eb, nr); 488 489 read_eb_member(eb, item, struct btrfs_item, key, disk_key); 490 } 491 492 static inline void btrfs_set_item_key(struct extent_buffer *eb, 493 struct btrfs_disk_key *disk_key, int nr) 494 { 495 struct btrfs_item *item = btrfs_item_nr(eb, nr); 496 497 write_eb_member(eb, item, struct btrfs_item, key, disk_key); 498 } 499 500 BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64); 501 502 /* struct btrfs_root_ref */ 503 BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64); 504 BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64); 505 BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16); 506 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_dirid, struct btrfs_root_ref, dirid, 64); 507 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence, struct btrfs_root_ref, sequence, 64); 508 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_len, 16); 509 510 /* struct btrfs_dir_item */ 511 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); 512 BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, type, 8); 513 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); 514 BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64); 515 BTRFS_SETGET_STACK_FUNCS(stack_dir_flags, struct btrfs_dir_item, type, 8); 516 BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, data_len, 16); 517 BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16); 518 BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, transid, 64); 519 520 static inline u8 btrfs_dir_ftype(const struct extent_buffer *eb, 521 const struct btrfs_dir_item *item) 522 { 523 return btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, item)); 524 } 525 526 static inline u8 btrfs_stack_dir_ftype(const struct btrfs_dir_item *item) 527 { 528 return btrfs_dir_flags_to_ftype(btrfs_stack_dir_flags(item)); 529 } 530 531 static inline void btrfs_dir_item_key(const struct extent_buffer *eb, 532 const struct btrfs_dir_item *item, 533 struct btrfs_disk_key *key) 534 { 535 read_eb_member(eb, item, struct btrfs_dir_item, location, key); 536 } 537 538 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, 539 struct btrfs_dir_item *item, 540 const struct btrfs_disk_key *key) 541 { 542 write_eb_member(eb, item, struct btrfs_dir_item, location, key); 543 } 544 545 BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header, 546 num_entries, 64); 547 BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header, 548 num_bitmaps, 64); 549 BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, 550 generation, 64); 551 552 static inline void btrfs_free_space_key(const struct extent_buffer *eb, 553 const struct btrfs_free_space_header *h, 554 struct btrfs_disk_key *key) 555 { 556 read_eb_member(eb, h, struct btrfs_free_space_header, location, key); 557 } 558 559 static inline void btrfs_set_free_space_key(struct extent_buffer *eb, 560 struct btrfs_free_space_header *h, 561 const struct btrfs_disk_key *key) 562 { 563 write_eb_member(eb, h, struct btrfs_free_space_header, location, key); 564 } 565 566 /* struct btrfs_disk_key */ 567 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, objectid, 64); 568 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); 569 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); 570 571 #ifdef __LITTLE_ENDIAN 572 573 /* 574 * Optimized helpers for little-endian architectures where CPU and on-disk 575 * structures have the same endianness and we can skip conversions. 576 */ 577 578 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key, 579 const struct btrfs_disk_key *disk_key) 580 { 581 memcpy(cpu_key, disk_key, sizeof(struct btrfs_key)); 582 } 583 584 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key, 585 const struct btrfs_key *cpu_key) 586 { 587 memcpy(disk_key, cpu_key, sizeof(struct btrfs_key)); 588 } 589 590 static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, 591 struct btrfs_key *cpu_key, int nr) 592 { 593 struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; 594 595 btrfs_node_key(eb, disk_key, nr); 596 } 597 598 static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, 599 struct btrfs_key *cpu_key, int nr) 600 { 601 struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; 602 603 btrfs_item_key(eb, disk_key, nr); 604 } 605 606 static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, 607 const struct btrfs_dir_item *item, 608 struct btrfs_key *cpu_key) 609 { 610 struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; 611 612 btrfs_dir_item_key(eb, item, disk_key); 613 } 614 615 #else 616 617 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, 618 const struct btrfs_disk_key *disk) 619 { 620 cpu->offset = le64_to_cpu(disk->offset); 621 cpu->type = disk->type; 622 cpu->objectid = le64_to_cpu(disk->objectid); 623 } 624 625 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, 626 const struct btrfs_key *cpu) 627 { 628 disk->offset = cpu_to_le64(cpu->offset); 629 disk->type = cpu->type; 630 disk->objectid = cpu_to_le64(cpu->objectid); 631 } 632 633 static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, 634 struct btrfs_key *key, int nr) 635 { 636 struct btrfs_disk_key disk_key; 637 638 btrfs_node_key(eb, &disk_key, nr); 639 btrfs_disk_key_to_cpu(key, &disk_key); 640 } 641 642 static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, 643 struct btrfs_key *key, int nr) 644 { 645 struct btrfs_disk_key disk_key; 646 647 btrfs_item_key(eb, &disk_key, nr); 648 btrfs_disk_key_to_cpu(key, &disk_key); 649 } 650 651 static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, 652 const struct btrfs_dir_item *item, 653 struct btrfs_key *key) 654 { 655 struct btrfs_disk_key disk_key; 656 657 btrfs_dir_item_key(eb, item, &disk_key); 658 btrfs_disk_key_to_cpu(key, &disk_key); 659 } 660 661 #endif 662 663 /* struct btrfs_header */ 664 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); 665 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, generation, 64); 666 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); 667 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); 668 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); 669 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); 670 BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, 671 generation, 64); 672 BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); 673 BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, nritems, 32); 674 BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); 675 676 static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag) 677 { 678 return (btrfs_header_flags(eb) & flag) == flag; 679 } 680 681 static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag) 682 { 683 u64 flags = btrfs_header_flags(eb); 684 685 btrfs_set_header_flags(eb, flags | flag); 686 } 687 688 static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag) 689 { 690 u64 flags = btrfs_header_flags(eb); 691 692 btrfs_set_header_flags(eb, flags & ~flag); 693 } 694 695 static inline int btrfs_header_backref_rev(const struct extent_buffer *eb) 696 { 697 u64 flags = btrfs_header_flags(eb); 698 699 return flags >> BTRFS_BACKREF_REV_SHIFT; 700 } 701 702 static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb, int rev) 703 { 704 u64 flags = btrfs_header_flags(eb); 705 706 flags &= ~BTRFS_BACKREF_REV_MASK; 707 flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT; 708 btrfs_set_header_flags(eb, flags); 709 } 710 711 static inline int btrfs_is_leaf(const struct extent_buffer *eb) 712 { 713 return btrfs_header_level(eb) == 0; 714 } 715 716 /* struct btrfs_root_item */ 717 BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item, generation, 64); 718 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); 719 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); 720 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); 721 722 BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item, generation, 64); 723 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); 724 BTRFS_SETGET_STACK_FUNCS(root_drop_level, struct btrfs_root_item, drop_level, 8); 725 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); 726 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); 727 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); 728 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64); 729 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); 730 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); 731 BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item, 732 last_snapshot, 64); 733 BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item, 734 generation_v2, 64); 735 BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item, ctransid, 64); 736 BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item, otransid, 64); 737 BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item, stransid, 64); 738 BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, rtransid, 64); 739 740 /* struct btrfs_root_backup */ 741 BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup, 742 tree_root, 64); 743 BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup, 744 tree_root_gen, 64); 745 BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup, 746 tree_root_level, 8); 747 748 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup, 749 chunk_root, 64); 750 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup, 751 chunk_root_gen, 64); 752 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup, 753 chunk_root_level, 8); 754 755 BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup, 756 extent_root, 64); 757 BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup, 758 extent_root_gen, 64); 759 BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup, 760 extent_root_level, 8); 761 762 BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup, 763 fs_root, 64); 764 BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup, 765 fs_root_gen, 64); 766 BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup, 767 fs_root_level, 8); 768 769 BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup, 770 dev_root, 64); 771 BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup, 772 dev_root_gen, 64); 773 BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup, 774 dev_root_level, 8); 775 776 BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup, 777 csum_root, 64); 778 BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup, 779 csum_root_gen, 64); 780 BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup, 781 csum_root_level, 8); 782 BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup, 783 total_bytes, 64); 784 BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup, 785 bytes_used, 64); 786 BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup, 787 num_devices, 64); 788 789 /* struct btrfs_balance_item */ 790 BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64); 791 792 static inline void btrfs_balance_data(const struct extent_buffer *eb, 793 const struct btrfs_balance_item *bi, 794 struct btrfs_disk_balance_args *ba) 795 { 796 read_eb_member(eb, bi, struct btrfs_balance_item, data, ba); 797 } 798 799 static inline void btrfs_set_balance_data(struct extent_buffer *eb, 800 struct btrfs_balance_item *bi, 801 const struct btrfs_disk_balance_args *ba) 802 { 803 write_eb_member(eb, bi, struct btrfs_balance_item, data, ba); 804 } 805 806 static inline void btrfs_balance_meta(const struct extent_buffer *eb, 807 const struct btrfs_balance_item *bi, 808 struct btrfs_disk_balance_args *ba) 809 { 810 read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); 811 } 812 813 static inline void btrfs_set_balance_meta(struct extent_buffer *eb, 814 struct btrfs_balance_item *bi, 815 const struct btrfs_disk_balance_args *ba) 816 { 817 write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); 818 } 819 820 static inline void btrfs_balance_sys(const struct extent_buffer *eb, 821 const struct btrfs_balance_item *bi, 822 struct btrfs_disk_balance_args *ba) 823 { 824 read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); 825 } 826 827 static inline void btrfs_set_balance_sys(struct extent_buffer *eb, 828 struct btrfs_balance_item *bi, 829 const struct btrfs_disk_balance_args *ba) 830 { 831 write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); 832 } 833 834 static inline void btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu, 835 const struct btrfs_disk_balance_args *disk) 836 { 837 memset(cpu, 0, sizeof(*cpu)); 838 839 cpu->profiles = le64_to_cpu(disk->profiles); 840 cpu->usage = le64_to_cpu(disk->usage); 841 cpu->devid = le64_to_cpu(disk->devid); 842 cpu->pstart = le64_to_cpu(disk->pstart); 843 cpu->pend = le64_to_cpu(disk->pend); 844 cpu->vstart = le64_to_cpu(disk->vstart); 845 cpu->vend = le64_to_cpu(disk->vend); 846 cpu->target = le64_to_cpu(disk->target); 847 cpu->flags = le64_to_cpu(disk->flags); 848 cpu->limit = le64_to_cpu(disk->limit); 849 cpu->stripes_min = le32_to_cpu(disk->stripes_min); 850 cpu->stripes_max = le32_to_cpu(disk->stripes_max); 851 } 852 853 static inline void btrfs_cpu_balance_args_to_disk( 854 struct btrfs_disk_balance_args *disk, 855 const struct btrfs_balance_args *cpu) 856 { 857 memset(disk, 0, sizeof(*disk)); 858 859 disk->profiles = cpu_to_le64(cpu->profiles); 860 disk->usage = cpu_to_le64(cpu->usage); 861 disk->devid = cpu_to_le64(cpu->devid); 862 disk->pstart = cpu_to_le64(cpu->pstart); 863 disk->pend = cpu_to_le64(cpu->pend); 864 disk->vstart = cpu_to_le64(cpu->vstart); 865 disk->vend = cpu_to_le64(cpu->vend); 866 disk->target = cpu_to_le64(cpu->target); 867 disk->flags = cpu_to_le64(cpu->flags); 868 disk->limit = cpu_to_le64(cpu->limit); 869 disk->stripes_min = cpu_to_le32(cpu->stripes_min); 870 disk->stripes_max = cpu_to_le32(cpu->stripes_max); 871 } 872 873 /* struct btrfs_super_block */ 874 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); 875 BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64); 876 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, 877 generation, 64); 878 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); 879 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size, 880 struct btrfs_super_block, sys_chunk_array_size, 32); 881 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation, 882 struct btrfs_super_block, chunk_root_generation, 64); 883 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, 884 root_level, 8); 885 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block, 886 chunk_root, 64); 887 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block, 888 chunk_root_level, 8); 889 BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, log_root, 64); 890 BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block, 891 log_root_level, 8); 892 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, 893 total_bytes, 64); 894 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, 895 bytes_used, 64); 896 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, 897 sectorsize, 32); 898 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, 899 nodesize, 32); 900 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, 901 stripesize, 32); 902 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, 903 root_dir_objectid, 64); 904 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, 905 num_devices, 64); 906 BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, 907 compat_flags, 64); 908 BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, 909 compat_ro_flags, 64); 910 BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, 911 incompat_flags, 64); 912 BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, 913 csum_type, 16); 914 BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, 915 cache_generation, 64); 916 BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64); 917 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, 918 uuid_tree_generation, 64); 919 BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block, 920 nr_global_roots, 64); 921 922 /* struct btrfs_file_extent_item */ 923 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, 924 type, 8); 925 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, 926 struct btrfs_file_extent_item, disk_bytenr, 64); 927 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset, 928 struct btrfs_file_extent_item, offset, 64); 929 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation, 930 struct btrfs_file_extent_item, generation, 64); 931 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes, 932 struct btrfs_file_extent_item, num_bytes, 64); 933 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes, 934 struct btrfs_file_extent_item, ram_bytes, 64); 935 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes, 936 struct btrfs_file_extent_item, disk_num_bytes, 64); 937 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, 938 struct btrfs_file_extent_item, compression, 8); 939 940 941 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); 942 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, 943 disk_bytenr, 64); 944 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, 945 generation, 64); 946 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, 947 disk_num_bytes, 64); 948 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, 949 offset, 64); 950 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, 951 num_bytes, 64); 952 BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item, 953 ram_bytes, 64); 954 BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item, 955 compression, 8); 956 BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, 957 encryption, 8); 958 BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, 959 other_encoding, 16); 960 961 /* btrfs_qgroup_status_item */ 962 BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, 963 generation, 64); 964 BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, 965 version, 64); 966 BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item, 967 flags, 64); 968 BTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item, 969 rescan, 64); 970 971 /* btrfs_qgroup_info_item */ 972 BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item, 973 generation, 64); 974 BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64); 975 BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item, 976 rfer_cmpr, 64); 977 BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64); 978 BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item, 979 excl_cmpr, 64); 980 981 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation, 982 struct btrfs_qgroup_info_item, generation, 64); 983 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item, 984 rfer, 64); 985 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr, 986 struct btrfs_qgroup_info_item, rfer_cmpr, 64); 987 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item, 988 excl, 64); 989 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr, 990 struct btrfs_qgroup_info_item, excl_cmpr, 64); 991 992 /* btrfs_qgroup_limit_item */ 993 BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, flags, 64); 994 BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item, 995 max_rfer, 64); 996 BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item, 997 max_excl, 64); 998 BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item, 999 rsv_rfer, 64); 1000 BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item, 1001 rsv_excl, 64); 1002 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_flags, 1003 struct btrfs_qgroup_limit_item, flags, 64); 1004 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_rfer, 1005 struct btrfs_qgroup_limit_item, max_rfer, 64); 1006 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_excl, 1007 struct btrfs_qgroup_limit_item, max_excl, 64); 1008 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_rfer, 1009 struct btrfs_qgroup_limit_item, rsv_rfer, 64); 1010 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_excl, 1011 struct btrfs_qgroup_limit_item, rsv_excl, 64); 1012 1013 /* btrfs_dev_replace_item */ 1014 BTRFS_SETGET_FUNCS(dev_replace_src_devid, 1015 struct btrfs_dev_replace_item, src_devid, 64); 1016 BTRFS_SETGET_FUNCS(dev_replace_cont_reading_from_srcdev_mode, 1017 struct btrfs_dev_replace_item, cont_reading_from_srcdev_mode, 1018 64); 1019 BTRFS_SETGET_FUNCS(dev_replace_replace_state, struct btrfs_dev_replace_item, 1020 replace_state, 64); 1021 BTRFS_SETGET_FUNCS(dev_replace_time_started, struct btrfs_dev_replace_item, 1022 time_started, 64); 1023 BTRFS_SETGET_FUNCS(dev_replace_time_stopped, struct btrfs_dev_replace_item, 1024 time_stopped, 64); 1025 BTRFS_SETGET_FUNCS(dev_replace_num_write_errors, struct btrfs_dev_replace_item, 1026 num_write_errors, 64); 1027 BTRFS_SETGET_FUNCS(dev_replace_num_uncorrectable_read_errors, 1028 struct btrfs_dev_replace_item, num_uncorrectable_read_errors, 1029 64); 1030 BTRFS_SETGET_FUNCS(dev_replace_cursor_left, struct btrfs_dev_replace_item, 1031 cursor_left, 64); 1032 BTRFS_SETGET_FUNCS(dev_replace_cursor_right, struct btrfs_dev_replace_item, 1033 cursor_right, 64); 1034 1035 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_src_devid, 1036 struct btrfs_dev_replace_item, src_devid, 64); 1037 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cont_reading_from_srcdev_mode, 1038 struct btrfs_dev_replace_item, 1039 cont_reading_from_srcdev_mode, 64); 1040 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_replace_state, 1041 struct btrfs_dev_replace_item, replace_state, 64); 1042 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_started, 1043 struct btrfs_dev_replace_item, time_started, 64); 1044 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_stopped, 1045 struct btrfs_dev_replace_item, time_stopped, 64); 1046 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_write_errors, 1047 struct btrfs_dev_replace_item, num_write_errors, 64); 1048 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_uncorrectable_read_errors, 1049 struct btrfs_dev_replace_item, 1050 num_uncorrectable_read_errors, 64); 1051 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left, 1052 struct btrfs_dev_replace_item, cursor_left, 64); 1053 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right, 1054 struct btrfs_dev_replace_item, cursor_right, 64); 1055 1056 /* btrfs_verity_descriptor_item */ 1057 BTRFS_SETGET_FUNCS(verity_descriptor_encryption, struct btrfs_verity_descriptor_item, 1058 encryption, 8); 1059 BTRFS_SETGET_FUNCS(verity_descriptor_size, struct btrfs_verity_descriptor_item, 1060 size, 64); 1061 BTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_encryption, 1062 struct btrfs_verity_descriptor_item, encryption, 8); 1063 BTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_size, 1064 struct btrfs_verity_descriptor_item, size, 64); 1065 1066 /* Cast into the data area of the leaf. */ 1067 #define btrfs_item_ptr(leaf, slot, type) \ 1068 ((type *)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot))) 1069 1070 #define btrfs_item_ptr_offset(leaf, slot) \ 1071 ((unsigned long)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot))) 1072 1073 #endif 1074