LCOV - code coverage report
Current view: top level - fs/btrfs - accessors.h (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc4-xfsa @ Mon Jul 31 20:08:27 PDT 2023 Lines: 7 367 1.9 %
Date: 2023-07-31 20:08:27 Functions: 0 9 0.0 %

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

Generated by: LCOV version 1.14