build/image: warn if missing qemu-img for VDI/VMDK
[openwrt/staging/mkresin.git] / tools / qemu / patches / 0004-VMDK-probe-for-monolithicFlat-images.patch
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
5
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
10 accepted.
11
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>
15 ---
16 block/vmdk.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
17 1 file changed, 43 insertions(+), 2 deletions(-)
18
19 --- a/block/vmdk.c
20 +++ b/block/vmdk.c
21 @@ -103,10 +103,51 @@ static int vmdk_probe(const uint8_t *buf
22 return 0;
23 magic = be32_to_cpu(*(uint32_t *)buf);
24 if (magic == VMDK3_MAGIC ||
25 - magic == VMDK4_MAGIC)
26 + magic == VMDK4_MAGIC) {
27 return 100;
28 - else
29 + } else {
30 + const char *p = (const char *)buf;
31 + const char *end = p + buf_size;
32 + while (p < end) {
33 + if (*p == '#') {
34 + /* skip comment line */
35 + while (p < end && *p != '\n') {
36 + p++;
37 + }
38 + p++;
39 + continue;
40 + }
41 + if (*p == ' ') {
42 + while (p < end && *p == ' ') {
43 + p++;
44 + }
45 + /* skip '\r' if windows line endings used. */
46 + if (p < end && *p == '\r') {
47 + p++;
48 + }
49 + /* only accept blank lines before 'version=' line */
50 + if (p == end || *p != '\n') {
51 + return 0;
52 + }
53 + p++;
54 + continue;
55 + }
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) {
59 + return 100;
60 + }
61 + }
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) {
65 + return 100;
66 + }
67 + }
68 + return 0;
69 + }
70 return 0;
71 + }
72 }
73
74 #define CHECK_CID 1