qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image
@ 2011-06-04  0:40 Fam Zheng
  2011-06-14  8:06 ` Stefan Hajnoczi
  0 siblings, 1 reply; 6+ messages in thread
From: Fam Zheng @ 2011-06-04  0:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Christoph Hellwig

vmdk_probe for mono flat images.

Signed-off-by: Fam Zheng <famcool@gmail.com>
---
 block/vmdk.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index f787528..bf8d02a 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -101,10 +101,17 @@ static int vmdk_probe(const uint8_t *buf, int
buf_size, const char *filename)
         return 0;
     magic = be32_to_cpu(*(uint32_t *)buf);
     if (magic == VMDK3_MAGIC ||
-        magic == VMDK4_MAGIC)
+        magic == VMDK4_MAGIC) {
         return 100;
-    else
-        return 0;
+    } else {
+        char *cid_p, *ct_p, *extent_p;
+        cid_p = strstr((char *)buf, "CID");
+        ct_p = strstr((char *)buf, "createType");
+        extent_p = strstr((char *)buf, "RW");
+        if (cid_p && ct_p && extent_p)
+            return 100;
+    }
+    return 0;
 }

 #define CHECK_CID 1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image
  2011-06-04  0:40 [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image Fam Zheng
@ 2011-06-14  8:06 ` Stefan Hajnoczi
  2011-06-15  4:26   ` Fam Zheng
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2011-06-14  8:06 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On Sat, Jun 04, 2011 at 08:40:50AM +0800, Fam Zheng wrote:
> vmdk_probe for mono flat images.
> 
> Signed-off-by: Fam Zheng <famcool@gmail.com>
> ---
>  block/vmdk.c |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index f787528..bf8d02a 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -101,10 +101,17 @@ static int vmdk_probe(const uint8_t *buf, int
> buf_size, const char *filename)
>          return 0;
>      magic = be32_to_cpu(*(uint32_t *)buf);
>      if (magic == VMDK3_MAGIC ||
> -        magic == VMDK4_MAGIC)
> +        magic == VMDK4_MAGIC) {
>          return 100;
> -    else
> -        return 0;
> +    } else {
> +        char *cid_p, *ct_p, *extent_p;
> +        cid_p = strstr((char *)buf, "CID");
> +        ct_p = strstr((char *)buf, "createType");
> +        extent_p = strstr((char *)buf, "RW");
> +        if (cid_p && ct_p && extent_p)
> +            return 100;

NUL-terminated string functions cannot be used for probing because the
input file may be invalid.  If the magic number matches but there is no
NUL in the buffer then the strstr(3) will run off the end of the buffer.

Also note that the specification says "The descriptor file is not
case-sensitive".  "cid", "CiD", and "CID" should all be allowed.

Do non-monolithic vmdk images always have "# Disk DescriptorFile" as the
first line?  Perhaps you can test for that using memcmp(3) instead.

Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image
  2011-06-14  8:06 ` Stefan Hajnoczi
@ 2011-06-15  4:26   ` Fam Zheng
  2011-06-15  5:31     ` Stefan Hajnoczi
  0 siblings, 1 reply; 6+ messages in thread
