aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-14 10:31:29 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-14 10:31:29 -0400
commit4beb1b8b75a86373f6020103ab840448d14c8880 (patch)
tree944e80ccd6764afd16b4e31d5595d2decf36dabc /fs/btrfs
parent710874947aa0f81c3b348b052e81cb9075113c49 (diff)
Btrfs: add leaf data casting helper
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/ctree.h4
-rw-r--r--fs/btrfs/extent-tree.c8
-rw-r--r--fs/btrfs/print-tree.c5
3 files changed, 8 insertions, 9 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0968899fb7f9..05c7707263f5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -401,6 +401,10 @@ static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
401 s->blocksize = cpu_to_le16(val); 401 s->blocksize = cpu_to_le16(val);
402} 402}
403 403
404/* helper function to cast into the data area of the leaf. */
405#define btrfs_item_ptr(leaf, slot, type) \
406 ((type *)((leaf)->data + btrfs_item_offset((leaf)->items + (slot))))
407
404struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root); 408struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root);
405int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf); 409int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf);
406int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks); 410int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 7f156d9b7089..3767744f659e 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -41,9 +41,7 @@ static int inc_block_ref(struct btrfs_root *root, u64 blocknr)
41 BUG(); 41 BUG();
42 BUG_ON(ret != 0); 42 BUG_ON(ret != 0);
43 l = &path.nodes[0]->leaf; 43 l = &path.nodes[0]->leaf;
44 item = (struct btrfs_extent_item *)(l->data + 44 item = btrfs_item_ptr(l, path.slots[0], struct btrfs_extent_item);
45 btrfs_item_offset(l->items +
46 path.slots[0]));
47 refs = btrfs_extent_refs(item); 45 refs = btrfs_extent_refs(item);
48 btrfs_set_extent_refs(item, refs + 1); 46 btrfs_set_extent_refs(item, refs + 1);
49 47
@@ -69,9 +67,7 @@ static int lookup_block_ref(struct btrfs_root *root, u64 blocknr, u32 *refs)
69 if (ret != 0) 67 if (ret != 0)
70 BUG(); 68 BUG();
71 l = &path.nodes[0]->leaf; 69 l = &path.nodes[0]->leaf;
72 item = (struct btrfs_extent_item *)(l->data + 70 item = btrfs_item_ptr(l, path.slots[0], struct btrfs_extent_item);
73 btrfs_item_offset(l->items +
74 path.slots[0]));
75 *refs = btrfs_extent_refs(item); 71 *refs = btrfs_extent_refs(item);
76 btrfs_release_path(root->extent_root, &path); 72 btrfs_release_path(root->extent_root, &path);
77 return 0; 73 return 0;
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 64829b6b90f9..e769f36cf051 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -26,11 +26,10 @@ void btrfs_print_leaf(struct btrfs_leaf *l)
26 btrfs_item_size(item)); 26 btrfs_item_size(item));
27 printf("\t\titem data %.*s\n", btrfs_item_size(item), 27 printf("\t\titem data %.*s\n", btrfs_item_size(item),
28 l->data + btrfs_item_offset(item)); 28 l->data + btrfs_item_offset(item));
29 ei = (struct btrfs_extent_item *)(l->data + 29 ei = btrfs_item_ptr(l, i, struct btrfs_extent_item);
30 btrfs_item_offset(item));
31 printf("\t\textent data refs %u owner %Lu\n", 30 printf("\t\textent data refs %u owner %Lu\n",
32 btrfs_extent_refs(ei), btrfs_extent_owner(ei)); 31 btrfs_extent_refs(ei), btrfs_extent_owner(ei));
33 ri = (struct btrfs_root_item *)ei; 32 ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
34 printf("\t\troot data blocknr %Lu refs %u\n", 33 printf("\t\troot data blocknr %Lu refs %u\n",
35 btrfs_root_blocknr(ri), btrfs_root_refs(ri)); 34 btrfs_root_blocknr(ri), btrfs_root_refs(ri));
36 fflush(stdout); 35 fflush(stdout);