BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32);
BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32);
-static inline unsigned long btrfs_item_nr_offset(int nr)
+static inline unsigned long btrfs_item_nr_offset(const struct extent_buffer *eb, int nr)
{
return offsetof(struct btrfs_leaf, items) +
sizeof(struct btrfs_item) * nr;
}
-static inline struct btrfs_item *btrfs_item_nr(int nr)
+static inline struct btrfs_item *btrfs_item_nr(const struct extent_buffer *eb, int nr)
{
- return (struct btrfs_item *)btrfs_item_nr_offset(nr);
+ return (struct btrfs_item *)btrfs_item_nr_offset(eb, nr);
}
#define BTRFS_ITEM_SETGET_FUNCS(member) \
static inline u32 btrfs_item_##member(const struct extent_buffer *eb, int slot) \
{ \
- return btrfs_raw_item_##member(eb, btrfs_item_nr(slot)); \
+ return btrfs_raw_item_##member(eb, btrfs_item_nr(eb, slot)); \
} \
static inline void btrfs_set_item_##member(const struct extent_buffer *eb, \
int slot, u32 val) \
{ \
- btrfs_set_raw_item_##member(eb, btrfs_item_nr(slot), val); \
+ btrfs_set_raw_item_##member(eb, btrfs_item_nr(eb, slot), val); \
} \
static inline u32 btrfs_token_item_##member(struct btrfs_map_token *token, \
int slot) \
{ \
- struct btrfs_item *item = btrfs_item_nr(slot); \
+ struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \
return btrfs_token_raw_item_##member(token, item); \
} \
static inline void btrfs_set_token_item_##member(struct btrfs_map_token *token, \
int slot, u32 val) \
{ \
- struct btrfs_item *item = btrfs_item_nr(slot); \
+ struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \
btrfs_set_token_raw_item_##member(token, item, val); \
}
static inline void btrfs_item_key(const struct extent_buffer *eb,
struct btrfs_disk_key *disk_key, int nr)
{
- struct btrfs_item *item = btrfs_item_nr(nr);
+ struct btrfs_item *item = btrfs_item_nr(eb, nr);
read_eb_member(eb, item, struct btrfs_item, key, disk_key);
}
static inline void btrfs_set_item_key(struct extent_buffer *eb,
struct btrfs_disk_key *disk_key, int nr)
{
- struct btrfs_item *item = btrfs_item_nr(nr);
+ struct btrfs_item *item = btrfs_item_nr(eb, nr);
write_eb_member(eb, item, struct btrfs_item, key, disk_key);
}
BTRFS_LEAF_DATA_OFFSET + leaf_data_end(left),
push_space);
- memmove_extent_buffer(right, btrfs_item_nr_offset(push_items),
- btrfs_item_nr_offset(0),
+ memmove_extent_buffer(right, btrfs_item_nr_offset(right, push_items),
+ btrfs_item_nr_offset(right, 0),
right_nritems * sizeof(struct btrfs_item));
/* copy the items from left to right */
- copy_extent_buffer(right, left, btrfs_item_nr_offset(0),
- btrfs_item_nr_offset(left_nritems - push_items),
+ copy_extent_buffer(right, left, btrfs_item_nr_offset(right, 0),
+ btrfs_item_nr_offset(left, left_nritems - push_items),
push_items * sizeof(struct btrfs_item));
/* update the item pointers */
/* push data from right to left */
copy_extent_buffer(left, right,
- btrfs_item_nr_offset(btrfs_header_nritems(left)),
- btrfs_item_nr_offset(0),
+ btrfs_item_nr_offset(left, btrfs_header_nritems(left)),
+ btrfs_item_nr_offset(right, 0),
push_items * sizeof(struct btrfs_item));
push_space = BTRFS_LEAF_DATA_SIZE(fs_info) -
BTRFS_LEAF_DATA_OFFSET +
leaf_data_end(right), push_space);
- memmove_extent_buffer(right, btrfs_item_nr_offset(0),
- btrfs_item_nr_offset(push_items),
+ memmove_extent_buffer(right, btrfs_item_nr_offset(right, 0),
+ btrfs_item_nr_offset(left, push_items),
(btrfs_header_nritems(right) - push_items) *
sizeof(struct btrfs_item));
}
btrfs_set_header_nritems(right, nritems);
data_copy_size = btrfs_item_data_end(l, mid) - leaf_data_end(l);
- copy_extent_buffer(right, l, btrfs_item_nr_offset(0),
- btrfs_item_nr_offset(mid),
+ copy_extent_buffer(right, l, btrfs_item_nr_offset(right, 0),
+ btrfs_item_nr_offset(l, mid),
nritems * sizeof(struct btrfs_item));
copy_extent_buffer(right, l,
nritems = btrfs_header_nritems(leaf);
if (slot != nritems) {
/* shift the items */
- memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + 1),
- btrfs_item_nr_offset(slot),
+ memmove_extent_buffer(leaf, btrfs_item_nr_offset(leaf, slot + 1),
+ btrfs_item_nr_offset(leaf, slot),
(nritems - slot) * sizeof(struct btrfs_item));
}
ioff - batch->total_data_size);
}
/* shift the items */
- memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + batch->nr),
- btrfs_item_nr_offset(slot),
- (nritems - slot) * sizeof(struct btrfs_item));
+ memmove_extent_buffer(leaf,
+ btrfs_item_nr_offset(leaf, slot + batch->nr),
+ btrfs_item_nr_offset(leaf, slot),
+ (nritems - slot) * sizeof(struct btrfs_item));
/* shift the data */
memmove_extent_buffer(leaf, BTRFS_LEAF_DATA_OFFSET +
btrfs_set_token_item_offset(&token, i, ioff + dsize);
}
- memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot),
- btrfs_item_nr_offset(slot + nr),
+ memmove_extent_buffer(leaf, btrfs_item_nr_offset(leaf, slot),
+ btrfs_item_nr_offset(leaf, slot + nr),
sizeof(struct btrfs_item) *
(nritems - slot - nr));
}