提交 4beb1b8b 编写于 作者: C Chris Mason 提交者: David Woodhouse

Btrfs: add leaf data casting helper

Signed-off-by: NChris Mason <chris.mason@oracle.com>
上级 71087494
...@@ -401,6 +401,10 @@ static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s, ...@@ -401,6 +401,10 @@ static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
s->blocksize = cpu_to_le16(val); s->blocksize = cpu_to_le16(val);
} }
/* helper function to cast into the data area of the leaf. */
#define btrfs_item_ptr(leaf, slot, type) \
((type *)((leaf)->data + btrfs_item_offset((leaf)->items + (slot))))
struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root); struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root);
int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf); int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf);
int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks); int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks);
......
...@@ -41,9 +41,7 @@ static int inc_block_ref(struct btrfs_root *root, u64 blocknr) ...@@ -41,9 +41,7 @@ static int inc_block_ref(struct btrfs_root *root, u64 blocknr)
BUG(); BUG();
BUG_ON(ret != 0); BUG_ON(ret != 0);
l = &path.nodes[0]->leaf; l = &path.nodes[0]->leaf;
item = (struct btrfs_extent_item *)(l->data + item = btrfs_item_ptr(l, path.slots[0], struct btrfs_extent_item);
btrfs_item_offset(l->items +
path.slots[0]));
refs = btrfs_extent_refs(item); refs = btrfs_extent_refs(item);
btrfs_set_extent_refs(item, refs + 1); btrfs_set_extent_refs(item, refs + 1);
...@@ -69,9 +67,7 @@ static int lookup_block_ref(struct btrfs_root *root, u64 blocknr, u32 *refs) ...@@ -69,9 +67,7 @@ static int lookup_block_ref(struct btrfs_root *root, u64 blocknr, u32 *refs)
if (ret != 0) if (ret != 0)
BUG(); BUG();
l = &path.nodes[0]->leaf; l = &path.nodes[0]->leaf;
item = (struct btrfs_extent_item *)(l->data + item = btrfs_item_ptr(l, path.slots[0], struct btrfs_extent_item);
btrfs_item_offset(l->items +
path.slots[0]));
*refs = btrfs_extent_refs(item); *refs = btrfs_extent_refs(item);
btrfs_release_path(root->extent_root, &path); btrfs_release_path(root->extent_root, &path);
return 0; return 0;
......
...@@ -26,11 +26,10 @@ void btrfs_print_leaf(struct btrfs_leaf *l) ...@@ -26,11 +26,10 @@ void btrfs_print_leaf(struct btrfs_leaf *l)
btrfs_item_size(item)); btrfs_item_size(item));
printf("\t\titem data %.*s\n", btrfs_item_size(item), printf("\t\titem data %.*s\n", btrfs_item_size(item),
l->data + btrfs_item_offset(item)); l->data + btrfs_item_offset(item));
ei = (struct btrfs_extent_item *)(l->data + ei = btrfs_item_ptr(l, i, struct btrfs_extent_item);
btrfs_item_offset(item));
printf("\t\textent data refs %u owner %Lu\n", printf("\t\textent data refs %u owner %Lu\n",
btrfs_extent_refs(ei), btrfs_extent_owner(ei)); btrfs_extent_refs(ei), btrfs_extent_owner(ei));
ri = (struct btrfs_root_item *)ei; ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
printf("\t\troot data blocknr %Lu refs %u\n", printf("\t\troot data blocknr %Lu refs %u\n",
btrfs_root_blocknr(ri), btrfs_root_refs(ri)); btrfs_root_blocknr(ri), btrfs_root_refs(ri));
fflush(stdout); fflush(stdout);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册