From patchwork Tue Feb 12 12:33:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 219844 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2B0B82C0329 for ; Tue, 12 Feb 2013 23:35:04 +1100 (EST) Received: from localhost ([::1]:55738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5F4g-00009G-9Q for incoming@patchwork.ozlabs.org; Tue, 12 Feb 2013 07:35:02 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5F4Q-0008OQ-VN for qemu-devel@nongnu.org; Tue, 12 Feb 2013 07:34:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5F4J-0003UX-W4 for qemu-devel@nongnu.org; Tue, 12 Feb 2013 07:34:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5F4J-0003UK-NO for qemu-devel@nongnu.org; Tue, 12 Feb 2013 07:34:39 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1CCYd07006044 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Feb 2013 07:34:39 -0500 Received: from localhost (ovpn-112-27.ams2.redhat.com [10.36.112.27]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1CCYbxw001282; Tue, 12 Feb 2013 07:34:38 -0500 From: Stefan Hajnoczi To: Date: Tue, 12 Feb 2013 13:33:43 +0100 Message-Id: <1360672423-2286-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1360672423-2286-1-git-send-email-stefanha@redhat.com> References: <1360672423-2286-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 2/2] Revert "block/vpc: Fix size calculation" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This reverts commit f880defbb06708d30a38ce9f2667067626acdd38. Jeff Cody's testing revealed that the interpretation of size differs even between VirtualPC and HyperV. Revert this so there is time to consider the impact of any backwards incompatible behavior this change creates. Signed-off-by: Stefan Hajnoczi --- block/vpc.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index b4ff564..82229ef 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -34,8 +34,6 @@ #define HEADER_SIZE 512 -#define VHD_SECTOR_SIZE 512 - //#define CACHE enum vhd_type { @@ -206,13 +204,11 @@ static int vpc_open(BlockDriverState *bs, int flags) /* Write 'checksum' back to footer, or else will leave it with zero. */ footer->checksum = be32_to_cpu(checksum); - /* The visible size of a image in Virtual PC depends on the guest: - * QEMU and other emulators report the real size (here in sectors). - * All modern operating systems use this real size. - * Very old operating systems use CHS values to calculate the total size. - * This calculated size is usually smaller than the real size. - */ - bs->total_sectors = be64_to_cpu(footer->size) / VHD_SECTOR_SIZE; + // The visible size of a image in Virtual PC depends on the geometry + // rather than on the size stored in the footer (the size in the footer + // is too large usually) + bs->total_sectors = (int64_t) + be16_to_cpu(footer->cyls) * footer->heads * footer->secs_per_cyl; /* Allow a maximum disk size of approximately 2 TB */ if (bs->total_sectors >= 65535LL * 255 * 255) {