]> xenbits.xensource.com Git - people/dstodden/blktap.git/commitdiff
CA-51534: fix vhd-util "destroy data" for preallocated-BAT VHDs
authorAndrei Lifchits <andrei.lifchits@citrix.com>
Sat, 12 Feb 2011 16:22:04 +0000 (16:22 +0000)
committerAndrei Lifchits <andrei.lifchits@citrix.com>
Sat, 12 Feb 2011 16:22:04 +0000 (16:22 +0000)
vhd/lib/vhd-util-modify.c

index c78e0c166bbda7f87e7c1a09fe9b39bd63ed7216..644b03d116b28472b9f71f1eeafd26a5f5e033cc 100644 (file)
@@ -54,13 +54,15 @@ vhd_util_zero_bat(vhd_context_t *vhd)
                        return err;
        }
 
-       for (i = 0; i < vhd->header.max_bat_size; i++)
+       for (i = 0; i < vhd->bat.entries; i++)
                vhd->bat.bat[i] = DD_BLK_UNUSED;
        err = vhd_write_bat(vhd, &vhd->bat);
        if (err)
                return err;
 
-       map_bytes = vhd_sectors_to_bytes(vhd->batmap.header.batmap_size);
+       map_bytes = ((vhd->footer.curr_size >> VHD_SECTOR_SHIFT) /
+                       vhd->spb) >> 3;
+       map_bytes = vhd_sectors_to_bytes(secs_round_up_no_zero(map_bytes));
        memset(vhd->batmap.map, 0, map_bytes);
        return vhd_write_batmap(vhd, &vhd->batmap);
 }