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
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.
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>
15 block/vmdk.c | 27 ++++++++++++++++++---------
16 1 file changed, 18 insertions(+), 9 deletions(-)
20 @@ -81,6 +81,7 @@ typedef struct VmdkExtent {
23 typedef struct BDRVVmdkState {
27 /* Extent array with num_extents entries, ascend ordered by address */
28 @@ -175,10 +176,11 @@ static uint32_t vmdk_read_cid(BlockDrive
30 const char *p_name, *cid_str;
32 + BDRVVmdkState *s = bs->opaque;
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) {
41 cid_str = "parentCID";
42 @@ -200,10 +202,12 @@ static int vmdk_write_cid(BlockDriverSta
44 char desc[DESC_SIZE], tmp_desc[DESC_SIZE];
45 char *p_name, *tmp_str;
46 + BDRVVmdkState *s = bs->opaque;
48 - /* the descriptor offset = 0x200 */
49 - if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
51 + memset(desc, 0, sizeof(desc));
52 + if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
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);
62 - if (bdrv_pwrite_sync(bs->file, 0x200, desc, DESC_SIZE) < 0)
64 + if (bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE) < 0) {
70 @@ -402,10 +407,11 @@ static int vmdk_parent_open(BlockDriverS
74 + BDRVVmdkState *s = bs->opaque;
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) {
82 if ((p_name = strstr(desc,"parentFileNameHint")) != NULL) {
84 @@ -506,8 +512,10 @@ static int vmdk_open_vmdk3(BlockDriverSt
88 + BDRVVmdkState *s = bs->opaque;
91 + s->desc_offset = 0x200;
92 ret = bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header));
95 @@ -539,6 +547,7 @@ static int vmdk_open_vmdk4(BlockDriverSt
96 BDRVVmdkState *s = bs->opaque;
99 + s->desc_offset = 0x200;
100 ret = bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header));