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