162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci#ifndef BTRFS_ACCESSORS_H 462306a36Sopenharmony_ci#define BTRFS_ACCESSORS_H 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include <linux/stddef.h> 762306a36Sopenharmony_ci 862306a36Sopenharmony_cistruct btrfs_map_token { 962306a36Sopenharmony_ci struct extent_buffer *eb; 1062306a36Sopenharmony_ci char *kaddr; 1162306a36Sopenharmony_ci unsigned long offset; 1262306a36Sopenharmony_ci}; 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_civoid btrfs_init_map_token(struct btrfs_map_token *token, struct extent_buffer *eb); 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* 1762306a36Sopenharmony_ci * Some macros to generate set/get functions for the struct fields. This 1862306a36Sopenharmony_ci * assumes there is a lefoo_to_cpu for every type, so lets make a simple one 1962306a36Sopenharmony_ci * for u8: 2062306a36Sopenharmony_ci */ 2162306a36Sopenharmony_ci#define le8_to_cpu(v) (v) 2262306a36Sopenharmony_ci#define cpu_to_le8(v) (v) 2362306a36Sopenharmony_ci#define __le8 u8 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistatic inline u8 get_unaligned_le8(const void *p) 2662306a36Sopenharmony_ci{ 2762306a36Sopenharmony_ci return *(u8 *)p; 2862306a36Sopenharmony_ci} 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistatic inline void put_unaligned_le8(u8 val, void *p) 3162306a36Sopenharmony_ci{ 3262306a36Sopenharmony_ci *(u8 *)p = val; 3362306a36Sopenharmony_ci} 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define read_eb_member(eb, ptr, type, member, result) (\ 3662306a36Sopenharmony_ci read_extent_buffer(eb, (char *)(result), \ 3762306a36Sopenharmony_ci ((unsigned long)(ptr)) + \ 3862306a36Sopenharmony_ci offsetof(type, member), \ 3962306a36Sopenharmony_ci sizeof_field(type, member))) 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define write_eb_member(eb, ptr, type, member, result) (\ 4262306a36Sopenharmony_ci write_extent_buffer(eb, (char *)(result), \ 4362306a36Sopenharmony_ci ((unsigned long)(ptr)) + \ 4462306a36Sopenharmony_ci offsetof(type, member), \ 4562306a36Sopenharmony_ci sizeof_field(type, member))) 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci#define DECLARE_BTRFS_SETGET_BITS(bits) \ 4862306a36Sopenharmony_ciu##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \ 4962306a36Sopenharmony_ci const void *ptr, unsigned long off); \ 5062306a36Sopenharmony_civoid btrfs_set_token_##bits(struct btrfs_map_token *token, \ 5162306a36Sopenharmony_ci const void *ptr, unsigned long off, \ 5262306a36Sopenharmony_ci u##bits val); \ 5362306a36Sopenharmony_ciu##bits btrfs_get_##bits(const struct extent_buffer *eb, \ 5462306a36Sopenharmony_ci const void *ptr, unsigned long off); \ 5562306a36Sopenharmony_civoid btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \ 5662306a36Sopenharmony_ci unsigned long off, u##bits val); 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciDECLARE_BTRFS_SETGET_BITS(8) 5962306a36Sopenharmony_ciDECLARE_BTRFS_SETGET_BITS(16) 6062306a36Sopenharmony_ciDECLARE_BTRFS_SETGET_BITS(32) 6162306a36Sopenharmony_ciDECLARE_BTRFS_SETGET_BITS(64) 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define BTRFS_SETGET_FUNCS(name, type, member, bits) \ 6462306a36Sopenharmony_cistatic inline u##bits btrfs_##name(const struct extent_buffer *eb, \ 6562306a36Sopenharmony_ci const type *s) \ 6662306a36Sopenharmony_ci{ \ 6762306a36Sopenharmony_ci static_assert(sizeof(u##bits) == sizeof_field(type, member)); \ 6862306a36Sopenharmony_ci return btrfs_get_##bits(eb, s, offsetof(type, member)); \ 6962306a36Sopenharmony_ci} \ 7062306a36Sopenharmony_cistatic inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \ 7162306a36Sopenharmony_ci u##bits val) \ 7262306a36Sopenharmony_ci{ \ 7362306a36Sopenharmony_ci static_assert(sizeof(u##bits) == sizeof_field(type, member)); \ 7462306a36Sopenharmony_ci btrfs_set_##bits(eb, s, offsetof(type, member), val); \ 7562306a36Sopenharmony_ci} \ 7662306a36Sopenharmony_cistatic inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \ 7762306a36Sopenharmony_ci const type *s) \ 7862306a36Sopenharmony_ci{ \ 7962306a36Sopenharmony_ci static_assert(sizeof(u##bits) == sizeof_field(type, member)); \ 8062306a36Sopenharmony_ci return btrfs_get_token_##bits(token, s, offsetof(type, member));\ 8162306a36Sopenharmony_ci} \ 8262306a36Sopenharmony_cistatic inline void btrfs_set_token_##name(struct btrfs_map_token *token,\ 8362306a36Sopenharmony_ci type *s, u##bits val) \ 8462306a36Sopenharmony_ci{ \ 8562306a36Sopenharmony_ci static_assert(sizeof(u##bits) == sizeof_field(type, member)); \ 8662306a36Sopenharmony_ci btrfs_set_token_##bits(token, s, offsetof(type, member), val); \ 8762306a36Sopenharmony_ci} 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ 9062306a36Sopenharmony_cistatic inline u##bits btrfs_##name(const struct extent_buffer *eb) \ 9162306a36Sopenharmony_ci{ \ 9262306a36Sopenharmony_ci const type *p = page_address(eb->pages[0]) + \ 9362306a36Sopenharmony_ci offset_in_page(eb->start); \ 9462306a36Sopenharmony_ci return get_unaligned_le##bits(&p->member); \ 9562306a36Sopenharmony_ci} \ 9662306a36Sopenharmony_cistatic inline void btrfs_set_##name(const struct extent_buffer *eb, \ 9762306a36Sopenharmony_ci u##bits val) \ 9862306a36Sopenharmony_ci{ \ 9962306a36Sopenharmony_ci type *p = page_address(eb->pages[0]) + offset_in_page(eb->start); \ 10062306a36Sopenharmony_ci put_unaligned_le##bits(val, &p->member); \ 10162306a36Sopenharmony_ci} 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ 10462306a36Sopenharmony_cistatic inline u##bits btrfs_##name(const type *s) \ 10562306a36Sopenharmony_ci{ \ 10662306a36Sopenharmony_ci return get_unaligned_le##bits(&s->member); \ 10762306a36Sopenharmony_ci} \ 10862306a36Sopenharmony_cistatic inline void btrfs_set_##name(type *s, u##bits val) \ 10962306a36Sopenharmony_ci{ \ 11062306a36Sopenharmony_ci put_unaligned_le##bits(val, &s->member); \ 11162306a36Sopenharmony_ci} 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_cistatic inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb, 11462306a36Sopenharmony_ci struct btrfs_dev_item *s) 11562306a36Sopenharmony_ci{ 11662306a36Sopenharmony_ci static_assert(sizeof(u64) == sizeof_field(struct btrfs_dev_item, total_bytes)); 11762306a36Sopenharmony_ci return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes)); 11862306a36Sopenharmony_ci} 11962306a36Sopenharmony_cistatic inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb, 12062306a36Sopenharmony_ci struct btrfs_dev_item *s, 12162306a36Sopenharmony_ci u64 val) 12262306a36Sopenharmony_ci{ 12362306a36Sopenharmony_ci static_assert(sizeof(u64) == sizeof_field(struct btrfs_dev_item, total_bytes)); 12462306a36Sopenharmony_ci WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize)); 12562306a36Sopenharmony_ci btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val); 12662306a36Sopenharmony_ci} 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64); 12962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64); 13062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32); 13162306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32); 13262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item, start_offset, 64); 13362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32); 13462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64); 13562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32); 13662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8); 13762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8); 13862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64); 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64); 14162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item, 14262306a36Sopenharmony_ci total_bytes, 64); 14362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item, 14462306a36Sopenharmony_ci bytes_used, 64); 14562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item, 14662306a36Sopenharmony_ci io_align, 32); 14762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item, 14862306a36Sopenharmony_ci io_width, 32); 14962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item, 15062306a36Sopenharmony_ci sector_size, 32); 15162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64); 15262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item, dev_group, 32); 15362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item, 15462306a36Sopenharmony_ci seek_speed, 8); 15562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item, 15662306a36Sopenharmony_ci bandwidth, 8); 15762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item, 15862306a36Sopenharmony_ci generation, 64); 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_cistatic inline unsigned long btrfs_device_uuid(struct btrfs_dev_item *d) 16162306a36Sopenharmony_ci{ 16262306a36Sopenharmony_ci return (unsigned long)d + offsetof(struct btrfs_dev_item, uuid); 16362306a36Sopenharmony_ci} 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_cistatic inline unsigned long btrfs_device_fsid(struct btrfs_dev_item *d) 16662306a36Sopenharmony_ci{ 16762306a36Sopenharmony_ci return (unsigned long)d + offsetof(struct btrfs_dev_item, fsid); 16862306a36Sopenharmony_ci} 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64); 17162306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64); 17262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64); 17362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32); 17462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32); 17562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32); 17662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64); 17762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16); 17862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16); 17962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64); 18062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64); 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_cistatic inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s) 18362306a36Sopenharmony_ci{ 18462306a36Sopenharmony_ci return (char *)s + offsetof(struct btrfs_stripe, dev_uuid); 18562306a36Sopenharmony_ci} 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64); 18862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64); 18962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk, 19062306a36Sopenharmony_ci stripe_len, 64); 19162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk, io_align, 32); 19262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk, io_width, 32); 19362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk, 19462306a36Sopenharmony_ci sector_size, 32); 19562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64); 19662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk, 19762306a36Sopenharmony_ci num_stripes, 16); 19862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk, 19962306a36Sopenharmony_ci sub_stripes, 16); 20062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64); 20162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64); 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_cistatic inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c, int nr) 20462306a36Sopenharmony_ci{ 20562306a36Sopenharmony_ci unsigned long offset = (unsigned long)c; 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci offset += offsetof(struct btrfs_chunk, stripe); 20862306a36Sopenharmony_ci offset += nr * sizeof(struct btrfs_stripe); 20962306a36Sopenharmony_ci return (struct btrfs_stripe *)offset; 21062306a36Sopenharmony_ci} 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_cistatic inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr) 21362306a36Sopenharmony_ci{ 21462306a36Sopenharmony_ci return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr)); 21562306a36Sopenharmony_ci} 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_cistatic inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb, 21862306a36Sopenharmony_ci struct btrfs_chunk *c, int nr) 21962306a36Sopenharmony_ci{ 22062306a36Sopenharmony_ci return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr)); 22162306a36Sopenharmony_ci} 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_cistatic inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb, 22462306a36Sopenharmony_ci struct btrfs_chunk *c, int nr, 22562306a36Sopenharmony_ci u64 val) 22662306a36Sopenharmony_ci{ 22762306a36Sopenharmony_ci btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val); 22862306a36Sopenharmony_ci} 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_cistatic inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb, 23162306a36Sopenharmony_ci struct btrfs_chunk *c, int nr) 23262306a36Sopenharmony_ci{ 23362306a36Sopenharmony_ci return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr)); 23462306a36Sopenharmony_ci} 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_cistatic inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb, 23762306a36Sopenharmony_ci struct btrfs_chunk *c, int nr, 23862306a36Sopenharmony_ci u64 val) 23962306a36Sopenharmony_ci{ 24062306a36Sopenharmony_ci btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val); 24162306a36Sopenharmony_ci} 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci/* struct btrfs_block_group_item */ 24462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item, 24562306a36Sopenharmony_ci used, 64); 24662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item, used, 64); 24762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid, 24862306a36Sopenharmony_ci struct btrfs_block_group_item, chunk_objectid, 64); 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(block_group_chunk_objectid, 25162306a36Sopenharmony_ci struct btrfs_block_group_item, chunk_objectid, 64); 25262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(block_group_flags, struct btrfs_block_group_item, flags, 64); 25362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_block_group_flags, 25462306a36Sopenharmony_ci struct btrfs_block_group_item, flags, 64); 25562306a36Sopenharmony_ci 25662306a36Sopenharmony_ci/* struct btrfs_free_space_info */ 25762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_extent_count, struct btrfs_free_space_info, 25862306a36Sopenharmony_ci extent_count, 32); 25962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32); 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ci/* struct btrfs_inode_ref */ 26262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); 26362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64); 26462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); 26562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_ref_index, struct btrfs_inode_ref, index, 64); 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci/* struct btrfs_inode_extref */ 26862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref, 26962306a36Sopenharmony_ci parent_objectid, 64); 27062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref, 27162306a36Sopenharmony_ci name_len, 16); 27262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64); 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_ci/* struct btrfs_inode_item */ 27562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); 27662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64); 27762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64); 27862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); 27962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64); 28062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); 28162306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); 28262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); 28362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32); 28462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32); 28562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64); 28662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64); 28762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_generation, struct btrfs_inode_item, 28862306a36Sopenharmony_ci generation, 64); 28962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, struct btrfs_inode_item, 29062306a36Sopenharmony_ci sequence, 64); 29162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_transid, struct btrfs_inode_item, 29262306a36Sopenharmony_ci transid, 64); 29362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_size, struct btrfs_inode_item, size, 64); 29462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, struct btrfs_inode_item, nbytes, 64); 29562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, struct btrfs_inode_item, 29662306a36Sopenharmony_ci block_group, 64); 29762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, struct btrfs_inode_item, nlink, 32); 29862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_uid, struct btrfs_inode_item, uid, 32); 29962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_gid, struct btrfs_inode_item, gid, 32); 30062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_mode, struct btrfs_inode_item, mode, 32); 30162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, struct btrfs_inode_item, rdev, 64); 30262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_inode_flags, struct btrfs_inode_item, flags, 64); 30362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); 30462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); 30562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64); 30662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32); 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ci/* struct btrfs_dev_extent */ 30962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, chunk_tree, 64); 31062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent, 31162306a36Sopenharmony_ci chunk_objectid, 64); 31262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent, 31362306a36Sopenharmony_ci chunk_offset, 64); 31462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); 31562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_tree, struct btrfs_dev_extent, 31662306a36Sopenharmony_ci chunk_tree, 64); 31762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_objectid, struct btrfs_dev_extent, 31862306a36Sopenharmony_ci chunk_objectid, 64); 31962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_offset, struct btrfs_dev_extent, 32062306a36Sopenharmony_ci chunk_offset, 64); 32162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_extent_length, struct btrfs_dev_extent, length, 64); 32262306a36Sopenharmony_ci 32362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); 32462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, generation, 64); 32562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64); 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8); 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_cistatic inline void btrfs_tree_block_key(const struct extent_buffer *eb, 33062306a36Sopenharmony_ci struct btrfs_tree_block_info *item, 33162306a36Sopenharmony_ci struct btrfs_disk_key *key) 33262306a36Sopenharmony_ci{ 33362306a36Sopenharmony_ci read_eb_member(eb, item, struct btrfs_tree_block_info, key, key); 33462306a36Sopenharmony_ci} 33562306a36Sopenharmony_ci 33662306a36Sopenharmony_cistatic inline void btrfs_set_tree_block_key(const struct extent_buffer *eb, 33762306a36Sopenharmony_ci struct btrfs_tree_block_info *item, 33862306a36Sopenharmony_ci struct btrfs_disk_key *key) 33962306a36Sopenharmony_ci{ 34062306a36Sopenharmony_ci write_eb_member(eb, item, struct btrfs_tree_block_info, key, key); 34162306a36Sopenharmony_ci} 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref, root, 64); 34462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref, 34562306a36Sopenharmony_ci objectid, 64); 34662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref, 34762306a36Sopenharmony_ci offset, 64); 34862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref, count, 32); 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref, count, 32); 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref, 35362306a36Sopenharmony_ci type, 8); 35462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref, 35562306a36Sopenharmony_ci offset, 64); 35662306a36Sopenharmony_ci 35762306a36Sopenharmony_cistatic inline u32 btrfs_extent_inline_ref_size(int type) 35862306a36Sopenharmony_ci{ 35962306a36Sopenharmony_ci if (type == BTRFS_TREE_BLOCK_REF_KEY || 36062306a36Sopenharmony_ci type == BTRFS_SHARED_BLOCK_REF_KEY) 36162306a36Sopenharmony_ci return sizeof(struct btrfs_extent_inline_ref); 36262306a36Sopenharmony_ci if (type == BTRFS_SHARED_DATA_REF_KEY) 36362306a36Sopenharmony_ci return sizeof(struct btrfs_shared_data_ref) + 36462306a36Sopenharmony_ci sizeof(struct btrfs_extent_inline_ref); 36562306a36Sopenharmony_ci if (type == BTRFS_EXTENT_DATA_REF_KEY) 36662306a36Sopenharmony_ci return sizeof(struct btrfs_extent_data_ref) + 36762306a36Sopenharmony_ci offsetof(struct btrfs_extent_inline_ref, offset); 36862306a36Sopenharmony_ci return 0; 36962306a36Sopenharmony_ci} 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci/* struct btrfs_node */ 37262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); 37362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); 37462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr, blockptr, 64); 37562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr, 37662306a36Sopenharmony_ci generation, 64); 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_cistatic inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr) 37962306a36Sopenharmony_ci{ 38062306a36Sopenharmony_ci unsigned long ptr; 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ci ptr = offsetof(struct btrfs_node, ptrs) + 38362306a36Sopenharmony_ci sizeof(struct btrfs_key_ptr) * nr; 38462306a36Sopenharmony_ci return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); 38562306a36Sopenharmony_ci} 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_cistatic inline void btrfs_set_node_blockptr(const struct extent_buffer *eb, 38862306a36Sopenharmony_ci int nr, u64 val) 38962306a36Sopenharmony_ci{ 39062306a36Sopenharmony_ci unsigned long ptr; 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci ptr = offsetof(struct btrfs_node, ptrs) + 39362306a36Sopenharmony_ci sizeof(struct btrfs_key_ptr) * nr; 39462306a36Sopenharmony_ci btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); 39562306a36Sopenharmony_ci} 39662306a36Sopenharmony_ci 39762306a36Sopenharmony_cistatic inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr) 39862306a36Sopenharmony_ci{ 39962306a36Sopenharmony_ci unsigned long ptr; 40062306a36Sopenharmony_ci 40162306a36Sopenharmony_ci ptr = offsetof(struct btrfs_node, ptrs) + 40262306a36Sopenharmony_ci sizeof(struct btrfs_key_ptr) * nr; 40362306a36Sopenharmony_ci return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); 40462306a36Sopenharmony_ci} 40562306a36Sopenharmony_ci 40662306a36Sopenharmony_cistatic inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb, 40762306a36Sopenharmony_ci int nr, u64 val) 40862306a36Sopenharmony_ci{ 40962306a36Sopenharmony_ci unsigned long ptr; 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci ptr = offsetof(struct btrfs_node, ptrs) + 41262306a36Sopenharmony_ci sizeof(struct btrfs_key_ptr) * nr; 41362306a36Sopenharmony_ci btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val); 41462306a36Sopenharmony_ci} 41562306a36Sopenharmony_ci 41662306a36Sopenharmony_cistatic inline unsigned long btrfs_node_key_ptr_offset(const struct extent_buffer *eb, int nr) 41762306a36Sopenharmony_ci{ 41862306a36Sopenharmony_ci return offsetof(struct btrfs_node, ptrs) + 41962306a36Sopenharmony_ci sizeof(struct btrfs_key_ptr) * nr; 42062306a36Sopenharmony_ci} 42162306a36Sopenharmony_ci 42262306a36Sopenharmony_civoid btrfs_node_key(const struct extent_buffer *eb, 42362306a36Sopenharmony_ci struct btrfs_disk_key *disk_key, int nr); 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_cistatic inline void btrfs_set_node_key(const struct extent_buffer *eb, 42662306a36Sopenharmony_ci struct btrfs_disk_key *disk_key, int nr) 42762306a36Sopenharmony_ci{ 42862306a36Sopenharmony_ci unsigned long ptr; 42962306a36Sopenharmony_ci 43062306a36Sopenharmony_ci ptr = btrfs_node_key_ptr_offset(eb, nr); 43162306a36Sopenharmony_ci write_eb_member(eb, (struct btrfs_key_ptr *)ptr, 43262306a36Sopenharmony_ci struct btrfs_key_ptr, key, disk_key); 43362306a36Sopenharmony_ci} 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci/* struct btrfs_item */ 43662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(raw_item_offset, struct btrfs_item, offset, 32); 43762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(raw_item_size, struct btrfs_item, size, 32); 43862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32); 43962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32); 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_cistatic inline unsigned long btrfs_item_nr_offset(const struct extent_buffer *eb, int nr) 44262306a36Sopenharmony_ci{ 44362306a36Sopenharmony_ci return offsetof(struct btrfs_leaf, items) + 44462306a36Sopenharmony_ci sizeof(struct btrfs_item) * nr; 44562306a36Sopenharmony_ci} 44662306a36Sopenharmony_ci 44762306a36Sopenharmony_cistatic inline struct btrfs_item *btrfs_item_nr(const struct extent_buffer *eb, int nr) 44862306a36Sopenharmony_ci{ 44962306a36Sopenharmony_ci return (struct btrfs_item *)btrfs_item_nr_offset(eb, nr); 45062306a36Sopenharmony_ci} 45162306a36Sopenharmony_ci 45262306a36Sopenharmony_ci#define BTRFS_ITEM_SETGET_FUNCS(member) \ 45362306a36Sopenharmony_cistatic inline u32 btrfs_item_##member(const struct extent_buffer *eb, int slot) \ 45462306a36Sopenharmony_ci{ \ 45562306a36Sopenharmony_ci return btrfs_raw_item_##member(eb, btrfs_item_nr(eb, slot)); \ 45662306a36Sopenharmony_ci} \ 45762306a36Sopenharmony_cistatic inline void btrfs_set_item_##member(const struct extent_buffer *eb, \ 45862306a36Sopenharmony_ci int slot, u32 val) \ 45962306a36Sopenharmony_ci{ \ 46062306a36Sopenharmony_ci btrfs_set_raw_item_##member(eb, btrfs_item_nr(eb, slot), val); \ 46162306a36Sopenharmony_ci} \ 46262306a36Sopenharmony_cistatic inline u32 btrfs_token_item_##member(struct btrfs_map_token *token, \ 46362306a36Sopenharmony_ci int slot) \ 46462306a36Sopenharmony_ci{ \ 46562306a36Sopenharmony_ci struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \ 46662306a36Sopenharmony_ci return btrfs_token_raw_item_##member(token, item); \ 46762306a36Sopenharmony_ci} \ 46862306a36Sopenharmony_cistatic inline void btrfs_set_token_item_##member(struct btrfs_map_token *token, \ 46962306a36Sopenharmony_ci int slot, u32 val) \ 47062306a36Sopenharmony_ci{ \ 47162306a36Sopenharmony_ci struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \ 47262306a36Sopenharmony_ci btrfs_set_token_raw_item_##member(token, item, val); \ 47362306a36Sopenharmony_ci} 47462306a36Sopenharmony_ci 47562306a36Sopenharmony_ciBTRFS_ITEM_SETGET_FUNCS(offset) 47662306a36Sopenharmony_ciBTRFS_ITEM_SETGET_FUNCS(size); 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_cistatic inline u32 btrfs_item_data_end(const struct extent_buffer *eb, int nr) 47962306a36Sopenharmony_ci{ 48062306a36Sopenharmony_ci return btrfs_item_offset(eb, nr) + btrfs_item_size(eb, nr); 48162306a36Sopenharmony_ci} 48262306a36Sopenharmony_ci 48362306a36Sopenharmony_cistatic inline void btrfs_item_key(const struct extent_buffer *eb, 48462306a36Sopenharmony_ci struct btrfs_disk_key *disk_key, int nr) 48562306a36Sopenharmony_ci{ 48662306a36Sopenharmony_ci struct btrfs_item *item = btrfs_item_nr(eb, nr); 48762306a36Sopenharmony_ci 48862306a36Sopenharmony_ci read_eb_member(eb, item, struct btrfs_item, key, disk_key); 48962306a36Sopenharmony_ci} 49062306a36Sopenharmony_ci 49162306a36Sopenharmony_cistatic inline void btrfs_set_item_key(struct extent_buffer *eb, 49262306a36Sopenharmony_ci struct btrfs_disk_key *disk_key, int nr) 49362306a36Sopenharmony_ci{ 49462306a36Sopenharmony_ci struct btrfs_item *item = btrfs_item_nr(eb, nr); 49562306a36Sopenharmony_ci 49662306a36Sopenharmony_ci write_eb_member(eb, item, struct btrfs_item, key, disk_key); 49762306a36Sopenharmony_ci} 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64); 50062306a36Sopenharmony_ci 50162306a36Sopenharmony_ci/* struct btrfs_root_ref */ 50262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64); 50362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64); 50462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16); 50562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_root_ref_dirid, struct btrfs_root_ref, dirid, 64); 50662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence, struct btrfs_root_ref, sequence, 64); 50762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_len, 16); 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_ci/* struct btrfs_dir_item */ 51062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); 51162306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, type, 8); 51262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); 51362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64); 51462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dir_flags, struct btrfs_dir_item, type, 8); 51562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, data_len, 16); 51662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16); 51762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, transid, 64); 51862306a36Sopenharmony_ci 51962306a36Sopenharmony_cistatic inline u8 btrfs_dir_ftype(const struct extent_buffer *eb, 52062306a36Sopenharmony_ci const struct btrfs_dir_item *item) 52162306a36Sopenharmony_ci{ 52262306a36Sopenharmony_ci return btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, item)); 52362306a36Sopenharmony_ci} 52462306a36Sopenharmony_ci 52562306a36Sopenharmony_cistatic inline u8 btrfs_stack_dir_ftype(const struct btrfs_dir_item *item) 52662306a36Sopenharmony_ci{ 52762306a36Sopenharmony_ci return btrfs_dir_flags_to_ftype(btrfs_stack_dir_flags(item)); 52862306a36Sopenharmony_ci} 52962306a36Sopenharmony_ci 53062306a36Sopenharmony_cistatic inline void btrfs_dir_item_key(const struct extent_buffer *eb, 53162306a36Sopenharmony_ci const struct btrfs_dir_item *item, 53262306a36Sopenharmony_ci struct btrfs_disk_key *key) 53362306a36Sopenharmony_ci{ 53462306a36Sopenharmony_ci read_eb_member(eb, item, struct btrfs_dir_item, location, key); 53562306a36Sopenharmony_ci} 53662306a36Sopenharmony_ci 53762306a36Sopenharmony_cistatic inline void btrfs_set_dir_item_key(struct extent_buffer *eb, 53862306a36Sopenharmony_ci struct btrfs_dir_item *item, 53962306a36Sopenharmony_ci const struct btrfs_disk_key *key) 54062306a36Sopenharmony_ci{ 54162306a36Sopenharmony_ci write_eb_member(eb, item, struct btrfs_dir_item, location, key); 54262306a36Sopenharmony_ci} 54362306a36Sopenharmony_ci 54462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header, 54562306a36Sopenharmony_ci num_entries, 64); 54662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header, 54762306a36Sopenharmony_ci num_bitmaps, 64); 54862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, 54962306a36Sopenharmony_ci generation, 64); 55062306a36Sopenharmony_ci 55162306a36Sopenharmony_cistatic inline void btrfs_free_space_key(const struct extent_buffer *eb, 55262306a36Sopenharmony_ci const struct btrfs_free_space_header *h, 55362306a36Sopenharmony_ci struct btrfs_disk_key *key) 55462306a36Sopenharmony_ci{ 55562306a36Sopenharmony_ci read_eb_member(eb, h, struct btrfs_free_space_header, location, key); 55662306a36Sopenharmony_ci} 55762306a36Sopenharmony_ci 55862306a36Sopenharmony_cistatic inline void btrfs_set_free_space_key(struct extent_buffer *eb, 55962306a36Sopenharmony_ci struct btrfs_free_space_header *h, 56062306a36Sopenharmony_ci const struct btrfs_disk_key *key) 56162306a36Sopenharmony_ci{ 56262306a36Sopenharmony_ci write_eb_member(eb, h, struct btrfs_free_space_header, location, key); 56362306a36Sopenharmony_ci} 56462306a36Sopenharmony_ci 56562306a36Sopenharmony_ci/* struct btrfs_disk_key */ 56662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, objectid, 64); 56762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); 56862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); 56962306a36Sopenharmony_ci 57062306a36Sopenharmony_ci#ifdef __LITTLE_ENDIAN 57162306a36Sopenharmony_ci 57262306a36Sopenharmony_ci/* 57362306a36Sopenharmony_ci * Optimized helpers for little-endian architectures where CPU and on-disk 57462306a36Sopenharmony_ci * structures have the same endianness and we can skip conversions. 57562306a36Sopenharmony_ci */ 57662306a36Sopenharmony_ci 57762306a36Sopenharmony_cistatic inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key, 57862306a36Sopenharmony_ci const struct btrfs_disk_key *disk_key) 57962306a36Sopenharmony_ci{ 58062306a36Sopenharmony_ci memcpy(cpu_key, disk_key, sizeof(struct btrfs_key)); 58162306a36Sopenharmony_ci} 58262306a36Sopenharmony_ci 58362306a36Sopenharmony_cistatic inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key, 58462306a36Sopenharmony_ci const struct btrfs_key *cpu_key) 58562306a36Sopenharmony_ci{ 58662306a36Sopenharmony_ci memcpy(disk_key, cpu_key, sizeof(struct btrfs_key)); 58762306a36Sopenharmony_ci} 58862306a36Sopenharmony_ci 58962306a36Sopenharmony_cistatic inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, 59062306a36Sopenharmony_ci struct btrfs_key *cpu_key, int nr) 59162306a36Sopenharmony_ci{ 59262306a36Sopenharmony_ci struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ci btrfs_node_key(eb, disk_key, nr); 59562306a36Sopenharmony_ci} 59662306a36Sopenharmony_ci 59762306a36Sopenharmony_cistatic inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, 59862306a36Sopenharmony_ci struct btrfs_key *cpu_key, int nr) 59962306a36Sopenharmony_ci{ 60062306a36Sopenharmony_ci struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; 60162306a36Sopenharmony_ci 60262306a36Sopenharmony_ci btrfs_item_key(eb, disk_key, nr); 60362306a36Sopenharmony_ci} 60462306a36Sopenharmony_ci 60562306a36Sopenharmony_cistatic inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, 60662306a36Sopenharmony_ci const struct btrfs_dir_item *item, 60762306a36Sopenharmony_ci struct btrfs_key *cpu_key) 60862306a36Sopenharmony_ci{ 60962306a36Sopenharmony_ci struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; 61062306a36Sopenharmony_ci 61162306a36Sopenharmony_ci btrfs_dir_item_key(eb, item, disk_key); 61262306a36Sopenharmony_ci} 61362306a36Sopenharmony_ci 61462306a36Sopenharmony_ci#else 61562306a36Sopenharmony_ci 61662306a36Sopenharmony_cistatic inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, 61762306a36Sopenharmony_ci const struct btrfs_disk_key *disk) 61862306a36Sopenharmony_ci{ 61962306a36Sopenharmony_ci cpu->offset = le64_to_cpu(disk->offset); 62062306a36Sopenharmony_ci cpu->type = disk->type; 62162306a36Sopenharmony_ci cpu->objectid = le64_to_cpu(disk->objectid); 62262306a36Sopenharmony_ci} 62362306a36Sopenharmony_ci 62462306a36Sopenharmony_cistatic inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, 62562306a36Sopenharmony_ci const struct btrfs_key *cpu) 62662306a36Sopenharmony_ci{ 62762306a36Sopenharmony_ci disk->offset = cpu_to_le64(cpu->offset); 62862306a36Sopenharmony_ci disk->type = cpu->type; 62962306a36Sopenharmony_ci disk->objectid = cpu_to_le64(cpu->objectid); 63062306a36Sopenharmony_ci} 63162306a36Sopenharmony_ci 63262306a36Sopenharmony_cistatic inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, 63362306a36Sopenharmony_ci struct btrfs_key *key, int nr) 63462306a36Sopenharmony_ci{ 63562306a36Sopenharmony_ci struct btrfs_disk_key disk_key; 63662306a36Sopenharmony_ci 63762306a36Sopenharmony_ci btrfs_node_key(eb, &disk_key, nr); 63862306a36Sopenharmony_ci btrfs_disk_key_to_cpu(key, &disk_key); 63962306a36Sopenharmony_ci} 64062306a36Sopenharmony_ci 64162306a36Sopenharmony_cistatic inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, 64262306a36Sopenharmony_ci struct btrfs_key *key, int nr) 64362306a36Sopenharmony_ci{ 64462306a36Sopenharmony_ci struct btrfs_disk_key disk_key; 64562306a36Sopenharmony_ci 64662306a36Sopenharmony_ci btrfs_item_key(eb, &disk_key, nr); 64762306a36Sopenharmony_ci btrfs_disk_key_to_cpu(key, &disk_key); 64862306a36Sopenharmony_ci} 64962306a36Sopenharmony_ci 65062306a36Sopenharmony_cistatic inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, 65162306a36Sopenharmony_ci const struct btrfs_dir_item *item, 65262306a36Sopenharmony_ci struct btrfs_key *key) 65362306a36Sopenharmony_ci{ 65462306a36Sopenharmony_ci struct btrfs_disk_key disk_key; 65562306a36Sopenharmony_ci 65662306a36Sopenharmony_ci btrfs_dir_item_key(eb, item, &disk_key); 65762306a36Sopenharmony_ci btrfs_disk_key_to_cpu(key, &disk_key); 65862306a36Sopenharmony_ci} 65962306a36Sopenharmony_ci 66062306a36Sopenharmony_ci#endif 66162306a36Sopenharmony_ci 66262306a36Sopenharmony_ci/* struct btrfs_header */ 66362306a36Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); 66462306a36Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, generation, 64); 66562306a36Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); 66662306a36Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); 66762306a36Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); 66862306a36Sopenharmony_ciBTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); 66962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, 67062306a36Sopenharmony_ci generation, 64); 67162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); 67262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, nritems, 32); 67362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); 67462306a36Sopenharmony_ci 67562306a36Sopenharmony_cistatic inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag) 67662306a36Sopenharmony_ci{ 67762306a36Sopenharmony_ci return (btrfs_header_flags(eb) & flag) == flag; 67862306a36Sopenharmony_ci} 67962306a36Sopenharmony_ci 68062306a36Sopenharmony_cistatic inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag) 68162306a36Sopenharmony_ci{ 68262306a36Sopenharmony_ci u64 flags = btrfs_header_flags(eb); 68362306a36Sopenharmony_ci 68462306a36Sopenharmony_ci btrfs_set_header_flags(eb, flags | flag); 68562306a36Sopenharmony_ci} 68662306a36Sopenharmony_ci 68762306a36Sopenharmony_cistatic inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag) 68862306a36Sopenharmony_ci{ 68962306a36Sopenharmony_ci u64 flags = btrfs_header_flags(eb); 69062306a36Sopenharmony_ci 69162306a36Sopenharmony_ci btrfs_set_header_flags(eb, flags & ~flag); 69262306a36Sopenharmony_ci} 69362306a36Sopenharmony_ci 69462306a36Sopenharmony_cistatic inline int btrfs_header_backref_rev(const struct extent_buffer *eb) 69562306a36Sopenharmony_ci{ 69662306a36Sopenharmony_ci u64 flags = btrfs_header_flags(eb); 69762306a36Sopenharmony_ci 69862306a36Sopenharmony_ci return flags >> BTRFS_BACKREF_REV_SHIFT; 69962306a36Sopenharmony_ci} 70062306a36Sopenharmony_ci 70162306a36Sopenharmony_cistatic inline void btrfs_set_header_backref_rev(struct extent_buffer *eb, int rev) 70262306a36Sopenharmony_ci{ 70362306a36Sopenharmony_ci u64 flags = btrfs_header_flags(eb); 70462306a36Sopenharmony_ci 70562306a36Sopenharmony_ci flags &= ~BTRFS_BACKREF_REV_MASK; 70662306a36Sopenharmony_ci flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT; 70762306a36Sopenharmony_ci btrfs_set_header_flags(eb, flags); 70862306a36Sopenharmony_ci} 70962306a36Sopenharmony_ci 71062306a36Sopenharmony_cistatic inline int btrfs_is_leaf(const struct extent_buffer *eb) 71162306a36Sopenharmony_ci{ 71262306a36Sopenharmony_ci return btrfs_header_level(eb) == 0; 71362306a36Sopenharmony_ci} 71462306a36Sopenharmony_ci 71562306a36Sopenharmony_ci/* struct btrfs_root_item */ 71662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item, generation, 64); 71762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); 71862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); 71962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); 72062306a36Sopenharmony_ci 72162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item, generation, 64); 72262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); 72362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_drop_level, struct btrfs_root_item, drop_level, 8); 72462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); 72562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); 72662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); 72762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64); 72862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); 72962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); 73062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item, 73162306a36Sopenharmony_ci last_snapshot, 64); 73262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item, 73362306a36Sopenharmony_ci generation_v2, 64); 73462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item, ctransid, 64); 73562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item, otransid, 64); 73662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item, stransid, 64); 73762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, rtransid, 64); 73862306a36Sopenharmony_ci 73962306a36Sopenharmony_ci/* struct btrfs_root_backup */ 74062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup, 74162306a36Sopenharmony_ci tree_root, 64); 74262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup, 74362306a36Sopenharmony_ci tree_root_gen, 64); 74462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup, 74562306a36Sopenharmony_ci tree_root_level, 8); 74662306a36Sopenharmony_ci 74762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup, 74862306a36Sopenharmony_ci chunk_root, 64); 74962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup, 75062306a36Sopenharmony_ci chunk_root_gen, 64); 75162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup, 75262306a36Sopenharmony_ci chunk_root_level, 8); 75362306a36Sopenharmony_ci 75462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup, 75562306a36Sopenharmony_ci extent_root, 64); 75662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup, 75762306a36Sopenharmony_ci extent_root_gen, 64); 75862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup, 75962306a36Sopenharmony_ci extent_root_level, 8); 76062306a36Sopenharmony_ci 76162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup, 76262306a36Sopenharmony_ci fs_root, 64); 76362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup, 76462306a36Sopenharmony_ci fs_root_gen, 64); 76562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup, 76662306a36Sopenharmony_ci fs_root_level, 8); 76762306a36Sopenharmony_ci 76862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup, 76962306a36Sopenharmony_ci dev_root, 64); 77062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup, 77162306a36Sopenharmony_ci dev_root_gen, 64); 77262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup, 77362306a36Sopenharmony_ci dev_root_level, 8); 77462306a36Sopenharmony_ci 77562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup, 77662306a36Sopenharmony_ci csum_root, 64); 77762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup, 77862306a36Sopenharmony_ci csum_root_gen, 64); 77962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup, 78062306a36Sopenharmony_ci csum_root_level, 8); 78162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup, 78262306a36Sopenharmony_ci total_bytes, 64); 78362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup, 78462306a36Sopenharmony_ci bytes_used, 64); 78562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup, 78662306a36Sopenharmony_ci num_devices, 64); 78762306a36Sopenharmony_ci 78862306a36Sopenharmony_ci/* struct btrfs_balance_item */ 78962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64); 79062306a36Sopenharmony_ci 79162306a36Sopenharmony_cistatic inline void btrfs_balance_data(const struct extent_buffer *eb, 79262306a36Sopenharmony_ci const struct btrfs_balance_item *bi, 79362306a36Sopenharmony_ci struct btrfs_disk_balance_args *ba) 79462306a36Sopenharmony_ci{ 79562306a36Sopenharmony_ci read_eb_member(eb, bi, struct btrfs_balance_item, data, ba); 79662306a36Sopenharmony_ci} 79762306a36Sopenharmony_ci 79862306a36Sopenharmony_cistatic inline void btrfs_set_balance_data(struct extent_buffer *eb, 79962306a36Sopenharmony_ci struct btrfs_balance_item *bi, 80062306a36Sopenharmony_ci const struct btrfs_disk_balance_args *ba) 80162306a36Sopenharmony_ci{ 80262306a36Sopenharmony_ci write_eb_member(eb, bi, struct btrfs_balance_item, data, ba); 80362306a36Sopenharmony_ci} 80462306a36Sopenharmony_ci 80562306a36Sopenharmony_cistatic inline void btrfs_balance_meta(const struct extent_buffer *eb, 80662306a36Sopenharmony_ci const struct btrfs_balance_item *bi, 80762306a36Sopenharmony_ci struct btrfs_disk_balance_args *ba) 80862306a36Sopenharmony_ci{ 80962306a36Sopenharmony_ci read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); 81062306a36Sopenharmony_ci} 81162306a36Sopenharmony_ci 81262306a36Sopenharmony_cistatic inline void btrfs_set_balance_meta(struct extent_buffer *eb, 81362306a36Sopenharmony_ci struct btrfs_balance_item *bi, 81462306a36Sopenharmony_ci const struct btrfs_disk_balance_args *ba) 81562306a36Sopenharmony_ci{ 81662306a36Sopenharmony_ci write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); 81762306a36Sopenharmony_ci} 81862306a36Sopenharmony_ci 81962306a36Sopenharmony_cistatic inline void btrfs_balance_sys(const struct extent_buffer *eb, 82062306a36Sopenharmony_ci const struct btrfs_balance_item *bi, 82162306a36Sopenharmony_ci struct btrfs_disk_balance_args *ba) 82262306a36Sopenharmony_ci{ 82362306a36Sopenharmony_ci read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); 82462306a36Sopenharmony_ci} 82562306a36Sopenharmony_ci 82662306a36Sopenharmony_cistatic inline void btrfs_set_balance_sys(struct extent_buffer *eb, 82762306a36Sopenharmony_ci struct btrfs_balance_item *bi, 82862306a36Sopenharmony_ci const struct btrfs_disk_balance_args *ba) 82962306a36Sopenharmony_ci{ 83062306a36Sopenharmony_ci write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); 83162306a36Sopenharmony_ci} 83262306a36Sopenharmony_ci 83362306a36Sopenharmony_cistatic inline void btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu, 83462306a36Sopenharmony_ci const struct btrfs_disk_balance_args *disk) 83562306a36Sopenharmony_ci{ 83662306a36Sopenharmony_ci memset(cpu, 0, sizeof(*cpu)); 83762306a36Sopenharmony_ci 83862306a36Sopenharmony_ci cpu->profiles = le64_to_cpu(disk->profiles); 83962306a36Sopenharmony_ci cpu->usage = le64_to_cpu(disk->usage); 84062306a36Sopenharmony_ci cpu->devid = le64_to_cpu(disk->devid); 84162306a36Sopenharmony_ci cpu->pstart = le64_to_cpu(disk->pstart); 84262306a36Sopenharmony_ci cpu->pend = le64_to_cpu(disk->pend); 84362306a36Sopenharmony_ci cpu->vstart = le64_to_cpu(disk->vstart); 84462306a36Sopenharmony_ci cpu->vend = le64_to_cpu(disk->vend); 84562306a36Sopenharmony_ci cpu->target = le64_to_cpu(disk->target); 84662306a36Sopenharmony_ci cpu->flags = le64_to_cpu(disk->flags); 84762306a36Sopenharmony_ci cpu->limit = le64_to_cpu(disk->limit); 84862306a36Sopenharmony_ci cpu->stripes_min = le32_to_cpu(disk->stripes_min); 84962306a36Sopenharmony_ci cpu->stripes_max = le32_to_cpu(disk->stripes_max); 85062306a36Sopenharmony_ci} 85162306a36Sopenharmony_ci 85262306a36Sopenharmony_cistatic inline void btrfs_cpu_balance_args_to_disk( 85362306a36Sopenharmony_ci struct btrfs_disk_balance_args *disk, 85462306a36Sopenharmony_ci const struct btrfs_balance_args *cpu) 85562306a36Sopenharmony_ci{ 85662306a36Sopenharmony_ci memset(disk, 0, sizeof(*disk)); 85762306a36Sopenharmony_ci 85862306a36Sopenharmony_ci disk->profiles = cpu_to_le64(cpu->profiles); 85962306a36Sopenharmony_ci disk->usage = cpu_to_le64(cpu->usage); 86062306a36Sopenharmony_ci disk->devid = cpu_to_le64(cpu->devid); 86162306a36Sopenharmony_ci disk->pstart = cpu_to_le64(cpu->pstart); 86262306a36Sopenharmony_ci disk->pend = cpu_to_le64(cpu->pend); 86362306a36Sopenharmony_ci disk->vstart = cpu_to_le64(cpu->vstart); 86462306a36Sopenharmony_ci disk->vend = cpu_to_le64(cpu->vend); 86562306a36Sopenharmony_ci disk->target = cpu_to_le64(cpu->target); 86662306a36Sopenharmony_ci disk->flags = cpu_to_le64(cpu->flags); 86762306a36Sopenharmony_ci disk->limit = cpu_to_le64(cpu->limit); 86862306a36Sopenharmony_ci disk->stripes_min = cpu_to_le32(cpu->stripes_min); 86962306a36Sopenharmony_ci disk->stripes_max = cpu_to_le32(cpu->stripes_max); 87062306a36Sopenharmony_ci} 87162306a36Sopenharmony_ci 87262306a36Sopenharmony_ci/* struct btrfs_super_block */ 87362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); 87462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64); 87562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, 87662306a36Sopenharmony_ci generation, 64); 87762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); 87862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_sys_array_size, 87962306a36Sopenharmony_ci struct btrfs_super_block, sys_chunk_array_size, 32); 88062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation, 88162306a36Sopenharmony_ci struct btrfs_super_block, chunk_root_generation, 64); 88262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, 88362306a36Sopenharmony_ci root_level, 8); 88462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block, 88562306a36Sopenharmony_ci chunk_root, 64); 88662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block, 88762306a36Sopenharmony_ci chunk_root_level, 8); 88862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, log_root, 64); 88962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block, 89062306a36Sopenharmony_ci log_root_level, 8); 89162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, 89262306a36Sopenharmony_ci total_bytes, 64); 89362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, 89462306a36Sopenharmony_ci bytes_used, 64); 89562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, 89662306a36Sopenharmony_ci sectorsize, 32); 89762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, 89862306a36Sopenharmony_ci nodesize, 32); 89962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, 90062306a36Sopenharmony_ci stripesize, 32); 90162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, 90262306a36Sopenharmony_ci root_dir_objectid, 64); 90362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, 90462306a36Sopenharmony_ci num_devices, 64); 90562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, 90662306a36Sopenharmony_ci compat_flags, 64); 90762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, 90862306a36Sopenharmony_ci compat_ro_flags, 64); 90962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, 91062306a36Sopenharmony_ci incompat_flags, 64); 91162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, 91262306a36Sopenharmony_ci csum_type, 16); 91362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, 91462306a36Sopenharmony_ci cache_generation, 64); 91562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64); 91662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, 91762306a36Sopenharmony_ci uuid_tree_generation, 64); 91862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block, 91962306a36Sopenharmony_ci nr_global_roots, 64); 92062306a36Sopenharmony_ci 92162306a36Sopenharmony_ci/* struct btrfs_file_extent_item */ 92262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, 92362306a36Sopenharmony_ci type, 8); 92462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, 92562306a36Sopenharmony_ci struct btrfs_file_extent_item, disk_bytenr, 64); 92662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset, 92762306a36Sopenharmony_ci struct btrfs_file_extent_item, offset, 64); 92862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation, 92962306a36Sopenharmony_ci struct btrfs_file_extent_item, generation, 64); 93062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes, 93162306a36Sopenharmony_ci struct btrfs_file_extent_item, num_bytes, 64); 93262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes, 93362306a36Sopenharmony_ci struct btrfs_file_extent_item, ram_bytes, 64); 93462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes, 93562306a36Sopenharmony_ci struct btrfs_file_extent_item, disk_num_bytes, 64); 93662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, 93762306a36Sopenharmony_ci struct btrfs_file_extent_item, compression, 8); 93862306a36Sopenharmony_ci 93962306a36Sopenharmony_ci 94062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); 94162306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, 94262306a36Sopenharmony_ci disk_bytenr, 64); 94362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, 94462306a36Sopenharmony_ci generation, 64); 94562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, 94662306a36Sopenharmony_ci disk_num_bytes, 64); 94762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, 94862306a36Sopenharmony_ci offset, 64); 94962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, 95062306a36Sopenharmony_ci num_bytes, 64); 95162306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item, 95262306a36Sopenharmony_ci ram_bytes, 64); 95362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item, 95462306a36Sopenharmony_ci compression, 8); 95562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, 95662306a36Sopenharmony_ci encryption, 8); 95762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, 95862306a36Sopenharmony_ci other_encoding, 16); 95962306a36Sopenharmony_ci 96062306a36Sopenharmony_ci/* btrfs_qgroup_status_item */ 96162306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, 96262306a36Sopenharmony_ci generation, 64); 96362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, 96462306a36Sopenharmony_ci version, 64); 96562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item, 96662306a36Sopenharmony_ci flags, 64); 96762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item, 96862306a36Sopenharmony_ci rescan, 64); 96962306a36Sopenharmony_ci 97062306a36Sopenharmony_ci/* btrfs_qgroup_info_item */ 97162306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item, 97262306a36Sopenharmony_ci generation, 64); 97362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64); 97462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item, 97562306a36Sopenharmony_ci rfer_cmpr, 64); 97662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64); 97762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item, 97862306a36Sopenharmony_ci excl_cmpr, 64); 97962306a36Sopenharmony_ci 98062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation, 98162306a36Sopenharmony_ci struct btrfs_qgroup_info_item, generation, 64); 98262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item, 98362306a36Sopenharmony_ci rfer, 64); 98462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr, 98562306a36Sopenharmony_ci struct btrfs_qgroup_info_item, rfer_cmpr, 64); 98662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item, 98762306a36Sopenharmony_ci excl, 64); 98862306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr, 98962306a36Sopenharmony_ci struct btrfs_qgroup_info_item, excl_cmpr, 64); 99062306a36Sopenharmony_ci 99162306a36Sopenharmony_ci/* btrfs_qgroup_limit_item */ 99262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, flags, 64); 99362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item, 99462306a36Sopenharmony_ci max_rfer, 64); 99562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item, 99662306a36Sopenharmony_ci max_excl, 64); 99762306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item, 99862306a36Sopenharmony_ci rsv_rfer, 64); 99962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item, 100062306a36Sopenharmony_ci rsv_excl, 64); 100162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_flags, 100262306a36Sopenharmony_ci struct btrfs_qgroup_limit_item, flags, 64); 100362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_rfer, 100462306a36Sopenharmony_ci struct btrfs_qgroup_limit_item, max_rfer, 64); 100562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_excl, 100662306a36Sopenharmony_ci struct btrfs_qgroup_limit_item, max_excl, 64); 100762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_rfer, 100862306a36Sopenharmony_ci struct btrfs_qgroup_limit_item, rsv_rfer, 64); 100962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_excl, 101062306a36Sopenharmony_ci struct btrfs_qgroup_limit_item, rsv_excl, 64); 101162306a36Sopenharmony_ci 101262306a36Sopenharmony_ci/* btrfs_dev_replace_item */ 101362306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_src_devid, 101462306a36Sopenharmony_ci struct btrfs_dev_replace_item, src_devid, 64); 101562306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_cont_reading_from_srcdev_mode, 101662306a36Sopenharmony_ci struct btrfs_dev_replace_item, cont_reading_from_srcdev_mode, 101762306a36Sopenharmony_ci 64); 101862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_replace_state, struct btrfs_dev_replace_item, 101962306a36Sopenharmony_ci replace_state, 64); 102062306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_time_started, struct btrfs_dev_replace_item, 102162306a36Sopenharmony_ci time_started, 64); 102262306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_time_stopped, struct btrfs_dev_replace_item, 102362306a36Sopenharmony_ci time_stopped, 64); 102462306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_num_write_errors, struct btrfs_dev_replace_item, 102562306a36Sopenharmony_ci num_write_errors, 64); 102662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_num_uncorrectable_read_errors, 102762306a36Sopenharmony_ci struct btrfs_dev_replace_item, num_uncorrectable_read_errors, 102862306a36Sopenharmony_ci 64); 102962306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_cursor_left, struct btrfs_dev_replace_item, 103062306a36Sopenharmony_ci cursor_left, 64); 103162306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(dev_replace_cursor_right, struct btrfs_dev_replace_item, 103262306a36Sopenharmony_ci cursor_right, 64); 103362306a36Sopenharmony_ci 103462306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_src_devid, 103562306a36Sopenharmony_ci struct btrfs_dev_replace_item, src_devid, 64); 103662306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cont_reading_from_srcdev_mode, 103762306a36Sopenharmony_ci struct btrfs_dev_replace_item, 103862306a36Sopenharmony_ci cont_reading_from_srcdev_mode, 64); 103962306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_replace_state, 104062306a36Sopenharmony_ci struct btrfs_dev_replace_item, replace_state, 64); 104162306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_started, 104262306a36Sopenharmony_ci struct btrfs_dev_replace_item, time_started, 64); 104362306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_stopped, 104462306a36Sopenharmony_ci struct btrfs_dev_replace_item, time_stopped, 64); 104562306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_write_errors, 104662306a36Sopenharmony_ci struct btrfs_dev_replace_item, num_write_errors, 64); 104762306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_uncorrectable_read_errors, 104862306a36Sopenharmony_ci struct btrfs_dev_replace_item, 104962306a36Sopenharmony_ci num_uncorrectable_read_errors, 64); 105062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left, 105162306a36Sopenharmony_ci struct btrfs_dev_replace_item, cursor_left, 64); 105262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right, 105362306a36Sopenharmony_ci struct btrfs_dev_replace_item, cursor_right, 64); 105462306a36Sopenharmony_ci 105562306a36Sopenharmony_ci/* btrfs_verity_descriptor_item */ 105662306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(verity_descriptor_encryption, struct btrfs_verity_descriptor_item, 105762306a36Sopenharmony_ci encryption, 8); 105862306a36Sopenharmony_ciBTRFS_SETGET_FUNCS(verity_descriptor_size, struct btrfs_verity_descriptor_item, 105962306a36Sopenharmony_ci size, 64); 106062306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_encryption, 106162306a36Sopenharmony_ci struct btrfs_verity_descriptor_item, encryption, 8); 106262306a36Sopenharmony_ciBTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_size, 106362306a36Sopenharmony_ci struct btrfs_verity_descriptor_item, size, 64); 106462306a36Sopenharmony_ci 106562306a36Sopenharmony_ci/* Cast into the data area of the leaf. */ 106662306a36Sopenharmony_ci#define btrfs_item_ptr(leaf, slot, type) \ 106762306a36Sopenharmony_ci ((type *)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot))) 106862306a36Sopenharmony_ci 106962306a36Sopenharmony_ci#define btrfs_item_ptr_offset(leaf, slot) \ 107062306a36Sopenharmony_ci ((unsigned long)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot))) 107162306a36Sopenharmony_ci 107262306a36Sopenharmony_ci#endif 1073