1 From 930e57ecb64bbab75c2b71d0d1ba07451fec4567 Mon Sep 17 00:00:00 2001
2 From: Fam Zheng <famcool@gmail.com>
3 Date: Tue, 12 Jul 2011 19:56:30 +0800
4 Subject: [PATCH 04/12] VMDK: probe for monolithicFlat images
6 Probe as the same behavior as VMware does.
7 Recognize image as monolithicFlat descriptor file when the file is text
8 and the first effective line (not '#' leaded comment or space line) is
9 either 'version=1' or 'version=2'. No space or upper case charactors
12 Signed-off-by: Fam Zheng <famcool@gmail.com>
13 Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
14 Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16 block/vmdk.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
17 1 file changed, 43 insertions(+), 2 deletions(-)
21 @@ -103,10 +103,51 @@ static int vmdk_probe(const uint8_t *buf
23 magic = be32_to_cpu(*(uint32_t *)buf);
24 if (magic == VMDK3_MAGIC ||
25 - magic == VMDK4_MAGIC)
26 + magic == VMDK4_MAGIC) {
30 + const char *p = (const char *)buf;
31 + const char *end = p + buf_size;
34 + /* skip comment line */
35 + while (p < end && *p != '\n') {
42 + while (p < end && *p == ' ') {
45 + /* skip '\r' if windows line endings used. */
46 + if (p < end && *p == '\r') {
49 + /* only accept blank lines before 'version=' line */
50 + if (p == end || *p != '\n') {
56 + if (end - p >= strlen("version=X\n")) {
57 + if (strncmp("version=1\n", p, strlen("version=1\n")) == 0 ||
58 + strncmp("version=2\n", p, strlen("version=2\n")) == 0) {
62 + if (end - p >= strlen("version=X\r\n")) {
63 + if (strncmp("version=1\r\n", p, strlen("version=1\r\n")) == 0 ||
64 + strncmp("version=2\r\n", p, strlen("version=2\r\n")) == 0) {