From f11b76b78abd73e4e17707c9cd150bf3e50e23b6 Mon Sep 17 00:00:00 2001 From: Jake Wires Date: Wed, 1 Sep 2010 14:10:08 -0700 Subject: [PATCH] dm-decrypt: always write allocated blocks, even if they're empty otherwise the bat will be inconsistent --- vhd/lib/vhd-util-dm-decrypt.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/vhd/lib/vhd-util-dm-decrypt.c b/vhd/lib/vhd-util-dm-decrypt.c index c69ff5b..4ee41f3 100644 --- a/vhd/lib/vhd-util-dm-decrypt.c +++ b/vhd/lib/vhd-util-dm-decrypt.c @@ -103,16 +103,15 @@ out: static int vhd_util_stream_copy_block(struct vhd_decrypt_context *ctx, uint32_t blk) { + int err, i; off64_t off; char *bm, *data; - int err, i, empty; vhd_context_t *src, *dst; bm = NULL; data = NULL; src = ctx->src_vhd; dst = ctx->dst_vhd; - empty = 1; if (src->bat.bat[blk] == DD_BLK_UNUSED) { if (dst->bat.bat[blk] == DD_BLK_UNUSED) @@ -161,7 +160,6 @@ vhd_util_stream_copy_block(struct vhd_decrypt_context *ctx, uint32_t blk) cnt++; if (copy) { - empty = 0; err = vhd_util_pread_data(ctx->src_raw, buf, vhd_sectors_to_bytes(cnt), vhd_sectors_to_bytes(pos)); @@ -174,18 +172,16 @@ vhd_util_stream_copy_block(struct vhd_decrypt_context *ctx, uint32_t blk) i += cnt; } - if (!empty) { - err = vhd_write_bitmap(dst, blk, bm); - if (err) { - ERR("writing bitmap 0x%x: %d\n", blk, err); - goto out; - } + err = vhd_write_bitmap(dst, blk, bm); + if (err) { + ERR("writing bitmap 0x%x: %d\n", blk, err); + goto out; + } - err = vhd_write_block(dst, blk, data); - if (err) { - ERR("writing data 0x%x: %d\n", blk, err); - goto out; - } + err = vhd_write_block(dst, blk, data); + if (err) { + ERR("writing data 0x%x: %d\n", blk, err); + goto out; } out: -- 2.39.5