From patchwork Fri Dec 18 16:07:10 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard W.M. Jones" X-Patchwork-Id: 41418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A14C9B6F0D for ; Sat, 19 Dec 2009 03:15:23 +1100 (EST) Received: from localhost ([127.0.0.1]:47795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLfU8-0005a3-Aq for incoming@patchwork.ozlabs.org; Fri, 18 Dec 2009 11:15:20 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLfMP-0008SS-0s for qemu-devel@nongnu.org; Fri, 18 Dec 2009 11:07:21 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLfMK-0008Ng-71 for qemu-devel@nongnu.org; Fri, 18 Dec 2009 11:07:20 -0500 Received: from [199.232.76.173] (port=44485 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLfMK-0008NW-2D for qemu-devel@nongnu.org; Fri, 18 Dec 2009 11:07:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50544) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NLfMJ-0001pi-Fe for qemu-devel@nongnu.org; Fri, 18 Dec 2009 11:07:15 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBIG7ESl000957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 18 Dec 2009 11:07:14 -0500 Received: from localhost (vpn2-10-80.ams2.redhat.com [10.36.10.80]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBIG79Tn016911 for ; Fri, 18 Dec 2009 11:07:13 -0500 Date: Fri, 18 Dec 2009 16:07:10 +0000 From: "Richard W.M. Jones" To: qemu-devel@nongnu.org Message-ID: <20091218160710.GB28180@amd.home.annexia.org> References: <20091218155655.GA28076@amd.home.annexia.org> <20091218155820.GB28141@amd.home.annexia.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20091218155820.GB28141@amd.home.annexia.org> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 2/2] VMDK4: Parse and check the createType (VMDK file type) field. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add Signed-off-by line. Rich. diff --git a/block/vmdk.c b/block/vmdk.c index 0f59ea5..4cb126b 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -81,6 +81,7 @@ typedef struct BDRVVmdkState { /* VMDK4 fields */ int64_t cid_offset; int64_t parent_cid_offset; + char *create_type; } BDRVVmdkState; typedef struct VmdkMetaData { @@ -161,6 +162,13 @@ static int vmdk4_parse_desc_assignment(BlockDriverState *bs, if (!strncmp(p, "parentCID=", 10)) s->parent_cid_offset = file_offset + 10; + if (strncmp(p, "createType=\"", 12) == 0) { + p[len-1] = '\0'; /* Remove trailing double quote. */ + if (s->create_type) + qemu_free(s->create_type); + s->create_type = qemu_strdup(p+12); + } + return 0; } @@ -174,6 +182,7 @@ static int vmdk4_parse_desc(BlockDriverState *bs, VMDK4Header *header) s->cid_offset = 0; s->parent_cid_offset = 0; + s->create_type = NULL; /* Stored in the header are the offset/size in sectors. */ desc_size = le64_to_cpu(header->desc_size) * SECTOR_SIZE; @@ -522,6 +531,16 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags) if (vmdk4_parse_desc(bs, &header) == -1) goto fail; + if (s->create_type && + !(!strcmp(s->create_type, "monolithicSparse") || + !strcmp(s->create_type, "monolithicFlat") || + !strcmp(s->create_type, "twoGbMaxExtentSparse") || + !strcmp(s->create_type, "twoGbMaxExtentFlat"))) { + fprintf (stderr, "vmdk: disk type '%s' is not supported by qemu\n", + s->create_type); + goto fail; + } + if (parent_open) s->is_parent = 1; else @@ -560,6 +579,7 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags) qemu_free(s->l1_backup_table); qemu_free(s->l1_table); qemu_free(s->l2_cache); + qemu_free(s->create_type); bdrv_delete(s->hd); return -1; } @@ -928,6 +948,7 @@ static void vmdk_close(BlockDriverState *bs) qemu_free(s->l1_table); qemu_free(s->l2_cache); + qemu_free(s->create_type); // try to close parent image, if exist vmdk_parent_close(s->hd); bdrv_delete(s->hd);