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