From patchwork Sat Dec 27 15:01:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 424212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 896C61400DD for ; Sun, 28 Dec 2014 02:05:45 +1100 (AEDT) Received: from localhost ([::1]:56188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4sw3-0004fi-MH for incoming@patchwork.ozlabs.org; Sat, 27 Dec 2014 10:05:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4ssO-0006Ij-Fj for qemu-devel@nongnu.org; Sat, 27 Dec 2014 10:01:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y4ssJ-0000Oo-2b for qemu-devel@nongnu.org; Sat, 27 Dec 2014 10:01:56 -0500 Received: from mail.lekensteyn.nl ([2a02:2308::360:1:25]:44805) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4ssI-0000Nx-Si for qemu-devel@nongnu.org; Sat, 27 Dec 2014 10:01:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2014-q3; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=vZywMUTAWGNE5jdH6k4SnTQBwRV45syeihtwUMT1UrU=; b=Ula7t2jE00GrOSmPTmg/KyiRdT0ediVOny7oDHABx/A6K7kXgvBXIEeNK3xU3eXnI97HOXSY3ueEInmy9vanw7AdNG0gGRC3OT3bnsnBrJ8UMiAE7IsPtci+cRBdDX4+iCSuQhHfqmWR+/SBRholcusA1nutlD/NSuMvObh7tWZdhe/JpzGOm16SslP6TMPmmvZMY59yngHz2/M2Iaum1Tgogg8L8WNT986K0EraFefmukp1nvcnVaUYlQJibLkhllbM1cEVtWOUMCYWb8hwDcv+eySWB75bG3yduRHFPZ0uDnSH05TEjB0ju2GPeY7qn5mhIETq7nh1XOkJnlbVFw==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA256:128) (Exim 4.80) (envelope-from ) id 1Y4ssH-00082D-Fc; Sat, 27 Dec 2014 16:01:49 +0100 From: Peter Wu To: qemu-devel@nongnu.org Date: Sat, 27 Dec 2014 16:01:41 +0100 Message-Id: <1419692504-29373-8-git-send-email-peter@lekensteyn.nl> X-Mailer: git-send-email 2.2.1 In-Reply-To: <1419692504-29373-1-git-send-email-peter@lekensteyn.nl> References: <1419692504-29373-1-git-send-email-peter@lekensteyn.nl> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:2308::360:1:25 Cc: Kevin Wolf , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 07/10] block/dmg: set virtual size to a non-zero value 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 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 BLXX ("mish") header. 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 --- block/dmg.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/dmg.c b/block/dmg.c index c03ea01..984997f 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -430,6 +430,14 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { 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_offset != 0 && rsrc_fork_length != 0) { ret = dmg_read_resource_fork(bs, &ds, rsrc_fork_offset, rsrc_fork_length);