build/image: warn if missing qemu-img for VDI/VMDK
[openwrt/staging/mkresin.git] / tools / qemu / patches / 0006-VMDK-add-field-BDRVVmdkState.desc_offset.patch
1 From 1c1781fa1c45a7c012f7b2c4be1be372f19e3cc6 Mon Sep 17 00:00:00 2001
2 From: Fam Zheng <famcool@gmail.com>
3 Date: Tue, 12 Jul 2011 19:56:32 +0800
4 Subject: [PATCH 06/12] VMDK: add field BDRVVmdkState.desc_offset
5
6 There are several occurrence of magic number 0x200 as the descriptor
7 offset within mono sparse image file. This is not the case for images
8 with separate descriptor file. So a field is added to BDRVVmdkState to
9 hold the correct value.
10
11 Signed-off-by: Fam Zheng <famcool@gmail.com>
12 Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
13 Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14 ---
15 block/vmdk.c | 27 ++++++++++++++++++---------
16 1 file changed, 18 insertions(+), 9 deletions(-)
17
18 --- a/block/vmdk.c
19 +++ b/block/vmdk.c
20 @@ -81,6 +81,7 @@ typedef struct VmdkExtent {
21 } VmdkExtent;
22
23 typedef struct BDRVVmdkState {
24 + int desc_offset;
25 uint32_t parent_cid;
26 int num_extents;
27 /* Extent array with num_extents entries, ascend ordered by address */
28 @@ -175,10 +176,11 @@ static uint32_t vmdk_read_cid(BlockDrive
29 uint32_t cid;
30 const char *p_name, *cid_str;
31 size_t cid_str_size;
32 + BDRVVmdkState *s = bs->opaque;
33
34 - /* the descriptor offset = 0x200 */
35 - if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
36 + if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
37 return 0;
38 + }
39
40 if (parent) {
41 cid_str = "parentCID";
42 @@ -200,10 +202,12 @@ static int vmdk_write_cid(BlockDriverSta
43 {
44 char desc[DESC_SIZE], tmp_desc[DESC_SIZE];
45 char *p_name, *tmp_str;
46 + BDRVVmdkState *s = bs->opaque;
47
48 - /* the descriptor offset = 0x200 */
49 - if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
50 - return -1;
51 + memset(desc, 0, sizeof(desc));
52 + if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
53 + return -EIO;
54 + }
55
56 tmp_str = strstr(desc,"parentCID");
57 pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str);
58 @@ -213,8 +217,9 @@ static int vmdk_write_cid(BlockDriverSta
59 pstrcat(desc, sizeof(desc), tmp_desc);
60 }
61
62 - if (bdrv_pwrite_sync(bs->file, 0x200, desc, DESC_SIZE) < 0)
63 - return -1;
64 + if (bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE) < 0) {
65 + return -EIO;
66 + }
67 return 0;
68 }
69
70 @@ -402,10 +407,11 @@ static int vmdk_parent_open(BlockDriverS
71 {
72 char *p_name;
73 char desc[DESC_SIZE];
74 + BDRVVmdkState *s = bs->opaque;
75
76 - /* the descriptor offset = 0x200 */
77 - if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
78 + if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
79 return -1;
80 + }
81
82 if ((p_name = strstr(desc,"parentFileNameHint")) != NULL) {
83 char *end_name;
84 @@ -506,8 +512,10 @@ static int vmdk_open_vmdk3(BlockDriverSt
85 int ret;
86 uint32_t magic;
87 VMDK3Header header;
88 + BDRVVmdkState *s = bs->opaque;
89 VmdkExtent *extent;
90
91 + s->desc_offset = 0x200;
92 ret = bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header));
93 if (ret < 0) {
94 goto fail;
95 @@ -539,6 +547,7 @@ static int vmdk_open_vmdk4(BlockDriverSt
96 BDRVVmdkState *s = bs->opaque;
97 VmdkExtent *extent;
98
99 + s->desc_offset = 0x200;
100 ret = bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header));
101 if (ret < 0) {
102 goto fail;