From: Fam Zheng @ 2011-06-15  4:26 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On Tue, Jun 14, 2011 at 4:06 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Sat, Jun 04, 2011 at 08:40:50AM +0800, Fam Zheng wrote:
>> vmdk_probe for mono flat images.
>>
>> Signed-off-by: Fam Zheng <famcool@gmail.com>
>> ---
>>  block/vmdk.c |   13 ++++++++++---
>>  1 files changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/block/vmdk.c b/block/vmdk.c
>> index f787528..bf8d02a 100644
>> --- a/block/vmdk.c
>> +++ b/block/vmdk.c
>> @@ -101,10 +101,17 @@ static int vmdk_probe(const uint8_t *buf, int
>> buf_size, const char *filename)
>>          return 0;
>>      magic = be32_to_cpu(*(uint32_t *)buf);
>>      if (magic == VMDK3_MAGIC ||
>> -        magic == VMDK4_MAGIC)
>> +        magic == VMDK4_MAGIC) {
>>          return 100;
>> -    else
>> -        return 0;
>> +    } else {
>> +        char *cid_p, *ct_p, *extent_p;
>> +        cid_p = strstr((char *)buf, "CID");
>> +        ct_p = strstr((char *)buf, "createType");
>> +        extent_p = strstr((char *)buf, "RW");
>> +        if (cid_p && ct_p && extent_p)
>> +            return 100;
>
> NUL-terminated string functions cannot be used for probing because the
> input file may be invalid.  If the magic number matches but there is no
> NUL in the buffer then the strstr(3) will run off the end of the buffer.
>
> Also note that the specification says "The descriptor file is not
> case-sensitive".  "cid", "CiD", and "CID" should all be allowed.
>
> Do non-monolithic vmdk images always have "# Disk DescriptorFile" as the
> first line?  Perhaps you can test for that using memcmp(3) instead.
No guarantee in specification, although VMware does start descriptors
with such a line "# Disk DescriptorFile".
But is it proper that we make this assumption?


-- 
Best regards!
Fam Zheng

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image
  2011-06-15  4:26   ` Fam Zheng
@ 2011-06-15  5:31     ` Stefan Hajnoczi
  2011-06-15  5:45       ` Fam Zheng
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2011-06-15  5:31 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On Wed, Jun 15, 2011 at 5:26 AM, Fam Zheng <famcool@gmail.com> wrote:
> On Tue, Jun 14, 2011 at 4:06 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>> On Sat, Jun 04, 2011 at 08:40:50AM +0800, Fam Zheng wrote:
>>> vmdk_probe for mono flat images.
>>>
>>> Signed-off-by: Fam Zheng <famcool@gmail.com>
>>> ---
>>>  block/vmdk.c |   13 ++++++++++---
>>>  1 files changed, 10 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/block/vmdk.c b/block/vmdk.c
>>> index f787528..bf8d02a 100644
>>> --- a/block/vmdk.c
>>> +++ b/block/vmdk.c
>>> @@ -101,10 +101,17 @@ static int vmdk_probe(const uint8_t *buf, int
>>> buf_size, const char *filename)
>>>          return 0;
>>>      magic = be32_to_cpu(*(uint32_t *)buf);
>>>      if (magic == VMDK3_MAGIC ||
>>> -        magic == VMDK4_MAGIC)
>>> +        magic == VMDK4_MAGIC) {
>>>          return 100;
>>> -    else
>>> -        return 0;
>>> +    } else {
>>> +        char *cid_p, *ct_p, *extent_p;
>>> +        cid_p = strstr((char *)buf, "CID");
>>> +        ct_p = strstr((char *)buf, "createType");
>>> +        extent_p = strstr((char *)buf, "RW");
>>> +        if (cid_p && ct_p && extent_p)
>>> +            return 100;
>>
>> NUL-terminated string functions cannot be used for probing because the
>> input file may be invalid.  If the magic number matches but there is no
>> NUL in the buffer then the strstr(3) will run off the end of the buffer.
>>
>> Also note that the specification says "The descriptor file is not
>> case-sensitive".  "cid", "CiD", and "CID" should all be allowed.
>>
>> Do non-monolithic vmdk images always have "# Disk DescriptorFile" as the
>> first line?  Perhaps you can test for that using memcmp(3) instead.
> No guarantee in specification, although VMware does start descriptors
> with such a line "# Disk DescriptorFile".
> But is it proper that we make this assumption?

Have you tried removing that comment line to see if VMware still
recognizes the file?

Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image
  2011-06-15  5:31     ` Stefan Hajnoczi
@ 2011-06-15  5:45       ` Fam Zheng
  2011-06-15  6:10         ` Stefan Hajnoczi
  0 siblings, 1 reply; 6+ messages in thread
From: Fam Zheng @ 2011-06-15  5:45 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

> Have you tried removing that comment line to see if VMware still
> recognizes the file?
>

Yes, it recognizes iff the first option line (non-comment, non-empty)
is "version=1" or "version=2“.

(An interesting thing that it is both space sensitive and case sensitive)


-- 
Best regards!
Fam Zheng

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image
  2011-06-15  5:45       ` Fam Zheng
@ 2011-06-15  6:10         ` Stefan Hajnoczi
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2011-06-15  6:10 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Kevin Wolf, qemu-devel, Christoph Hellwig

On Wed, Jun 15, 2011 at 6:45 AM, Fam Zheng <famcool@gmail.com> wrote:
>> Have you tried removing that comment line to see if VMware still
>> recognizes the file?
>>
>
> Yes, it recognizes iff the first option line (non-comment, non-empty)
> is "version=1" or "version=2“.
>
> (An interesting thing that it is both space sensitive and case sensitive)

Cool, nice job figuring this out.  We should do the same.

Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-06-15  6:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-04  0:40 [Qemu-devel] [PATCH 03/12] VMDK: probe for mono flat image Fam Zheng
2011-06-14  8:06 ` Stefan Hajnoczi
2011-06-15  4:26   ` Fam Zheng
2011-06-15  5:31     ` Stefan Hajnoczi
2011-06-15  5:45       ` Fam Zheng
2011-06-15  6:10         ` Stefan Hajnoczi

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).