qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "B Gordon" <bbgordonn@fastmail.fm>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] VMDK: footer must take precedence over header when present
Date: Wed, 21 Dec 2011 15:34:11 -0800	[thread overview]
Message-ID: <1324510451.31148.140661014597833@webmail.messagingengine.com> (raw)

VMDK: footer must take precedence over header when present

In e.g. streamOptimized VMDKs from VSphere 4 with this flag set the
header l1_table is bogus and only the footer l1_table can be used to
correctly read extents.

Also reverts recent change to VMDK4Header so order of rgd_ and
gd_offset matches the VMDK spec.

https://bugs.launchpad.net/qemu/+bug/907063

Signed-off-by: B.B. Gordon <bbgordonn@fastmail.fm>

diff --git a/block/vmdk.c b/block/vmdk.c
index 5623ac1..77ff9e1 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -35,6 +35,7 @@
 #define VMDK4_FLAG_RGD (1 << 1)
 #define VMDK4_FLAG_COMPRESS (1 << 16)
 #define VMDK4_FLAG_MARKER (1 << 17)
+#define VMDK4_HEADER_AT_END 0xffffffffffffffffULL
 
 typedef struct {
     uint32_t version;
@@ -57,8 +58,8 @@ typedef struct {
     int64_t desc_offset;
     int64_t desc_size;
     int32_t num_gtes_per_gte;
-    int64_t gd_offset;
     int64_t rgd_offset;
+    int64_t gd_offset;
     int64_t grain_offset;
     char filler[1];
     char check_bytes[4];
@@ -443,11 +445,27 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
     VMDK4Header header;
     VmdkExtent *extent;
     int64_t l1_backup_offset = 0;
+    struct stat sb;
 
     ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
     if (ret < 0) {
         return ret;
     }
+    if (le64_to_cpu(header.gd_offset) == VMDK4_HEADER_AT_END) {
+        uint64_t filesize;
+        if (stat(bs->filename, &sb) == -1) {
+            fprintf(stderr, "Unable to get file size.\n");
+            return -1;
+        }
+        filesize = (((uint64_t)sb.st_size + (512 - 1)) &
~(uint64_t)(512 - 1));
+        ret = bdrv_pread(bs->file,
+                         (filesize - 1024 + sizeof(magic)),
+                         &header,
+                         sizeof(header));
+        if (ret != sizeof(header)) {
+            return ret;
+        }
+    }
     if (header.capacity == 0 && header.desc_offset) {
         return vmdk_open_desc_file(bs, flags, header.desc_offset << 9);
     }

-- 
http://www.fastmail.fm - Choose from over 50 domains or use your own

             reply	other threads:[~2011-12-21 23:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-21 23:34 B Gordon [this message]
2011-12-22  9:54 ` [Qemu-devel] VMDK: footer must take precedence over header when present Stefan Hajnoczi
2011-12-24  9:46 ` Fam Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1324510451.31148.140661014597833@webmail.messagingengine.com \
    --to=bbgordonn@fastmail.fm \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).