1ad1ac501SJosef Bacik /* SPDX-License-Identifier: GPL-2.0 */ 2ad1ac501SJosef Bacik 3ad1ac501SJosef Bacik #ifndef BTRFS_ACCESSORS_H 4ad1ac501SJosef Bacik #define BTRFS_ACCESSORS_H 5ad1ac501SJosef Bacik 6ad1ac501SJosef Bacik struct btrfs_map_token { 7ad1ac501SJosef Bacik struct extent_buffer *eb; 8ad1ac501SJosef Bacik char *kaddr; 9ad1ac501SJosef Bacik unsigned long offset; 10ad1ac501SJosef Bacik }; 11ad1ac501SJosef Bacik 1207e81dc9SJosef Bacik #define BTRFS_LEAF_DATA_OFFSET offsetof(struct btrfs_leaf, items) 1307e81dc9SJosef Bacik 14ad1ac501SJosef Bacik void btrfs_init_map_token(struct btrfs_map_token *token, struct extent_buffer *eb); 15ad1ac501SJosef Bacik 1607e81dc9SJosef Bacik /* 1707e81dc9SJosef Bacik * Some macros to generate set/get functions for the struct fields. This 1807e81dc9SJosef Bacik * assumes there is a lefoo_to_cpu for every type, so lets make a simple one 1907e81dc9SJosef Bacik * for u8: 2007e81dc9SJosef Bacik */ 2107e81dc9SJosef Bacik #define le8_to_cpu(v) (v) 2207e81dc9SJosef Bacik #define cpu_to_le8(v) (v) 2307e81dc9SJosef Bacik #define __le8 u8 2407e81dc9SJosef Bacik 2507e81dc9SJosef Bacik static inline u8 get_unaligned_le8(const void *p) 2607e81dc9SJosef Bacik { 2707e81dc9SJosef Bacik return *(u8 *)p; 2807e81dc9SJosef Bacik } 2907e81dc9SJosef Bacik 3007e81dc9SJosef Bacik static inline void put_unaligned_le8(u8 val, void *p) 3107e81dc9SJosef Bacik { 3207e81dc9SJosef Bacik *(u8 *)p = val; 3307e81dc9SJosef Bacik } 3407e81dc9SJosef Bacik 3507e81dc9SJosef Bacik #define read_eb_member(eb, ptr, type, member, result) (\ 3607e81dc9SJosef Bacik read_extent_buffer(eb, (char *)(result), \ 3707e81dc9SJosef Bacik ((unsigned long)(ptr)) + \ 3807e81dc9SJosef Bacik offsetof(type, member), \ 3907e81dc9SJosef Bacik sizeof(((type *)0)->member))) 4007e81dc9SJosef Bacik 4107e81dc9SJosef Bacik #define write_eb_member(eb, ptr, type, member, result) (\ 4207e81dc9SJosef Bacik write_extent_buffer(eb, (char *)(result), \ 4307e81dc9SJosef Bacik ((unsigned long)(ptr)) + \ 4407e81dc9SJosef Bacik offsetof(type, member), \ 4507e81dc9SJosef Bacik sizeof(((type *)0)->member))) 4607e81dc9SJosef Bacik 4707e81dc9SJosef Bacik #define DECLARE_BTRFS_SETGET_BITS(bits) \ 4807e81dc9SJosef Bacik u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \ 4907e81dc9SJosef Bacik const void *ptr, unsigned long off); \ 5007e81dc9SJosef Bacik void btrfs_set_token_##bits(struct btrfs_map_token *token, \ 5107e81dc9SJosef Bacik const void *ptr, unsigned long off, \ 5207e81dc9SJosef Bacik u##bits val); \ 5307e81dc9SJosef Bacik u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ 5407e81dc9SJosef Bacik const void *ptr, unsigned long off); \ 5507e81dc9SJosef Bacik void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \ 5607e81dc9SJosef Bacik unsigned long off, u##bits val); 5707e81dc9SJosef Bacik 5807e81dc9SJosef Bacik DECLARE_BTRFS_SETGET_BITS(8) 5907e81dc9SJosef Bacik DECLARE_BTRFS_SETGET_BITS(16) 6007e81dc9SJosef Bacik DECLARE_BTRFS_SETGET_BITS(32) 6107e81dc9SJosef Bacik DECLARE_BTRFS_SETGET_BITS(64) 6207e81dc9SJosef Bacik 6307e81dc9SJosef Bacik #define BTRFS_SETGET_FUNCS(name, type, member, bits) \ 6407e81dc9SJosef Bacik static inline u##bits btrfs_##name(const struct extent_buffer *eb, \ 6507e81dc9SJosef Bacik const type *s) \ 6607e81dc9SJosef Bacik { \ 6707e81dc9SJosef Bacik static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ 6807e81dc9SJosef Bacik return btrfs_get_##bits(eb, s, offsetof(type, member)); \ 6907e81dc9SJosef Bacik } \ 7007e81dc9SJosef Bacik static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \ 7107e81dc9SJosef Bacik u##bits val) \ 7207e81dc9SJosef Bacik { \ 7307e81dc9SJosef Bacik static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ 7407e81dc9SJosef Bacik btrfs_set_##bits(eb, s, offsetof(type, member), val); \ 7507e81dc9SJosef Bacik } \ 7607e81dc9SJosef Bacik static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \ 7707e81dc9SJosef Bacik const type *s) \ 7807e81dc9SJosef Bacik { \ 7907e81dc9SJosef Bacik static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ 8007e81dc9SJosef Bacik return btrfs_get_token_##bits(token, s, offsetof(type, member));\ 8107e81dc9SJosef Bacik } \ 8207e81dc9SJosef Bacik static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\ 8307e81dc9SJosef Bacik type *s, u##bits val) \ 8407e81dc9SJosef Bacik { \ 8507e81dc9SJosef Bacik static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ 8607e81dc9SJosef Bacik btrfs_set_token_##bits(token, s, offsetof(type, member), val); \ 8707e81dc9SJosef Bacik } 8807e81dc9SJosef Bacik 8907e81dc9SJosef Bacik #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ 9007e81dc9SJosef Bacik static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ 9107e81dc9SJosef Bacik { \ 9207e81dc9SJosef Bacik const type *p = page_address(eb->pages[0]) + \ 9307e81dc9SJosef Bacik offset_in_page(eb->start); \ 9407e81dc9SJosef Bacik return get_unaligned_le##bits(&p->member); \ 9507e81dc9SJosef Bacik } \ 9607e81dc9SJosef Bacik static inline void btrfs_set_##name(const struct extent_buffer *eb, \ 9707e81dc9SJosef Bacik u##bits val) \ 9807e81dc9SJosef Bacik { \ 9907e81dc9SJosef Bacik type *p = page_address(eb->pages[0]) + offset_in_page(eb->start); \ 10007e81dc9SJosef Bacik put_unaligned_le##bits(val, &p->member); \ 10107e81dc9SJosef Bacik } 10207e81dc9SJosef Bacik 10307e81dc9SJosef Bacik #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ 10407e81dc9SJosef Bacik static inline u##bits btrfs_##name(const type *s) \ 10507e81dc9SJosef Bacik { \ 10607e81dc9SJosef Bacik return get_unaligned_le##bits(&s->member); \ 10707e81dc9SJosef Bacik } \ 10807e81dc9SJosef Bacik static inline void btrfs_set_##name(type *s, u##bits val) \ 10907e81dc9SJosef Bacik { \ 11007e81dc9SJosef Bacik put_unaligned_le##bits(val, &s->member); \ 11107e81dc9SJosef Bacik } 11207e81dc9SJosef Bacik 11307e81dc9SJosef Bacik static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb, 11407e81dc9SJosef Bacik struct btrfs_dev_item *s) 11507e81dc9SJosef Bacik { 11607e81dc9SJosef Bacik static_assert(sizeof(u64) == 11707e81dc9SJosef Bacik sizeof(((struct btrfs_dev_item *)0))->total_bytes); 11807e81dc9SJosef Bacik return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item, 11907e81dc9SJosef Bacik total_bytes)); 12007e81dc9SJosef Bacik } 12107e81dc9SJosef Bacik static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb, 12207e81dc9SJosef Bacik struct btrfs_dev_item *s, 12307e81dc9SJosef Bacik u64 val) 12407e81dc9SJosef Bacik { 12507e81dc9SJosef Bacik static_assert(sizeof(u64) == 12607e81dc9SJosef Bacik sizeof(((struct btrfs_dev_item *)0))->total_bytes); 12707e81dc9SJosef Bacik WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize)); 12807e81dc9SJosef Bacik btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val); 12907e81dc9SJosef Bacik } 13007e81dc9SJosef Bacik 13107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64); 13207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64); 13307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32); 13407e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32); 13507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item, start_offset, 64); 13607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32); 13707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64); 13807e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32); 13907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8); 14007e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8); 14107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64); 14207e81dc9SJosef Bacik 14307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64); 14407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item, 14507e81dc9SJosef Bacik total_bytes, 64); 14607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item, 14707e81dc9SJosef Bacik bytes_used, 64); 14807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item, 14907e81dc9SJosef Bacik io_align, 32); 15007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item, 15107e81dc9SJosef Bacik io_width, 32); 15207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item, 15307e81dc9SJosef Bacik sector_size, 32); 15407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64); 15507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item, dev_group, 32); 15607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item, 15707e81dc9SJosef Bacik seek_speed, 8); 15807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item, 15907e81dc9SJosef Bacik bandwidth, 8); 16007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item, 16107e81dc9SJosef Bacik generation, 64); 16207e81dc9SJosef Bacik 16307e81dc9SJosef Bacik static inline unsigned long btrfs_device_uuid(struct btrfs_dev_item *d) 16407e81dc9SJosef Bacik { 16507e81dc9SJosef Bacik return (unsigned long)d + offsetof(struct btrfs_dev_item, uuid); 16607e81dc9SJosef Bacik } 16707e81dc9SJosef Bacik 16807e81dc9SJosef Bacik static inline unsigned long btrfs_device_fsid(struct btrfs_dev_item *d) 16907e81dc9SJosef Bacik { 17007e81dc9SJosef Bacik return (unsigned long)d + offsetof(struct btrfs_dev_item, fsid); 17107e81dc9SJosef Bacik } 17207e81dc9SJosef Bacik 17307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64); 17407e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64); 17507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64); 17607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32); 17707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32); 17807e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32); 17907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64); 18007e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16); 18107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16); 18207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64); 18307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64); 18407e81dc9SJosef Bacik 18507e81dc9SJosef Bacik static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s) 18607e81dc9SJosef Bacik { 18707e81dc9SJosef Bacik return (char *)s + offsetof(struct btrfs_stripe, dev_uuid); 18807e81dc9SJosef Bacik } 18907e81dc9SJosef Bacik 19007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64); 19107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64); 19207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk, 19307e81dc9SJosef Bacik stripe_len, 64); 19407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk, io_align, 32); 19507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk, io_width, 32); 19607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk, 19707e81dc9SJosef Bacik sector_size, 32); 19807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64); 19907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk, 20007e81dc9SJosef Bacik num_stripes, 16); 20107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk, 20207e81dc9SJosef Bacik sub_stripes, 16); 20307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64); 20407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64); 20507e81dc9SJosef Bacik 20607e81dc9SJosef Bacik static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c, int nr) 20707e81dc9SJosef Bacik { 20807e81dc9SJosef Bacik unsigned long offset = (unsigned long)c; 20907e81dc9SJosef Bacik 21007e81dc9SJosef Bacik offset += offsetof(struct btrfs_chunk, stripe); 21107e81dc9SJosef Bacik offset += nr * sizeof(struct btrfs_stripe); 21207e81dc9SJosef Bacik return (struct btrfs_stripe *)offset; 21307e81dc9SJosef Bacik } 21407e81dc9SJosef Bacik 21507e81dc9SJosef Bacik static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr) 21607e81dc9SJosef Bacik { 21707e81dc9SJosef Bacik return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr)); 21807e81dc9SJosef Bacik } 21907e81dc9SJosef Bacik 22007e81dc9SJosef Bacik static inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb, 22107e81dc9SJosef Bacik struct btrfs_chunk *c, int nr) 22207e81dc9SJosef Bacik { 22307e81dc9SJosef Bacik return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr)); 22407e81dc9SJosef Bacik } 22507e81dc9SJosef Bacik 22607e81dc9SJosef Bacik static inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb, 22707e81dc9SJosef Bacik struct btrfs_chunk *c, int nr) 22807e81dc9SJosef Bacik { 22907e81dc9SJosef Bacik return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr)); 23007e81dc9SJosef Bacik } 23107e81dc9SJosef Bacik 23207e81dc9SJosef Bacik /* struct btrfs_block_group_item */ 23307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item, 23407e81dc9SJosef Bacik used, 64); 23507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item, used, 64); 23607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid, 23707e81dc9SJosef Bacik struct btrfs_block_group_item, chunk_objectid, 64); 23807e81dc9SJosef Bacik 23907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(block_group_chunk_objectid, 24007e81dc9SJosef Bacik struct btrfs_block_group_item, chunk_objectid, 64); 24107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(block_group_flags, struct btrfs_block_group_item, flags, 64); 24207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_block_group_flags, 24307e81dc9SJosef Bacik struct btrfs_block_group_item, flags, 64); 24407e81dc9SJosef Bacik 24507e81dc9SJosef Bacik /* struct btrfs_free_space_info */ 24607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(free_space_extent_count, struct btrfs_free_space_info, 24707e81dc9SJosef Bacik extent_count, 32); 24807e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32); 24907e81dc9SJosef Bacik 25007e81dc9SJosef Bacik /* struct btrfs_inode_ref */ 25107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); 25207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64); 25307e81dc9SJosef Bacik 25407e81dc9SJosef Bacik /* struct btrfs_inode_extref */ 25507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref, 25607e81dc9SJosef Bacik parent_objectid, 64); 25707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref, 25807e81dc9SJosef Bacik name_len, 16); 25907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64); 26007e81dc9SJosef Bacik 26107e81dc9SJosef Bacik /* struct btrfs_inode_item */ 26207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); 26307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64); 26407e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64); 26507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); 26607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64); 26707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); 26807e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); 26907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); 27007e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32); 27107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32); 27207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64); 27307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64); 27407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_generation, struct btrfs_inode_item, 27507e81dc9SJosef Bacik generation, 64); 27607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, struct btrfs_inode_item, 27707e81dc9SJosef Bacik sequence, 64); 27807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_transid, struct btrfs_inode_item, 27907e81dc9SJosef Bacik transid, 64); 28007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_size, struct btrfs_inode_item, size, 64); 28107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, struct btrfs_inode_item, nbytes, 64); 28207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, struct btrfs_inode_item, 28307e81dc9SJosef Bacik block_group, 64); 28407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, struct btrfs_inode_item, nlink, 32); 28507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_uid, struct btrfs_inode_item, uid, 32); 28607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_gid, struct btrfs_inode_item, gid, 32); 28707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_mode, struct btrfs_inode_item, mode, 32); 28807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, struct btrfs_inode_item, rdev, 64); 28907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_inode_flags, struct btrfs_inode_item, flags, 64); 29007e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); 29107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); 29207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64); 29307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32); 29407e81dc9SJosef Bacik 29507e81dc9SJosef Bacik /* struct btrfs_dev_extent */ 29607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, chunk_tree, 64); 29707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent, 29807e81dc9SJosef Bacik chunk_objectid, 64); 29907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent, 30007e81dc9SJosef Bacik chunk_offset, 64); 30107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); 30207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); 30307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, generation, 64); 30407e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64); 30507e81dc9SJosef Bacik 30607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8); 30707e81dc9SJosef Bacik 30807e81dc9SJosef Bacik static inline void btrfs_tree_block_key(const struct extent_buffer *eb, 30907e81dc9SJosef Bacik struct btrfs_tree_block_info *item, 31007e81dc9SJosef Bacik struct btrfs_disk_key *key) 31107e81dc9SJosef Bacik { 31207e81dc9SJosef Bacik read_eb_member(eb, item, struct btrfs_tree_block_info, key, key); 31307e81dc9SJosef Bacik } 31407e81dc9SJosef Bacik 31507e81dc9SJosef Bacik static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb, 31607e81dc9SJosef Bacik struct btrfs_tree_block_info *item, 31707e81dc9SJosef Bacik struct btrfs_disk_key *key) 31807e81dc9SJosef Bacik { 31907e81dc9SJosef Bacik write_eb_member(eb, item, struct btrfs_tree_block_info, key, key); 32007e81dc9SJosef Bacik } 32107e81dc9SJosef Bacik 32207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref, root, 64); 32307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref, 32407e81dc9SJosef Bacik objectid, 64); 32507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref, 32607e81dc9SJosef Bacik offset, 64); 32707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref, count, 32); 32807e81dc9SJosef Bacik 32907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref, count, 32); 33007e81dc9SJosef Bacik 33107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref, 33207e81dc9SJosef Bacik type, 8); 33307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref, 33407e81dc9SJosef Bacik offset, 64); 33507e81dc9SJosef Bacik 33607e81dc9SJosef Bacik static inline u32 btrfs_extent_inline_ref_size(int type) 33707e81dc9SJosef Bacik { 33807e81dc9SJosef Bacik if (type == BTRFS_TREE_BLOCK_REF_KEY || 33907e81dc9SJosef Bacik type == BTRFS_SHARED_BLOCK_REF_KEY) 34007e81dc9SJosef Bacik return sizeof(struct btrfs_extent_inline_ref); 34107e81dc9SJosef Bacik if (type == BTRFS_SHARED_DATA_REF_KEY) 34207e81dc9SJosef Bacik return sizeof(struct btrfs_shared_data_ref) + 34307e81dc9SJosef Bacik sizeof(struct btrfs_extent_inline_ref); 34407e81dc9SJosef Bacik if (type == BTRFS_EXTENT_DATA_REF_KEY) 34507e81dc9SJosef Bacik return sizeof(struct btrfs_extent_data_ref) + 34607e81dc9SJosef Bacik offsetof(struct btrfs_extent_inline_ref, offset); 34707e81dc9SJosef Bacik return 0; 34807e81dc9SJosef Bacik } 34907e81dc9SJosef Bacik 35007e81dc9SJosef Bacik /* struct btrfs_node */ 35107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); 35207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); 35307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr, blockptr, 64); 35407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr, 35507e81dc9SJosef Bacik generation, 64); 35607e81dc9SJosef Bacik 35707e81dc9SJosef Bacik static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr) 35807e81dc9SJosef Bacik { 35907e81dc9SJosef Bacik unsigned long ptr; 36007e81dc9SJosef Bacik 36107e81dc9SJosef Bacik ptr = offsetof(struct btrfs_node, ptrs) + 36207e81dc9SJosef Bacik sizeof(struct btrfs_key_ptr) * nr; 36307e81dc9SJosef Bacik return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); 36407e81dc9SJosef Bacik } 36507e81dc9SJosef Bacik 36607e81dc9SJosef Bacik static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb, 36707e81dc9SJosef Bacik int nr, u64 val) 36807e81dc9SJosef Bacik { 36907e81dc9SJosef Bacik unsigned long ptr; 37007e81dc9SJosef Bacik 37107e81dc9SJosef Bacik ptr = offsetof(struct btrfs_node, ptrs) + 37207e81dc9SJosef Bacik sizeof(struct btrfs_key_ptr) * nr; 37307e81dc9SJosef Bacik btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); 37407e81dc9SJosef Bacik } 37507e81dc9SJosef Bacik 37607e81dc9SJosef Bacik static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr) 37707e81dc9SJosef Bacik { 37807e81dc9SJosef Bacik unsigned long ptr; 37907e81dc9SJosef Bacik 38007e81dc9SJosef Bacik ptr = offsetof(struct btrfs_node, ptrs) + 38107e81dc9SJosef Bacik sizeof(struct btrfs_key_ptr) * nr; 38207e81dc9SJosef Bacik return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); 38307e81dc9SJosef Bacik } 38407e81dc9SJosef Bacik 38507e81dc9SJosef Bacik static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb, 38607e81dc9SJosef Bacik int nr, u64 val) 38707e81dc9SJosef Bacik { 38807e81dc9SJosef Bacik unsigned long ptr; 38907e81dc9SJosef Bacik 39007e81dc9SJosef Bacik ptr = offsetof(struct btrfs_node, ptrs) + 39107e81dc9SJosef Bacik sizeof(struct btrfs_key_ptr) * nr; 39207e81dc9SJosef Bacik btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val); 39307e81dc9SJosef Bacik } 39407e81dc9SJosef Bacik 39507e81dc9SJosef Bacik static inline unsigned long btrfs_node_key_ptr_offset(int nr) 39607e81dc9SJosef Bacik { 39707e81dc9SJosef Bacik return offsetof(struct btrfs_node, ptrs) + 39807e81dc9SJosef Bacik sizeof(struct btrfs_key_ptr) * nr; 39907e81dc9SJosef Bacik } 40007e81dc9SJosef Bacik 40107e81dc9SJosef Bacik void btrfs_node_key(const struct extent_buffer *eb, 40207e81dc9SJosef Bacik struct btrfs_disk_key *disk_key, int nr); 40307e81dc9SJosef Bacik 40407e81dc9SJosef Bacik static inline void btrfs_set_node_key(const struct extent_buffer *eb, 40507e81dc9SJosef Bacik struct btrfs_disk_key *disk_key, int nr) 40607e81dc9SJosef Bacik { 40707e81dc9SJosef Bacik unsigned long ptr; 40807e81dc9SJosef Bacik 40907e81dc9SJosef Bacik ptr = btrfs_node_key_ptr_offset(nr); 41007e81dc9SJosef Bacik write_eb_member(eb, (struct btrfs_key_ptr *)ptr, 41107e81dc9SJosef Bacik struct btrfs_key_ptr, key, disk_key); 41207e81dc9SJosef Bacik } 41307e81dc9SJosef Bacik 41407e81dc9SJosef Bacik /* struct btrfs_item */ 41507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(raw_item_offset, struct btrfs_item, offset, 32); 41607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(raw_item_size, struct btrfs_item, size, 32); 41707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32); 41807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32); 41907e81dc9SJosef Bacik 420*42c9419aSJosef Bacik static inline unsigned long btrfs_item_nr_offset(const struct extent_buffer *eb, int nr) 42107e81dc9SJosef Bacik { 42207e81dc9SJosef Bacik return offsetof(struct btrfs_leaf, items) + 42307e81dc9SJosef Bacik sizeof(struct btrfs_item) * nr; 42407e81dc9SJosef Bacik } 42507e81dc9SJosef Bacik 426*42c9419aSJosef Bacik static inline struct btrfs_item *btrfs_item_nr(const struct extent_buffer *eb, int nr) 42707e81dc9SJosef Bacik { 428*42c9419aSJosef Bacik return (struct btrfs_item *)btrfs_item_nr_offset(eb, nr); 42907e81dc9SJosef Bacik } 43007e81dc9SJosef Bacik 43107e81dc9SJosef Bacik #define BTRFS_ITEM_SETGET_FUNCS(member) \ 43207e81dc9SJosef Bacik static inline u32 btrfs_item_##member(const struct extent_buffer *eb, int slot) \ 43307e81dc9SJosef Bacik { \ 434*42c9419aSJosef Bacik return btrfs_raw_item_##member(eb, btrfs_item_nr(eb, slot)); \ 43507e81dc9SJosef Bacik } \ 43607e81dc9SJosef Bacik static inline void btrfs_set_item_##member(const struct extent_buffer *eb, \ 43707e81dc9SJosef Bacik int slot, u32 val) \ 43807e81dc9SJosef Bacik { \ 439*42c9419aSJosef Bacik btrfs_set_raw_item_##member(eb, btrfs_item_nr(eb, slot), val); \ 44007e81dc9SJosef Bacik } \ 44107e81dc9SJosef Bacik static inline u32 btrfs_token_item_##member(struct btrfs_map_token *token, \ 44207e81dc9SJosef Bacik int slot) \ 44307e81dc9SJosef Bacik { \ 444*42c9419aSJosef Bacik struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \ 44507e81dc9SJosef Bacik return btrfs_token_raw_item_##member(token, item); \ 44607e81dc9SJosef Bacik } \ 44707e81dc9SJosef Bacik static inline void btrfs_set_token_item_##member(struct btrfs_map_token *token, \ 44807e81dc9SJosef Bacik int slot, u32 val) \ 44907e81dc9SJosef Bacik { \ 450*42c9419aSJosef Bacik struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \ 45107e81dc9SJosef Bacik btrfs_set_token_raw_item_##member(token, item, val); \ 45207e81dc9SJosef Bacik } 45307e81dc9SJosef Bacik 45407e81dc9SJosef Bacik BTRFS_ITEM_SETGET_FUNCS(offset) 45507e81dc9SJosef Bacik BTRFS_ITEM_SETGET_FUNCS(size); 45607e81dc9SJosef Bacik 45707e81dc9SJosef Bacik static inline u32 btrfs_item_data_end(const struct extent_buffer *eb, int nr) 45807e81dc9SJosef Bacik { 45907e81dc9SJosef Bacik return btrfs_item_offset(eb, nr) + btrfs_item_size(eb, nr); 46007e81dc9SJosef Bacik } 46107e81dc9SJosef Bacik 46207e81dc9SJosef Bacik static inline void btrfs_item_key(const struct extent_buffer *eb, 46307e81dc9SJosef Bacik struct btrfs_disk_key *disk_key, int nr) 46407e81dc9SJosef Bacik { 465*42c9419aSJosef Bacik struct btrfs_item *item = btrfs_item_nr(eb, nr); 46607e81dc9SJosef Bacik 46707e81dc9SJosef Bacik read_eb_member(eb, item, struct btrfs_item, key, disk_key); 46807e81dc9SJosef Bacik } 46907e81dc9SJosef Bacik 47007e81dc9SJosef Bacik static inline void btrfs_set_item_key(struct extent_buffer *eb, 47107e81dc9SJosef Bacik struct btrfs_disk_key *disk_key, int nr) 47207e81dc9SJosef Bacik { 473*42c9419aSJosef Bacik struct btrfs_item *item = btrfs_item_nr(eb, nr); 47407e81dc9SJosef Bacik 47507e81dc9SJosef Bacik write_eb_member(eb, item, struct btrfs_item, key, disk_key); 47607e81dc9SJosef Bacik } 47707e81dc9SJosef Bacik 47807e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64); 47907e81dc9SJosef Bacik 48007e81dc9SJosef Bacik /* struct btrfs_root_ref */ 48107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64); 48207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64); 48307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16); 48407e81dc9SJosef Bacik 48507e81dc9SJosef Bacik /* struct btrfs_dir_item */ 48607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); 48794a48aefSOmar Sandoval BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, type, 8); 48807e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); 48907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64); 49094a48aefSOmar Sandoval BTRFS_SETGET_STACK_FUNCS(stack_dir_flags, struct btrfs_dir_item, type, 8); 49107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, data_len, 16); 49207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16); 49307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, transid, 64); 49407e81dc9SJosef Bacik 49594a48aefSOmar Sandoval static inline u8 btrfs_dir_ftype(const struct extent_buffer *eb, 49694a48aefSOmar Sandoval const struct btrfs_dir_item *item) 49794a48aefSOmar Sandoval { 49894a48aefSOmar Sandoval return btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, item)); 49994a48aefSOmar Sandoval } 50094a48aefSOmar Sandoval 50194a48aefSOmar Sandoval static inline u8 btrfs_stack_dir_ftype(const struct btrfs_dir_item *item) 50294a48aefSOmar Sandoval { 50394a48aefSOmar Sandoval return btrfs_dir_flags_to_ftype(btrfs_stack_dir_flags(item)); 50494a48aefSOmar Sandoval } 50594a48aefSOmar Sandoval 50607e81dc9SJosef Bacik static inline void btrfs_dir_item_key(const struct extent_buffer *eb, 50707e81dc9SJosef Bacik const struct btrfs_dir_item *item, 50807e81dc9SJosef Bacik struct btrfs_disk_key *key) 50907e81dc9SJosef Bacik { 51007e81dc9SJosef Bacik read_eb_member(eb, item, struct btrfs_dir_item, location, key); 51107e81dc9SJosef Bacik } 51207e81dc9SJosef Bacik 51307e81dc9SJosef Bacik static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, 51407e81dc9SJosef Bacik struct btrfs_dir_item *item, 51507e81dc9SJosef Bacik const struct btrfs_disk_key *key) 51607e81dc9SJosef Bacik { 51707e81dc9SJosef Bacik write_eb_member(eb, item, struct btrfs_dir_item, location, key); 51807e81dc9SJosef Bacik } 51907e81dc9SJosef Bacik 52007e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header, 52107e81dc9SJosef Bacik num_entries, 64); 52207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header, 52307e81dc9SJosef Bacik num_bitmaps, 64); 52407e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, 52507e81dc9SJosef Bacik generation, 64); 52607e81dc9SJosef Bacik 52707e81dc9SJosef Bacik static inline void btrfs_free_space_key(const struct extent_buffer *eb, 52807e81dc9SJosef Bacik const struct btrfs_free_space_header *h, 52907e81dc9SJosef Bacik struct btrfs_disk_key *key) 53007e81dc9SJosef Bacik { 53107e81dc9SJosef Bacik read_eb_member(eb, h, struct btrfs_free_space_header, location, key); 53207e81dc9SJosef Bacik } 53307e81dc9SJosef Bacik 53407e81dc9SJosef Bacik static inline void btrfs_set_free_space_key(struct extent_buffer *eb, 53507e81dc9SJosef Bacik struct btrfs_free_space_header *h, 53607e81dc9SJosef Bacik const struct btrfs_disk_key *key) 53707e81dc9SJosef Bacik { 53807e81dc9SJosef Bacik write_eb_member(eb, h, struct btrfs_free_space_header, location, key); 53907e81dc9SJosef Bacik } 54007e81dc9SJosef Bacik 54107e81dc9SJosef Bacik /* struct btrfs_disk_key */ 54207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, objectid, 64); 54307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); 54407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); 54507e81dc9SJosef Bacik 54607e81dc9SJosef Bacik #ifdef __LITTLE_ENDIAN 54707e81dc9SJosef Bacik 54807e81dc9SJosef Bacik /* 54907e81dc9SJosef Bacik * Optimized helpers for little-endian architectures where CPU and on-disk 55007e81dc9SJosef Bacik * structures have the same endianness and we can skip conversions. 55107e81dc9SJosef Bacik */ 55207e81dc9SJosef Bacik 55307e81dc9SJosef Bacik static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key, 55407e81dc9SJosef Bacik const struct btrfs_disk_key *disk_key) 55507e81dc9SJosef Bacik { 55607e81dc9SJosef Bacik memcpy(cpu_key, disk_key, sizeof(struct btrfs_key)); 55707e81dc9SJosef Bacik } 55807e81dc9SJosef Bacik 55907e81dc9SJosef Bacik static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key, 56007e81dc9SJosef Bacik const struct btrfs_key *cpu_key) 56107e81dc9SJosef Bacik { 56207e81dc9SJosef Bacik memcpy(disk_key, cpu_key, sizeof(struct btrfs_key)); 56307e81dc9SJosef Bacik } 56407e81dc9SJosef Bacik 56507e81dc9SJosef Bacik static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, 56607e81dc9SJosef Bacik struct btrfs_key *cpu_key, int nr) 56707e81dc9SJosef Bacik { 56807e81dc9SJosef Bacik struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; 56907e81dc9SJosef Bacik 57007e81dc9SJosef Bacik btrfs_node_key(eb, disk_key, nr); 57107e81dc9SJosef Bacik } 57207e81dc9SJosef Bacik 57307e81dc9SJosef Bacik static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, 57407e81dc9SJosef Bacik struct btrfs_key *cpu_key, int nr) 57507e81dc9SJosef Bacik { 57607e81dc9SJosef Bacik struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; 57707e81dc9SJosef Bacik 57807e81dc9SJosef Bacik btrfs_item_key(eb, disk_key, nr); 57907e81dc9SJosef Bacik } 58007e81dc9SJosef Bacik 58107e81dc9SJosef Bacik static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, 58207e81dc9SJosef Bacik const struct btrfs_dir_item *item, 58307e81dc9SJosef Bacik struct btrfs_key *cpu_key) 58407e81dc9SJosef Bacik { 58507e81dc9SJosef Bacik struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key; 58607e81dc9SJosef Bacik 58707e81dc9SJosef Bacik btrfs_dir_item_key(eb, item, disk_key); 58807e81dc9SJosef Bacik } 58907e81dc9SJosef Bacik 59007e81dc9SJosef Bacik #else 59107e81dc9SJosef Bacik 59207e81dc9SJosef Bacik static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, 59307e81dc9SJosef Bacik const struct btrfs_disk_key *disk) 59407e81dc9SJosef Bacik { 59507e81dc9SJosef Bacik cpu->offset = le64_to_cpu(disk->offset); 59607e81dc9SJosef Bacik cpu->type = disk->type; 59707e81dc9SJosef Bacik cpu->objectid = le64_to_cpu(disk->objectid); 59807e81dc9SJosef Bacik } 59907e81dc9SJosef Bacik 60007e81dc9SJosef Bacik static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, 60107e81dc9SJosef Bacik const struct btrfs_key *cpu) 60207e81dc9SJosef Bacik { 60307e81dc9SJosef Bacik disk->offset = cpu_to_le64(cpu->offset); 60407e81dc9SJosef Bacik disk->type = cpu->type; 60507e81dc9SJosef Bacik disk->objectid = cpu_to_le64(cpu->objectid); 60607e81dc9SJosef Bacik } 60707e81dc9SJosef Bacik 60807e81dc9SJosef Bacik static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb, 60907e81dc9SJosef Bacik struct btrfs_key *key, int nr) 61007e81dc9SJosef Bacik { 61107e81dc9SJosef Bacik struct btrfs_disk_key disk_key; 61207e81dc9SJosef Bacik 61307e81dc9SJosef Bacik btrfs_node_key(eb, &disk_key, nr); 61407e81dc9SJosef Bacik btrfs_disk_key_to_cpu(key, &disk_key); 61507e81dc9SJosef Bacik } 61607e81dc9SJosef Bacik 61707e81dc9SJosef Bacik static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb, 61807e81dc9SJosef Bacik struct btrfs_key *key, int nr) 61907e81dc9SJosef Bacik { 62007e81dc9SJosef Bacik struct btrfs_disk_key disk_key; 62107e81dc9SJosef Bacik 62207e81dc9SJosef Bacik btrfs_item_key(eb, &disk_key, nr); 62307e81dc9SJosef Bacik btrfs_disk_key_to_cpu(key, &disk_key); 62407e81dc9SJosef Bacik } 62507e81dc9SJosef Bacik 62607e81dc9SJosef Bacik static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb, 62707e81dc9SJosef Bacik const struct btrfs_dir_item *item, 62807e81dc9SJosef Bacik struct btrfs_key *key) 62907e81dc9SJosef Bacik { 63007e81dc9SJosef Bacik struct btrfs_disk_key disk_key; 63107e81dc9SJosef Bacik 63207e81dc9SJosef Bacik btrfs_dir_item_key(eb, item, &disk_key); 63307e81dc9SJosef Bacik btrfs_disk_key_to_cpu(key, &disk_key); 63407e81dc9SJosef Bacik } 63507e81dc9SJosef Bacik 63607e81dc9SJosef Bacik #endif 63707e81dc9SJosef Bacik 63807e81dc9SJosef Bacik /* struct btrfs_header */ 63907e81dc9SJosef Bacik BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); 64007e81dc9SJosef Bacik BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, generation, 64); 64107e81dc9SJosef Bacik BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); 64207e81dc9SJosef Bacik BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); 64307e81dc9SJosef Bacik BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); 64407e81dc9SJosef Bacik BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); 64507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, 64607e81dc9SJosef Bacik generation, 64); 64707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); 64807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, nritems, 32); 64907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); 65007e81dc9SJosef Bacik 65107e81dc9SJosef Bacik static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag) 65207e81dc9SJosef Bacik { 65307e81dc9SJosef Bacik return (btrfs_header_flags(eb) & flag) == flag; 65407e81dc9SJosef Bacik } 65507e81dc9SJosef Bacik 65607e81dc9SJosef Bacik static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag) 65707e81dc9SJosef Bacik { 65807e81dc9SJosef Bacik u64 flags = btrfs_header_flags(eb); 65907e81dc9SJosef Bacik 66007e81dc9SJosef Bacik btrfs_set_header_flags(eb, flags | flag); 66107e81dc9SJosef Bacik } 66207e81dc9SJosef Bacik 66307e81dc9SJosef Bacik static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag) 66407e81dc9SJosef Bacik { 66507e81dc9SJosef Bacik u64 flags = btrfs_header_flags(eb); 66607e81dc9SJosef Bacik 66707e81dc9SJosef Bacik btrfs_set_header_flags(eb, flags & ~flag); 66807e81dc9SJosef Bacik } 66907e81dc9SJosef Bacik 67007e81dc9SJosef Bacik static inline int btrfs_header_backref_rev(const struct extent_buffer *eb) 67107e81dc9SJosef Bacik { 67207e81dc9SJosef Bacik u64 flags = btrfs_header_flags(eb); 67307e81dc9SJosef Bacik 67407e81dc9SJosef Bacik return flags >> BTRFS_BACKREF_REV_SHIFT; 67507e81dc9SJosef Bacik } 67607e81dc9SJosef Bacik 67707e81dc9SJosef Bacik static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb, int rev) 67807e81dc9SJosef Bacik { 67907e81dc9SJosef Bacik u64 flags = btrfs_header_flags(eb); 68007e81dc9SJosef Bacik 68107e81dc9SJosef Bacik flags &= ~BTRFS_BACKREF_REV_MASK; 68207e81dc9SJosef Bacik flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT; 68307e81dc9SJosef Bacik btrfs_set_header_flags(eb, flags); 68407e81dc9SJosef Bacik } 68507e81dc9SJosef Bacik 68607e81dc9SJosef Bacik static inline int btrfs_is_leaf(const struct extent_buffer *eb) 68707e81dc9SJosef Bacik { 68807e81dc9SJosef Bacik return btrfs_header_level(eb) == 0; 68907e81dc9SJosef Bacik } 69007e81dc9SJosef Bacik 69107e81dc9SJosef Bacik /* struct btrfs_root_item */ 69207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item, generation, 64); 69307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); 69407e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); 69507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); 69607e81dc9SJosef Bacik 69707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item, generation, 64); 69807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); 69907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_drop_level, struct btrfs_root_item, drop_level, 8); 70007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); 70107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); 70207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); 70307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64); 70407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); 70507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); 70607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item, 70707e81dc9SJosef Bacik last_snapshot, 64); 70807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item, 70907e81dc9SJosef Bacik generation_v2, 64); 71007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item, ctransid, 64); 71107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item, otransid, 64); 71207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item, stransid, 64); 71307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, rtransid, 64); 71407e81dc9SJosef Bacik 71507e81dc9SJosef Bacik /* struct btrfs_root_backup */ 71607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup, 71707e81dc9SJosef Bacik tree_root, 64); 71807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup, 71907e81dc9SJosef Bacik tree_root_gen, 64); 72007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup, 72107e81dc9SJosef Bacik tree_root_level, 8); 72207e81dc9SJosef Bacik 72307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup, 72407e81dc9SJosef Bacik chunk_root, 64); 72507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup, 72607e81dc9SJosef Bacik chunk_root_gen, 64); 72707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup, 72807e81dc9SJosef Bacik chunk_root_level, 8); 72907e81dc9SJosef Bacik 73007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup, 73107e81dc9SJosef Bacik extent_root, 64); 73207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup, 73307e81dc9SJosef Bacik extent_root_gen, 64); 73407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup, 73507e81dc9SJosef Bacik extent_root_level, 8); 73607e81dc9SJosef Bacik 73707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup, 73807e81dc9SJosef Bacik fs_root, 64); 73907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup, 74007e81dc9SJosef Bacik fs_root_gen, 64); 74107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup, 74207e81dc9SJosef Bacik fs_root_level, 8); 74307e81dc9SJosef Bacik 74407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup, 74507e81dc9SJosef Bacik dev_root, 64); 74607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup, 74707e81dc9SJosef Bacik dev_root_gen, 64); 74807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup, 74907e81dc9SJosef Bacik dev_root_level, 8); 75007e81dc9SJosef Bacik 75107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup, 75207e81dc9SJosef Bacik csum_root, 64); 75307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup, 75407e81dc9SJosef Bacik csum_root_gen, 64); 75507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup, 75607e81dc9SJosef Bacik csum_root_level, 8); 75707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup, 75807e81dc9SJosef Bacik total_bytes, 64); 75907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup, 76007e81dc9SJosef Bacik bytes_used, 64); 76107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup, 76207e81dc9SJosef Bacik num_devices, 64); 76307e81dc9SJosef Bacik 76407e81dc9SJosef Bacik /* struct btrfs_balance_item */ 76507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64); 76607e81dc9SJosef Bacik 76707e81dc9SJosef Bacik static inline void btrfs_balance_data(const struct extent_buffer *eb, 76807e81dc9SJosef Bacik const struct btrfs_balance_item *bi, 76907e81dc9SJosef Bacik struct btrfs_disk_balance_args *ba) 77007e81dc9SJosef Bacik { 77107e81dc9SJosef Bacik read_eb_member(eb, bi, struct btrfs_balance_item, data, ba); 77207e81dc9SJosef Bacik } 77307e81dc9SJosef Bacik 77407e81dc9SJosef Bacik static inline void btrfs_set_balance_data(struct extent_buffer *eb, 77507e81dc9SJosef Bacik struct btrfs_balance_item *bi, 77607e81dc9SJosef Bacik const struct btrfs_disk_balance_args *ba) 77707e81dc9SJosef Bacik { 77807e81dc9SJosef Bacik write_eb_member(eb, bi, struct btrfs_balance_item, data, ba); 77907e81dc9SJosef Bacik } 78007e81dc9SJosef Bacik 78107e81dc9SJosef Bacik static inline void btrfs_balance_meta(const struct extent_buffer *eb, 78207e81dc9SJosef Bacik const struct btrfs_balance_item *bi, 78307e81dc9SJosef Bacik struct btrfs_disk_balance_args *ba) 78407e81dc9SJosef Bacik { 78507e81dc9SJosef Bacik read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); 78607e81dc9SJosef Bacik } 78707e81dc9SJosef Bacik 78807e81dc9SJosef Bacik static inline void btrfs_set_balance_meta(struct extent_buffer *eb, 78907e81dc9SJosef Bacik struct btrfs_balance_item *bi, 79007e81dc9SJosef Bacik const struct btrfs_disk_balance_args *ba) 79107e81dc9SJosef Bacik { 79207e81dc9SJosef Bacik write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba); 79307e81dc9SJosef Bacik } 79407e81dc9SJosef Bacik 79507e81dc9SJosef Bacik static inline void btrfs_balance_sys(const struct extent_buffer *eb, 79607e81dc9SJosef Bacik const struct btrfs_balance_item *bi, 79707e81dc9SJosef Bacik struct btrfs_disk_balance_args *ba) 79807e81dc9SJosef Bacik { 79907e81dc9SJosef Bacik read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); 80007e81dc9SJosef Bacik } 80107e81dc9SJosef Bacik 80207e81dc9SJosef Bacik static inline void btrfs_set_balance_sys(struct extent_buffer *eb, 80307e81dc9SJosef Bacik struct btrfs_balance_item *bi, 80407e81dc9SJosef Bacik const struct btrfs_disk_balance_args *ba) 80507e81dc9SJosef Bacik { 80607e81dc9SJosef Bacik write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba); 80707e81dc9SJosef Bacik } 80807e81dc9SJosef Bacik 80907e81dc9SJosef Bacik static inline void btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu, 81007e81dc9SJosef Bacik const struct btrfs_disk_balance_args *disk) 81107e81dc9SJosef Bacik { 81207e81dc9SJosef Bacik memset(cpu, 0, sizeof(*cpu)); 81307e81dc9SJosef Bacik 81407e81dc9SJosef Bacik cpu->profiles = le64_to_cpu(disk->profiles); 81507e81dc9SJosef Bacik cpu->usage = le64_to_cpu(disk->usage); 81607e81dc9SJosef Bacik cpu->devid = le64_to_cpu(disk->devid); 81707e81dc9SJosef Bacik cpu->pstart = le64_to_cpu(disk->pstart); 81807e81dc9SJosef Bacik cpu->pend = le64_to_cpu(disk->pend); 81907e81dc9SJosef Bacik cpu->vstart = le64_to_cpu(disk->vstart); 82007e81dc9SJosef Bacik cpu->vend = le64_to_cpu(disk->vend); 82107e81dc9SJosef Bacik cpu->target = le64_to_cpu(disk->target); 82207e81dc9SJosef Bacik cpu->flags = le64_to_cpu(disk->flags); 82307e81dc9SJosef Bacik cpu->limit = le64_to_cpu(disk->limit); 82407e81dc9SJosef Bacik cpu->stripes_min = le32_to_cpu(disk->stripes_min); 82507e81dc9SJosef Bacik cpu->stripes_max = le32_to_cpu(disk->stripes_max); 82607e81dc9SJosef Bacik } 82707e81dc9SJosef Bacik 82807e81dc9SJosef Bacik static inline void btrfs_cpu_balance_args_to_disk( 82907e81dc9SJosef Bacik struct btrfs_disk_balance_args *disk, 83007e81dc9SJosef Bacik const struct btrfs_balance_args *cpu) 83107e81dc9SJosef Bacik { 83207e81dc9SJosef Bacik memset(disk, 0, sizeof(*disk)); 83307e81dc9SJosef Bacik 83407e81dc9SJosef Bacik disk->profiles = cpu_to_le64(cpu->profiles); 83507e81dc9SJosef Bacik disk->usage = cpu_to_le64(cpu->usage); 83607e81dc9SJosef Bacik disk->devid = cpu_to_le64(cpu->devid); 83707e81dc9SJosef Bacik disk->pstart = cpu_to_le64(cpu->pstart); 83807e81dc9SJosef Bacik disk->pend = cpu_to_le64(cpu->pend); 83907e81dc9SJosef Bacik disk->vstart = cpu_to_le64(cpu->vstart); 84007e81dc9SJosef Bacik disk->vend = cpu_to_le64(cpu->vend); 84107e81dc9SJosef Bacik disk->target = cpu_to_le64(cpu->target); 84207e81dc9SJosef Bacik disk->flags = cpu_to_le64(cpu->flags); 84307e81dc9SJosef Bacik disk->limit = cpu_to_le64(cpu->limit); 84407e81dc9SJosef Bacik disk->stripes_min = cpu_to_le32(cpu->stripes_min); 84507e81dc9SJosef Bacik disk->stripes_max = cpu_to_le32(cpu->stripes_max); 84607e81dc9SJosef Bacik } 84707e81dc9SJosef Bacik 84807e81dc9SJosef Bacik /* struct btrfs_super_block */ 84907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); 85007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64); 85107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, 85207e81dc9SJosef Bacik generation, 64); 85307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); 85407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_sys_array_size, 85507e81dc9SJosef Bacik struct btrfs_super_block, sys_chunk_array_size, 32); 85607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation, 85707e81dc9SJosef Bacik struct btrfs_super_block, chunk_root_generation, 64); 85807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, 85907e81dc9SJosef Bacik root_level, 8); 86007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block, 86107e81dc9SJosef Bacik chunk_root, 64); 86207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block, 86307e81dc9SJosef Bacik chunk_root_level, 8); 86407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, log_root, 64); 86507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block, 86607e81dc9SJosef Bacik log_root_level, 8); 86707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, 86807e81dc9SJosef Bacik total_bytes, 64); 86907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, 87007e81dc9SJosef Bacik bytes_used, 64); 87107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, 87207e81dc9SJosef Bacik sectorsize, 32); 87307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, 87407e81dc9SJosef Bacik nodesize, 32); 87507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, 87607e81dc9SJosef Bacik stripesize, 32); 87707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, 87807e81dc9SJosef Bacik root_dir_objectid, 64); 87907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, 88007e81dc9SJosef Bacik num_devices, 64); 88107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, 88207e81dc9SJosef Bacik compat_flags, 64); 88307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, 88407e81dc9SJosef Bacik compat_ro_flags, 64); 88507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, 88607e81dc9SJosef Bacik incompat_flags, 64); 88707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, 88807e81dc9SJosef Bacik csum_type, 16); 88907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, 89007e81dc9SJosef Bacik cache_generation, 64); 89107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64); 89207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, 89307e81dc9SJosef Bacik uuid_tree_generation, 64); 89407e81dc9SJosef Bacik 89507e81dc9SJosef Bacik /* struct btrfs_file_extent_item */ 89607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, 89707e81dc9SJosef Bacik type, 8); 89807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr, 89907e81dc9SJosef Bacik struct btrfs_file_extent_item, disk_bytenr, 64); 90007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset, 90107e81dc9SJosef Bacik struct btrfs_file_extent_item, offset, 64); 90207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation, 90307e81dc9SJosef Bacik struct btrfs_file_extent_item, generation, 64); 90407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes, 90507e81dc9SJosef Bacik struct btrfs_file_extent_item, num_bytes, 64); 90607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes, 90707e81dc9SJosef Bacik struct btrfs_file_extent_item, ram_bytes, 64); 90807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes, 90907e81dc9SJosef Bacik struct btrfs_file_extent_item, disk_num_bytes, 64); 91007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, 91107e81dc9SJosef Bacik struct btrfs_file_extent_item, compression, 8); 91207e81dc9SJosef Bacik 91307e81dc9SJosef Bacik 91407e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); 91507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, 91607e81dc9SJosef Bacik disk_bytenr, 64); 91707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, 91807e81dc9SJosef Bacik generation, 64); 91907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, 92007e81dc9SJosef Bacik disk_num_bytes, 64); 92107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, 92207e81dc9SJosef Bacik offset, 64); 92307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, 92407e81dc9SJosef Bacik num_bytes, 64); 92507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item, 92607e81dc9SJosef Bacik ram_bytes, 64); 92707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item, 92807e81dc9SJosef Bacik compression, 8); 92907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, 93007e81dc9SJosef Bacik encryption, 8); 93107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, 93207e81dc9SJosef Bacik other_encoding, 16); 93307e81dc9SJosef Bacik 93407e81dc9SJosef Bacik /* btrfs_qgroup_status_item */ 93507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, 93607e81dc9SJosef Bacik generation, 64); 93707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, 93807e81dc9SJosef Bacik version, 64); 93907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item, 94007e81dc9SJosef Bacik flags, 64); 94107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item, 94207e81dc9SJosef Bacik rescan, 64); 94307e81dc9SJosef Bacik 94407e81dc9SJosef Bacik /* btrfs_qgroup_info_item */ 94507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item, 94607e81dc9SJosef Bacik generation, 64); 94707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64); 94807e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item, 94907e81dc9SJosef Bacik rfer_cmpr, 64); 95007e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64); 95107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item, 95207e81dc9SJosef Bacik excl_cmpr, 64); 95307e81dc9SJosef Bacik 95407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation, 95507e81dc9SJosef Bacik struct btrfs_qgroup_info_item, generation, 64); 95607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item, 95707e81dc9SJosef Bacik rfer, 64); 95807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr, 95907e81dc9SJosef Bacik struct btrfs_qgroup_info_item, rfer_cmpr, 64); 96007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item, 96107e81dc9SJosef Bacik excl, 64); 96207e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr, 96307e81dc9SJosef Bacik struct btrfs_qgroup_info_item, excl_cmpr, 64); 96407e81dc9SJosef Bacik 96507e81dc9SJosef Bacik /* btrfs_qgroup_limit_item */ 96607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, flags, 64); 96707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item, 96807e81dc9SJosef Bacik max_rfer, 64); 96907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item, 97007e81dc9SJosef Bacik max_excl, 64); 97107e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item, 97207e81dc9SJosef Bacik rsv_rfer, 64); 97307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item, 97407e81dc9SJosef Bacik rsv_excl, 64); 97507e81dc9SJosef Bacik 97607e81dc9SJosef Bacik /* btrfs_dev_replace_item */ 97707e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_replace_src_devid, 97807e81dc9SJosef Bacik struct btrfs_dev_replace_item, src_devid, 64); 97907e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_replace_cont_reading_from_srcdev_mode, 98007e81dc9SJosef Bacik struct btrfs_dev_replace_item, cont_reading_from_srcdev_mode, 98107e81dc9SJosef Bacik 64); 98207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_replace_replace_state, struct btrfs_dev_replace_item, 98307e81dc9SJosef Bacik replace_state, 64); 98407e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_replace_time_started, struct btrfs_dev_replace_item, 98507e81dc9SJosef Bacik time_started, 64); 98607e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_replace_time_stopped, struct btrfs_dev_replace_item, 98707e81dc9SJosef Bacik time_stopped, 64); 98807e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_replace_num_write_errors, struct btrfs_dev_replace_item, 98907e81dc9SJosef Bacik num_write_errors, 64); 99007e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_replace_num_uncorrectable_read_errors, 99107e81dc9SJosef Bacik struct btrfs_dev_replace_item, num_uncorrectable_read_errors, 99207e81dc9SJosef Bacik 64); 99307e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_replace_cursor_left, struct btrfs_dev_replace_item, 99407e81dc9SJosef Bacik cursor_left, 64); 99507e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(dev_replace_cursor_right, struct btrfs_dev_replace_item, 99607e81dc9SJosef Bacik cursor_right, 64); 99707e81dc9SJosef Bacik 99807e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_src_devid, 99907e81dc9SJosef Bacik struct btrfs_dev_replace_item, src_devid, 64); 100007e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cont_reading_from_srcdev_mode, 100107e81dc9SJosef Bacik struct btrfs_dev_replace_item, 100207e81dc9SJosef Bacik cont_reading_from_srcdev_mode, 64); 100307e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_replace_state, 100407e81dc9SJosef Bacik struct btrfs_dev_replace_item, replace_state, 64); 100507e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_started, 100607e81dc9SJosef Bacik struct btrfs_dev_replace_item, time_started, 64); 100707e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_stopped, 100807e81dc9SJosef Bacik struct btrfs_dev_replace_item, time_stopped, 64); 100907e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_write_errors, 101007e81dc9SJosef Bacik struct btrfs_dev_replace_item, num_write_errors, 64); 101107e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_uncorrectable_read_errors, 101207e81dc9SJosef Bacik struct btrfs_dev_replace_item, 101307e81dc9SJosef Bacik num_uncorrectable_read_errors, 64); 101407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left, 101507e81dc9SJosef Bacik struct btrfs_dev_replace_item, cursor_left, 64); 101607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right, 101707e81dc9SJosef Bacik struct btrfs_dev_replace_item, cursor_right, 64); 101807e81dc9SJosef Bacik 101907e81dc9SJosef Bacik /* btrfs_verity_descriptor_item */ 102007e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(verity_descriptor_encryption, struct btrfs_verity_descriptor_item, 102107e81dc9SJosef Bacik encryption, 8); 102207e81dc9SJosef Bacik BTRFS_SETGET_FUNCS(verity_descriptor_size, struct btrfs_verity_descriptor_item, 102307e81dc9SJosef Bacik size, 64); 102407e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_encryption, 102507e81dc9SJosef Bacik struct btrfs_verity_descriptor_item, encryption, 8); 102607e81dc9SJosef Bacik BTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_size, 102707e81dc9SJosef Bacik struct btrfs_verity_descriptor_item, size, 64); 102807e81dc9SJosef Bacik 102907e81dc9SJosef Bacik /* Cast into the data area of the leaf. */ 103007e81dc9SJosef Bacik #define btrfs_item_ptr(leaf, slot, type) \ 103107e81dc9SJosef Bacik ((type *)(BTRFS_LEAF_DATA_OFFSET + btrfs_item_offset(leaf, slot))) 103207e81dc9SJosef Bacik 103307e81dc9SJosef Bacik #define btrfs_item_ptr_offset(leaf, slot) \ 103407e81dc9SJosef Bacik ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + btrfs_item_offset(leaf, slot))) 103507e81dc9SJosef Bacik 1036ad1ac501SJosef Bacik #endif 1037