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