From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJlyC-0004eE-Mw for qemu-devel@nongnu.org; Fri, 06 Feb 2015 11:41:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJlyB-0000o9-Dh for qemu-devel@nongnu.org; Fri, 06 Feb 2015 11:41:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49631) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJlyB-0000o2-7L for qemu-devel@nongnu.org; Fri, 06 Feb 2015 11:41:27 -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 t16GfQog011838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 6 Feb 2015 11:41:26 -0500 From: Kevin Wolf Date: Fri, 6 Feb 2015 17:40:33 +0100 Message-Id: <1423240849-15499-27-git-send-email-kwolf@redhat.com> In-Reply-To: <1423240849-15499-1-git-send-email-kwolf@redhat.com> References: <1423240849-15499-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 26/42] block/dmg: set virtual size to a non-zero value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Peter Wu Right now the virtual size is always reported as zero which makes it impossible to convert between formats. After this patch, the number of sectors will be read from the trailer ("koly" block). To verify the behavior, the output of `dmg2img foo.dmg foo.img` was compared against `qemu-img convert -f dmg -O raw foo.dmg foo.raw`. The tests showed that the file contents are exactly the same, except that QEMU creates a slightly larger file (it matches the total sectors count). Signed-off-by: Peter Wu Reviewed-by: John Snow Message-id: 1420566495-13284-8-git-send-email-peter@lekensteyn.nl Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/dmg.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/dmg.c b/block/dmg.c index a78506a..a33c131 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -452,6 +452,14 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, ret = -EINVAL; goto fail; } + ret = read_uint64(bs, offset + 0x1ec, (uint64_t *)&bs->total_sectors); + if (ret < 0) { + goto fail; + } + if (bs->total_sectors < 0) { + ret = -EINVAL; + goto fail; + } if (rsrc_fork_length != 0) { ret = dmg_read_resource_fork(bs, &ds, rsrc_fork_offset, rsrc_fork_length); -- 1.8.3.1