From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58804) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLa42-0005YA-M3 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 11:22:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLa3x-0002o9-7e for qemu-devel@nongnu.org; Wed, 11 Feb 2015 11:22:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLa3w-0002nj-Q1 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 11:22:53 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1BGMpVE025326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 11 Feb 2015 11:22:52 -0500 From: Kevin Wolf Date: Wed, 11 Feb 2015 17:22:25 +0100 Message-Id: <1423671745-31547-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH] vpc: Fix size in fixed image creation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com If total_sectors is rounded to match the geometry, total_size needs to be changed as well. Otherwise we end up with an image whose geometry describes a disk larger than the image file, which doesn't end well. Signed-off-by: Kevin Wolf --- block/vpc.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 379ff4a..46830ee 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -850,6 +850,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) } total_sectors = (int64_t) cyls * heads * secs_per_cyl; + total_size = total_sectors * BDRV_SECTOR_SIZE; /* Prepare the Hard Disk Footer */ memset(buf, 0, 1024); @@ -871,13 +872,8 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) /* Version of Virtual PC 2007 */ footer->major = cpu_to_be16(0x0005); footer->minor = cpu_to_be16(0x0003); - if (disk_type == VHD_DYNAMIC) { - footer->orig_size = cpu_to_be64(total_sectors * 512); - footer->size = cpu_to_be64(total_sectors * 512); - } else { - footer->orig_size = cpu_to_be64(total_size); - footer->size = cpu_to_be64(total_size); - } + footer->orig_size = cpu_to_be64(total_size); + footer->size = cpu_to_be64(total_size); footer->cyls = cpu_to_be16(cyls); footer->heads = heads; footer->secs_per_cyl = secs_per_cyl; -- 1.8.3.1