From patchwork Fri Jun 24 08:18:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feiran Zheng X-Patchwork-Id: 101747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BED1CB6F77 for ; Fri, 24 Jun 2011 18:49:00 +1000 (EST) Received: from localhost ([::1]:45381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qa24P-0003Tv-Dm for incoming@patchwork.ozlabs.org; Fri, 24 Jun 2011 04:48:57 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qa1ck-0006PR-Jx for qemu-devel@nongnu.org; Fri, 24 Jun 2011 04:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qa1ci-0001qP-Fm for qemu-devel@nongnu.org; Fri, 24 Jun 2011 04:20:22 -0400 Received: from mail-iy0-f173.google.com ([209.85.210.173]:63570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qa1ch-0001ms-Rp for qemu-devel@nongnu.org; Fri, 24 Jun 2011 04:20:20 -0400 Received: by mail-iy0-f173.google.com with SMTP id 3so2656746iyb.4 for ; Fri, 24 Jun 2011 01:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=cMjHuVjtWJ0FKTr+3zIJkF6hhJGDUojZ76NQhaYrETI=; b=eq14omYxmsR1k4a+UEuRx9pupmVdDjII63HOJ8l9UA8SPDZaPkmfPZncFN5eOkj8K4 US7Onlhzbvenyg4G3Es/VYCVLXYgiZr/2ASIQqy20N807FWeGUFyAK8dUeVPcCC0Uspw eu1jTqGCZGfsSKRe/XXgaiIoXy7VVfXP4kwKw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=OPJjhivhits6OEbQ9uKtA7XoYStjJChJdreXzJcBjbDkRdByi9dd7c2AUJRSFm1a/F Gc3dX3kW6pz+RqtoGJ92IV0uL5CdXjB3cyzQeAD6gItKx7AZpDEGBoj9lkF7FV9/ycX3 4D1Z9ZnNv5vgP6t2YGvxH0SnqEuQndvV1Q8J8= Received: by 10.42.161.70 with SMTP id s6mr3193448icx.374.1308903619060; Fri, 24 Jun 2011 01:20:19 -0700 (PDT) Received: from localhost.localdomain (admis.tongji.edu.cn [202.120.189.202]) by mx.google.com with ESMTPS id f19sm1351912ibl.66.2011.06.24.01.20.16 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 24 Jun 2011 01:20:18 -0700 (PDT) From: famcool@gmail.com To: qemu-devel@nongnu.org Date: Fri, 24 Jun 2011 16:18:20 +0800 Message-Id: <1308903507-10799-6-git-send-email-famcool@gmail.com> X-Mailer: git-send-email 1.7.5.2 In-Reply-To: <1308903507-10799-1-git-send-email-famcool@gmail.com> References: <1308903507-10799-1-git-send-email-famcool@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.173 Cc: kwolf@redhat.com, Fam Zheng , hch@lst.de, stefanha@gmail.com Subject: [Qemu-devel] [PATCH v2 05/12] VMDK: add field BDRVVmdkState.desc_offset 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 From: Fam Zheng There are several occurrence of magic number 0x200 as the descriptor offset within mono sparse image file. This is not the case for images with separate descriptor file. So a field is added to BDRVVmdkState to hold the correct value. Signed-off-by: Fam Zheng --- block/vmdk.c | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 8d55e5f..e1b94c2 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -81,6 +81,7 @@ typedef struct VmdkExtent { } VmdkExtent; typedef struct BDRVVmdkState { + int desc_offset; int num_extents; uint32_t parent_cid; VmdkExtent *extents; @@ -151,10 +152,11 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent) uint32_t cid; const char *p_name, *cid_str; size_t cid_str_size; + BDRVVmdkState *s = bs->opaque; - /* the descriptor offset = 0x200 */ - if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE) + if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) { return 0; + } if (parent) { cid_str = "parentCID"; @@ -176,10 +178,11 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid) { char desc[DESC_SIZE], tmp_desc[DESC_SIZE]; char *p_name, *tmp_str; + BDRVVmdkState *s = bs->opaque; - /* the descriptor offset = 0x200 */ - if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE) - return -1; + if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) { + return -EIO; + } tmp_str = strstr(desc,"parentCID"); pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str); @@ -189,8 +192,9 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid) pstrcat(desc, sizeof(desc), tmp_desc); } - if (bdrv_pwrite_sync(bs->file, 0x200, desc, DESC_SIZE) < 0) - return -1; + if (bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE) < 0) { + return -EIO; + } return 0; } @@ -274,7 +278,6 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) ret = -errno; goto fail; } - /* the descriptor offset = 0x200 */ if (lseek(p_fd, 0x200, SEEK_SET) == -1) { ret = -errno; goto fail; @@ -378,10 +381,11 @@ static int vmdk_parent_open(BlockDriverState *bs) { char *p_name; char desc[DESC_SIZE]; + BDRVVmdkState *s = bs->opaque; - /* the descriptor offset = 0x200 */ - if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE) + if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) { return -1; + } if ((p_name = strstr(desc,"parentFileNameHint")) != NULL) { char *end_name; @@ -479,6 +483,7 @@ static int vmdk_open_vmdk3(BlockDriverState *bs, int flags) goto fail; } s->num_extents = 1; + s->desc_offset = 0x200; ret = bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header)); if (ret != sizeof(header)) { ret = ret < 0 ? ret : -EIO; @@ -520,6 +525,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, int flags) goto fail; } s->num_extents = 1; + s->desc_offset = 0x200; ret = bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header)); if (ret != sizeof(header)) { ret = ret < 0 ? ret : -EIO;