From patchwork Fri Dec 18 15:58:20 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: 41416 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 4526BB6F0A for ; Sat, 19 Dec 2009 03:04:03 +1100 (EST) Received: from localhost ([127.0.0.1]:53826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLfJA-0006Kc-Jk for incoming@patchwork.ozlabs.org; Fri, 18 Dec 2009 11:04:00 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLfDs-0000lC-QY for qemu-devel@nongnu.org; Fri, 18 Dec 2009 10:58:32 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLfDo-0000fj-KD for qemu-devel@nongnu.org; Fri, 18 Dec 2009 10:58:32 -0500 Received: from [199.232.76.173] (port=56441 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLfDo-0000fW-FS for qemu-devel@nongnu.org; Fri, 18 Dec 2009 10:58:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47561) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NLfDn-00013k-V2 for qemu-devel@nongnu.org; Fri, 18 Dec 2009 10:58:28 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBIFwRYn029147 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 18 Dec 2009 10:58:27 -0500 Received: from localhost (vpn2-10-80.ams2.redhat.com [10.36.10.80]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBIFwLJt014882 for ; Fri, 18 Dec 2009 10:58:24 -0500 Date: Fri, 18 Dec 2009 15:58:20 +0000 From: "Richard W.M. Jones" To: qemu-devel@nongnu.org Message-ID: <20091218155820.GB28141@amd.home.annexia.org> References: <20091218155655.GA28076@amd.home.annexia.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20091218155655.GA28076@amd.home.annexia.org> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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 diff --git a/block/vmdk.c b/block/vmdk.c index 71680f0..c0b3160 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; @@ -521,6 +530,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 @@ -559,6 +578,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; } @@ -927,6 +947,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);