1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef BTRFS_ACCESSORS_H
4 #define BTRFS_ACCESSORS_H
6 #include <linux/stddef.h>
8 struct btrfs_map_token {
9 struct extent_buffer *eb;
14 void btrfs_init_map_token(struct btrfs_map_token *token, struct extent_buffer *eb);
17 * Some macros to generate set/get functions for the struct fields. This
18 * assumes there is a lefoo_to_cpu for every type, so lets make a simple one
21 #define le8_to_cpu(v) (v)
22 #define cpu_to_le8(v) (v)
25 static inline u8 get_unaligned_le8(const void *p)
30 static inline void put_unaligned_le8(u8 val, void *p)
35 #define read_eb_member(eb, ptr, type, member, result) (\
36 read_extent_buffer(eb, (char *)(result), \
37 ((unsigned long)(ptr)) + \
38 offsetof(type, member), \
39 sizeof_field(type, member)))
41 #define write_eb_member(eb, ptr, type, member, result) (\
42 write_extent_buffer(eb, (char *)(result), \
43 ((unsigned long)(ptr)) + \
44 offsetof(type, member), \
45 sizeof_field(type, member)))
47 #define DECLARE_BTRFS_SETGET_BITS(bits) \
48 u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
49 const void *ptr, unsigned long off); \
50 void btrfs_set_token_##bits(struct btrfs_map_token *token, \
51 const void *ptr, unsigned long off, \
53 u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
54 const void *ptr, unsigned long off); \
55 void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
56 unsigned long off, u##bits val);
58 DECLARE_BTRFS_SETGET_BITS(8)
59 DECLARE_BTRFS_SETGET_BITS(16)
60 DECLARE_BTRFS_SETGET_BITS(32)
61 DECLARE_BTRFS_SETGET_BITS(64)
63 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
64 static inline u##bits btrfs_##name(const struct extent_buffer *eb, \
67 static_assert(sizeof(u##bits) == sizeof_field(type, member)); \
68 return btrfs_get_##bits(eb, s, offsetof(type, member)); \
70 static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \
73 static_assert(sizeof(u##bits) == sizeof_field(type, member)); \
74 btrfs_set_##bits(eb, s, offsetof(type, member), val); \
76 static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \
79 static_assert(sizeof(u##bits) == sizeof_field(type, member)); \
80 return btrfs_get_token_##bits(token, s, offsetof(type, member));\
82 static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\
83 type *s, u##bits val) \
85 static_assert(sizeof(u##bits) == sizeof_field(type, member)); \
86 btrfs_set_token_##bits(token, s, offsetof(type, member), val); \
89 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
90 static inline u##bits btrfs_##name(const struct extent_buffer *eb) \
92 const type *p = page_address(eb->pages[0]) + \
93 offset_in_page(eb->start); \
94 return get_unaligned_le##bits(&p->member); \
96 static inline void btrfs_set_##name(const struct extent_buffer *eb, \
99 type *p = page_address(eb->pages[0]) + offset_in_page(eb->start); \
100 put_unaligned_le##bits(val, &p->member); \
103 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
104 static inline u##bits btrfs_##name(const type *s) \
106 return get_unaligned_le##bits(&s->member); \
108 static inline void btrfs_set_##name(type *s, u##bits val) \
110 put_unaligned_le##bits(val, &s->member); \
113 static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
114 struct btrfs_dev_item *s)
116 static_assert(sizeof(u64) == sizeof_field(struct btrfs_dev_item, total_bytes));
117 return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes));
119 static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb,
120 struct btrfs_dev_item *s,
123 static_assert(sizeof(u64) == sizeof_field(struct btrfs_dev_item, total_bytes));
124 WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize));
125 btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val);
128 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
129 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
130 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
131 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
132 BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item, start_offset, 64);
133 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
134 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
135 BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
136 BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
137 BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
138 BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
140 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
141 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
143 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
145 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
147 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
149 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
151 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
152 BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item, dev_group, 32);
153 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
155 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
157 BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
160 static inline unsigned long btrfs_device_uuid(struct btrfs_dev_item *d)
162 return (unsigned long)d + offsetof(struct btrfs_dev_item, uuid);
165 static inline unsigned long btrfs_device_fsid(struct btrfs_dev_item *d)
167 return (unsigned long)d + offsetof(struct btrfs_dev_item, fsid);
170 BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
171 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
172 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
173 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
174 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
175 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
176 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
177 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
178 BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
179 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
180 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
182 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
184 return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
187 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
188 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
189 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
191 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk, io_align, 32);
192 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk, io_width, 32);
193 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
195 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
196 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
198 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
200 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
201 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
203 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c, int nr)
205 unsigned long offset = (unsigned long)c;
207 offset += offsetof(struct btrfs_chunk, stripe);
208 offset += nr * sizeof(struct btrfs_stripe);
209 return (struct btrfs_stripe *)offset;
212 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
214 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
217 static inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb,
218 struct btrfs_chunk *c, int nr)
220 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
223 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
224 struct btrfs_chunk *c, int nr,
227 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
230 static inline u64 btrfs_stripe_devid_nr(const struct extent_buffer *eb,
231 struct btrfs_chunk *c, int nr)
233 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
236 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
237 struct btrfs_chunk *c, int nr,
240 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
243 /* struct btrfs_block_group_item */
244 BTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item,
246 BTRFS_SETGET_FUNCS(block_group_used, struct btrfs_block_group_item, used, 64);
247 BTRFS_SETGET_STACK_FUNCS(stack_block_group_chunk_objectid,
248 struct btrfs_block_group_item, chunk_objectid, 64);
250 BTRFS_SETGET_FUNCS(block_group_chunk_objectid,
251 struct btrfs_block_group_item, chunk_objectid, 64);
252 BTRFS_SETGET_FUNCS(block_group_flags, struct btrfs_block_group_item, flags, 64);
253 BTRFS_SETGET_STACK_FUNCS(stack_block_group_flags,
254 struct btrfs_block_group_item, flags, 64);
256 /* struct btrfs_free_space_info */
257 BTRFS_SETGET_FUNCS(free_space_extent_count, struct btrfs_free_space_info,
259 BTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32);
261 /* struct btrfs_inode_ref */
262 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
263 BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
264 BTRFS_SETGET_STACK_FUNCS(stack_inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
265 BTRFS_SETGET_STACK_FUNCS(stack_inode_ref_index, struct btrfs_inode_ref, index, 64);
267 /* struct btrfs_inode_extref */
268 BTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref,
269 parent_objectid, 64);
270 BTRFS_SETGET_FUNCS(inode_extref_name_len, struct btrfs_inode_extref,
272 BTRFS_SETGET_FUNCS(inode_extref_index, struct btrfs_inode_extref, index, 64);
274 /* struct btrfs_inode_item */
275 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
276 BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
277 BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
278 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
279 BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
280 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
281 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
282 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
283 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
284 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
285 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
286 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
287 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation, struct btrfs_inode_item,
289 BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, struct btrfs_inode_item,
291 BTRFS_SETGET_STACK_FUNCS(stack_inode_transid, struct btrfs_inode_item,
293 BTRFS_SETGET_STACK_FUNCS(stack_inode_size, struct btrfs_inode_item, size, 64);
294 BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, struct btrfs_inode_item, nbytes, 64);
295 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, struct btrfs_inode_item,
297 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, struct btrfs_inode_item, nlink, 32);
298 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid, struct btrfs_inode_item, uid, 32);
299 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid, struct btrfs_inode_item, gid, 32);
300 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode, struct btrfs_inode_item, mode, 32);
301 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, struct btrfs_inode_item, rdev, 64);
302 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags, struct btrfs_inode_item, flags, 64);
303 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
304 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
305 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64);
306 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32);
308 /* struct btrfs_dev_extent */
309 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, chunk_tree, 64);
310 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
312 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
314 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
315 BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_tree, struct btrfs_dev_extent,
317 BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_objectid, struct btrfs_dev_extent,
319 BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_offset, struct btrfs_dev_extent,
321 BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_length, struct btrfs_dev_extent, length, 64);
323 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64);
324 BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, generation, 64);
325 BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64);
327 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
329 static inline void btrfs_tree_block_key(const struct extent_buffer *eb,
330 struct btrfs_tree_block_info *item,
331 struct btrfs_disk_key *key)
333 read_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
336 static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb,
337 struct btrfs_tree_block_info *item,
338 struct btrfs_disk_key *key)
340 write_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
343 BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref, root, 64);
344 BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref,
346 BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref,
348 BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref, count, 32);
350 BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref, count, 32);
352 BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref,
354 BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref,
357 static inline u32 btrfs_extent_inline_ref_size(int type)
359 if (type == BTRFS_TREE_BLOCK_REF_KEY ||
360 type == BTRFS_SHARED_BLOCK_REF_KEY)
361 return sizeof(struct btrfs_extent_inline_ref);
362 if (type == BTRFS_SHARED_DATA_REF_KEY)
363 return sizeof(struct btrfs_shared_data_ref) +
364 sizeof(struct btrfs_extent_inline_ref);
365 if (type == BTRFS_EXTENT_DATA_REF_KEY)
366 return sizeof(struct btrfs_extent_data_ref) +
367 offsetof(struct btrfs_extent_inline_ref, offset);
371 /* struct btrfs_node */
372 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
373 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
374 BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr, blockptr, 64);
375 BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr,
378 static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr)
382 ptr = offsetof(struct btrfs_node, ptrs) +
383 sizeof(struct btrfs_key_ptr) * nr;
384 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
387 static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb,
392 ptr = offsetof(struct btrfs_node, ptrs) +
393 sizeof(struct btrfs_key_ptr) * nr;
394 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
397 static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr)
401 ptr = offsetof(struct btrfs_node, ptrs) +
402 sizeof(struct btrfs_key_ptr) * nr;
403 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
406 static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb,
411 ptr = offsetof(struct btrfs_node, ptrs) +
412 sizeof(struct btrfs_key_ptr) * nr;
413 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
416 static inline unsigned long btrfs_node_key_ptr_offset(const struct extent_buffer *eb, int nr)
418 return offsetof(struct btrfs_node, ptrs) +
419 sizeof(struct btrfs_key_ptr) * nr;
422 void btrfs_node_key(const struct extent_buffer *eb,
423 struct btrfs_disk_key *disk_key, int nr);
425 static inline void btrfs_set_node_key(const struct extent_buffer *eb,
426 struct btrfs_disk_key *disk_key, int nr)
430 ptr = btrfs_node_key_ptr_offset(eb, nr);
431 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
432 struct btrfs_key_ptr, key, disk_key);
435 /* struct btrfs_item */
436 BTRFS_SETGET_FUNCS(raw_item_offset, struct btrfs_item, offset, 32);
437 BTRFS_SETGET_FUNCS(raw_item_size, struct btrfs_item, size, 32);
438 BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32);
439 BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32);
441 static inline unsigned long btrfs_item_nr_offset(const struct extent_buffer *eb, int nr)
443 return offsetof(struct btrfs_leaf, items) +
444 sizeof(struct btrfs_item) * nr;
447 static inline struct btrfs_item *btrfs_item_nr(const struct extent_buffer *eb, int nr)
449 return (struct btrfs_item *)btrfs_item_nr_offset(eb, nr);
452 #define BTRFS_ITEM_SETGET_FUNCS(member) \
453 static inline u32 btrfs_item_##member(const struct extent_buffer *eb, int slot) \
455 return btrfs_raw_item_##member(eb, btrfs_item_nr(eb, slot)); \
457 static inline void btrfs_set_item_##member(const struct extent_buffer *eb, \
460 btrfs_set_raw_item_##member(eb, btrfs_item_nr(eb, slot), val); \
462 static inline u32 btrfs_token_item_##member(struct btrfs_map_token *token, \
465 struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \
466 return btrfs_token_raw_item_##member(token, item); \
468 static inline void btrfs_set_token_item_##member(struct btrfs_map_token *token, \
471 struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \
472 btrfs_set_token_raw_item_##member(token, item, val); \
475 BTRFS_ITEM_SETGET_FUNCS(offset)
476 BTRFS_ITEM_SETGET_FUNCS(size);
478 static inline u32 btrfs_item_data_end(const struct extent_buffer *eb, int nr)
480 return btrfs_item_offset(eb, nr) + btrfs_item_size(eb, nr);
483 static inline void btrfs_item_key(const struct extent_buffer *eb,
484 struct btrfs_disk_key *disk_key, int nr)
486 struct btrfs_item *item = btrfs_item_nr(eb, nr);
488 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
491 static inline void btrfs_set_item_key(struct extent_buffer *eb,
492 struct btrfs_disk_key *disk_key, int nr)
494 struct btrfs_item *item = btrfs_item_nr(eb, nr);
496 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
499 BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);
501 /* struct btrfs_root_ref */
502 BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
503 BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
504 BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
505 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_dirid, struct btrfs_root_ref, dirid, 64);
506 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence, struct btrfs_root_ref, sequence, 64);
507 BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_len, 16);
509 /* struct btrfs_dir_item */
510 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
511 BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, type, 8);
512 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
513 BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
514 BTRFS_SETGET_STACK_FUNCS(stack_dir_flags, struct btrfs_dir_item, type, 8);
515 BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, data_len, 16);
516 BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16);
517 BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, transid, 64);
519 static inline u8 btrfs_dir_ftype(const struct extent_buffer *eb,
520 const struct btrfs_dir_item *item)
522 return btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, item));
525 static inline u8 btrfs_stack_dir_ftype(const struct btrfs_dir_item *item)
527 return btrfs_dir_flags_to_ftype(btrfs_stack_dir_flags(item));
530 static inline void btrfs_dir_item_key(const struct extent_buffer *eb,
531 const struct btrfs_dir_item *item,
532 struct btrfs_disk_key *key)
534 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
537 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
538 struct btrfs_dir_item *item,
539 const struct btrfs_disk_key *key)
541 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
544 BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header,
546 BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header,
548 BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header,
551 static inline void btrfs_free_space_key(const struct extent_buffer *eb,
552 const struct btrfs_free_space_header *h,
553 struct btrfs_disk_key *key)
555 read_eb_member(eb, h, struct btrfs_free_space_header, location, key);
558 static inline void btrfs_set_free_space_key(struct extent_buffer *eb,
559 struct btrfs_free_space_header *h,
560 const struct btrfs_disk_key *key)
562 write_eb_member(eb, h, struct btrfs_free_space_header, location, key);
565 /* struct btrfs_disk_key */
566 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, objectid, 64);
567 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
568 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
570 #ifdef __LITTLE_ENDIAN
573 * Optimized helpers for little-endian architectures where CPU and on-disk
574 * structures have the same endianness and we can skip conversions.
577 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu_key,
578 const struct btrfs_disk_key *disk_key)
580 memcpy(cpu_key, disk_key, sizeof(struct btrfs_key));
583 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk_key,
584 const struct btrfs_key *cpu_key)
586 memcpy(disk_key, cpu_key, sizeof(struct btrfs_key));
589 static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb,
590 struct btrfs_key *cpu_key, int nr)
592 struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
594 btrfs_node_key(eb, disk_key, nr);
597 static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb,
598 struct btrfs_key *cpu_key, int nr)
600 struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
602 btrfs_item_key(eb, disk_key, nr);
605 static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
606 const struct btrfs_dir_item *item,
607 struct btrfs_key *cpu_key)
609 struct btrfs_disk_key *disk_key = (struct btrfs_disk_key *)cpu_key;
611 btrfs_dir_item_key(eb, item, disk_key);
616 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
617 const struct btrfs_disk_key *disk)
619 cpu->offset = le64_to_cpu(disk->offset);
620 cpu->type = disk->type;
621 cpu->objectid = le64_to_cpu(disk->objectid);
624 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
625 const struct btrfs_key *cpu)
627 disk->offset = cpu_to_le64(cpu->offset);
628 disk->type = cpu->type;
629 disk->objectid = cpu_to_le64(cpu->objectid);
632 static inline void btrfs_node_key_to_cpu(const struct extent_buffer *eb,
633 struct btrfs_key *key, int nr)
635 struct btrfs_disk_key disk_key;
637 btrfs_node_key(eb, &disk_key, nr);
638 btrfs_disk_key_to_cpu(key, &disk_key);
641 static inline void btrfs_item_key_to_cpu(const struct extent_buffer *eb,
642 struct btrfs_key *key, int nr)
644 struct btrfs_disk_key disk_key;
646 btrfs_item_key(eb, &disk_key, nr);
647 btrfs_disk_key_to_cpu(key, &disk_key);
650 static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
651 const struct btrfs_dir_item *item,
652 struct btrfs_key *key)
654 struct btrfs_disk_key disk_key;
656 btrfs_dir_item_key(eb, item, &disk_key);
657 btrfs_disk_key_to_cpu(key, &disk_key);
662 /* struct btrfs_header */
663 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
664 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, generation, 64);
665 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
666 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
667 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
668 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
669 BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header,
671 BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64);
672 BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, nritems, 32);
673 BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64);
675 static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag)
677 return (btrfs_header_flags(eb) & flag) == flag;
680 static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
682 u64 flags = btrfs_header_flags(eb);
684 btrfs_set_header_flags(eb, flags | flag);
687 static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
689 u64 flags = btrfs_header_flags(eb);
691 btrfs_set_header_flags(eb, flags & ~flag);
694 static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
696 u64 flags = btrfs_header_flags(eb);
698 return flags >> BTRFS_BACKREF_REV_SHIFT;
701 static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb, int rev)
703 u64 flags = btrfs_header_flags(eb);
705 flags &= ~BTRFS_BACKREF_REV_MASK;
706 flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
707 btrfs_set_header_flags(eb, flags);
710 static inline int btrfs_is_leaf(const struct extent_buffer *eb)
712 return btrfs_header_level(eb) == 0;
715 /* struct btrfs_root_item */
716 BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item, generation, 64);
717 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
718 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
719 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
721 BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item, generation, 64);
722 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
723 BTRFS_SETGET_STACK_FUNCS(root_drop_level, struct btrfs_root_item, drop_level, 8);
724 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
725 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
726 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
727 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
728 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
729 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
730 BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
732 BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item,
734 BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item, ctransid, 64);
735 BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item, otransid, 64);
736 BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item, stransid, 64);
737 BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, rtransid, 64);
739 /* struct btrfs_root_backup */
740 BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup,
742 BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup,
744 BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup,
747 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup,
749 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup,
751 BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup,
752 chunk_root_level, 8);
754 BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup,
756 BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup,
757 extent_root_gen, 64);
758 BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup,
759 extent_root_level, 8);
761 BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup,
763 BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup,
765 BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup,
768 BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup,
770 BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup,
772 BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup,
775 BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup,
777 BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup,
779 BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup,
781 BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup,
783 BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup,
785 BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup,
788 /* struct btrfs_balance_item */
789 BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64);
791 static inline void btrfs_balance_data(const struct extent_buffer *eb,
792 const struct btrfs_balance_item *bi,
793 struct btrfs_disk_balance_args *ba)
795 read_eb_member(eb, bi, struct btrfs_balance_item, data, ba);
798 static inline void btrfs_set_balance_data(struct extent_buffer *eb,
799 struct btrfs_balance_item *bi,
800 const struct btrfs_disk_balance_args *ba)
802 write_eb_member(eb, bi, struct btrfs_balance_item, data, ba);
805 static inline void btrfs_balance_meta(const struct extent_buffer *eb,
806 const struct btrfs_balance_item *bi,
807 struct btrfs_disk_balance_args *ba)
809 read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba);
812 static inline void btrfs_set_balance_meta(struct extent_buffer *eb,
813 struct btrfs_balance_item *bi,
814 const struct btrfs_disk_balance_args *ba)
816 write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba);
819 static inline void btrfs_balance_sys(const struct extent_buffer *eb,
820 const struct btrfs_balance_item *bi,
821 struct btrfs_disk_balance_args *ba)
823 read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba);
826 static inline void btrfs_set_balance_sys(struct extent_buffer *eb,
827 struct btrfs_balance_item *bi,
828 const struct btrfs_disk_balance_args *ba)
830 write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba);
833 static inline void btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu,
834 const struct btrfs_disk_balance_args *disk)
836 memset(cpu, 0, sizeof(*cpu));
838 cpu->profiles = le64_to_cpu(disk->profiles);
839 cpu->usage = le64_to_cpu(disk->usage);
840 cpu->devid = le64_to_cpu(disk->devid);
841 cpu->pstart = le64_to_cpu(disk->pstart);
842 cpu->pend = le64_to_cpu(disk->pend);
843 cpu->vstart = le64_to_cpu(disk->vstart);
844 cpu->vend = le64_to_cpu(disk->vend);
845 cpu->target = le64_to_cpu(disk->target);
846 cpu->flags = le64_to_cpu(disk->flags);
847 cpu->limit = le64_to_cpu(disk->limit);
848 cpu->stripes_min = le32_to_cpu(disk->stripes_min);
849 cpu->stripes_max = le32_to_cpu(disk->stripes_max);
852 static inline void btrfs_cpu_balance_args_to_disk(
853 struct btrfs_disk_balance_args *disk,
854 const struct btrfs_balance_args *cpu)
856 memset(disk, 0, sizeof(*disk));
858 disk->profiles = cpu_to_le64(cpu->profiles);
859 disk->usage = cpu_to_le64(cpu->usage);
860 disk->devid = cpu_to_le64(cpu->devid);
861 disk->pstart = cpu_to_le64(cpu->pstart);
862 disk->pend = cpu_to_le64(cpu->pend);
863 disk->vstart = cpu_to_le64(cpu->vstart);
864 disk->vend = cpu_to_le64(cpu->vend);
865 disk->target = cpu_to_le64(cpu->target);
866 disk->flags = cpu_to_le64(cpu->flags);
867 disk->limit = cpu_to_le64(cpu->limit);
868 disk->stripes_min = cpu_to_le32(cpu->stripes_min);
869 disk->stripes_max = cpu_to_le32(cpu->stripes_max);
872 /* struct btrfs_super_block */
873 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
874 BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
875 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
877 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
878 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
879 struct btrfs_super_block, sys_chunk_array_size, 32);
880 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
881 struct btrfs_super_block, chunk_root_generation, 64);
882 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
884 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
886 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
887 chunk_root_level, 8);
888 BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, log_root, 64);
889 BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
891 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
893 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
895 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
897 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
899 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
901 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
902 root_dir_objectid, 64);
903 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
905 BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
907 BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
908 compat_ro_flags, 64);
909 BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
911 BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
913 BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
914 cache_generation, 64);
915 BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
916 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
917 uuid_tree_generation, 64);
918 BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block,
919 nr_global_roots, 64);
921 /* struct btrfs_file_extent_item */
922 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item,
924 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr,
925 struct btrfs_file_extent_item, disk_bytenr, 64);
926 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset,
927 struct btrfs_file_extent_item, offset, 64);
928 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation,
929 struct btrfs_file_extent_item, generation, 64);
930 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes,
931 struct btrfs_file_extent_item, num_bytes, 64);
932 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_ram_bytes,
933 struct btrfs_file_extent_item, ram_bytes, 64);
934 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes,
935 struct btrfs_file_extent_item, disk_num_bytes, 64);
936 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression,
937 struct btrfs_file_extent_item, compression, 8);
940 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
941 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
943 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
945 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
947 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
949 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
951 BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
953 BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
955 BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
957 BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
960 /* btrfs_qgroup_status_item */
961 BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item,
963 BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item,
965 BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item,
967 BTRFS_SETGET_FUNCS(qgroup_status_rescan, struct btrfs_qgroup_status_item,
970 /* btrfs_qgroup_info_item */
971 BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item,
973 BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64);
974 BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item,
976 BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64);
977 BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item,
980 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation,
981 struct btrfs_qgroup_info_item, generation, 64);
982 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item,
984 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr,
985 struct btrfs_qgroup_info_item, rfer_cmpr, 64);
986 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item,
988 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr,
989 struct btrfs_qgroup_info_item, excl_cmpr, 64);
991 /* btrfs_qgroup_limit_item */
992 BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, flags, 64);
993 BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item,
995 BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item,
997 BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item,
999 BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item,
1001 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_flags,
1002 struct btrfs_qgroup_limit_item, flags, 64);
1003 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_rfer,
1004 struct btrfs_qgroup_limit_item, max_rfer, 64);
1005 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_max_excl,
1006 struct btrfs_qgroup_limit_item, max_excl, 64);
1007 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_rfer,
1008 struct btrfs_qgroup_limit_item, rsv_rfer, 64);
1009 BTRFS_SETGET_STACK_FUNCS(stack_qgroup_limit_rsv_excl,
1010 struct btrfs_qgroup_limit_item, rsv_excl, 64);
1012 /* btrfs_dev_replace_item */
1013 BTRFS_SETGET_FUNCS(dev_replace_src_devid,
1014 struct btrfs_dev_replace_item, src_devid, 64);
1015 BTRFS_SETGET_FUNCS(dev_replace_cont_reading_from_srcdev_mode,
1016 struct btrfs_dev_replace_item, cont_reading_from_srcdev_mode,
1018 BTRFS_SETGET_FUNCS(dev_replace_replace_state, struct btrfs_dev_replace_item,
1020 BTRFS_SETGET_FUNCS(dev_replace_time_started, struct btrfs_dev_replace_item,
1022 BTRFS_SETGET_FUNCS(dev_replace_time_stopped, struct btrfs_dev_replace_item,
1024 BTRFS_SETGET_FUNCS(dev_replace_num_write_errors, struct btrfs_dev_replace_item,
1025 num_write_errors, 64);
1026 BTRFS_SETGET_FUNCS(dev_replace_num_uncorrectable_read_errors,
1027 struct btrfs_dev_replace_item, num_uncorrectable_read_errors,
1029 BTRFS_SETGET_FUNCS(dev_replace_cursor_left, struct btrfs_dev_replace_item,
1031 BTRFS_SETGET_FUNCS(dev_replace_cursor_right, struct btrfs_dev_replace_item,
1034 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_src_devid,
1035 struct btrfs_dev_replace_item, src_devid, 64);
1036 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cont_reading_from_srcdev_mode,
1037 struct btrfs_dev_replace_item,
1038 cont_reading_from_srcdev_mode, 64);
1039 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_replace_state,
1040 struct btrfs_dev_replace_item, replace_state, 64);
1041 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_started,
1042 struct btrfs_dev_replace_item, time_started, 64);
1043 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_time_stopped,
1044 struct btrfs_dev_replace_item, time_stopped, 64);
1045 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_write_errors,
1046 struct btrfs_dev_replace_item, num_write_errors, 64);
1047 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_num_uncorrectable_read_errors,
1048 struct btrfs_dev_replace_item,
1049 num_uncorrectable_read_errors, 64);
1050 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_left,
1051 struct btrfs_dev_replace_item, cursor_left, 64);
1052 BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right,
1053 struct btrfs_dev_replace_item, cursor_right, 64);
1055 /* btrfs_verity_descriptor_item */
1056 BTRFS_SETGET_FUNCS(verity_descriptor_encryption, struct btrfs_verity_descriptor_item,
1058 BTRFS_SETGET_FUNCS(verity_descriptor_size, struct btrfs_verity_descriptor_item,
1060 BTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_encryption,
1061 struct btrfs_verity_descriptor_item, encryption, 8);
1062 BTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_size,
1063 struct btrfs_verity_descriptor_item, size, 64);
1065 /* Cast into the data area of the leaf. */
1066 #define btrfs_item_ptr(leaf, slot, type) \
1067 ((type *)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot)))
1069 #define btrfs_item_ptr_offset(leaf, slot) \
1070 ((unsigned long)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot)))