diff mbox series

[03/15] btrfs-progs: image: use the appropriate offset helpers

Message ID 3b5c0bc05855fbcd999f75019585d24c5f491efa.1646691255.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: initial snapshot_id support | expand

Commit Message

Josef Bacik March 7, 2022, 10:17 p.m. UTC
We are using the size of the ondisk structures to figure out where we
need to zero out the buffers we're copying.  Fix this by using the
appropriate helpers instead so that it's extent tree v2 compatible.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 image/main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/image/main.c b/image/main.c
index c6af0cc2..600fc360 100644
--- a/image/main.c
+++ b/image/main.c
@@ -355,7 +355,7 @@  static void copy_buffer(struct metadump_struct *md, u8 *dst,
 	nritems = btrfs_header_nritems(src);
 
 	if (nritems == 0) {
-		size = sizeof(struct btrfs_header);
+		size = btrfs_leaf_data(src);
 		memset(dst + size, 0, src->len - size);
 	} else if (level == 0) {
 		size = btrfs_leaf_data(src) +
@@ -364,8 +364,7 @@  static void copy_buffer(struct metadump_struct *md, u8 *dst,
 		memset(dst + btrfs_item_nr_offset(src, nritems), 0, size);
 		zero_items(md, dst, src);
 	} else {
-		size = offsetof(struct btrfs_node, ptrs) +
-			sizeof(struct btrfs_key_ptr) * nritems;
+		size = btrfs_node_key_ptr_offset(src, nritems);
 		memset(dst + size, 0, src->len - size);
 	}
 	csum_block(dst, src->len);