* [Qemu-devel] [PATCH 05/12] VMDK: add field BDRVVmdkState.desc_offset to hold descriptor offset
@ 2011-06-04 0:41 Fam Zheng
0 siblings, 0 replies; only message in thread
From: Fam Zheng @ 2011-06-04 0:41 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Christoph Hellwig
There are several occurrence of magic number 0x200 as the descriptor
offset within mono sparse image file. This is not the case for images
with separate descriptor file. So a field is added to BDRVVmdkState to
hold the correct value.
Signed-off-by: Fam Zheng <famcool@gmail.com>
---
block/vmdk.c | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index e360156..b02a7b7 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -81,6 +81,7 @@ typedef struct VmdkExtent {
} VmdkExtent;
typedef struct BDRVVmdkState {
+ int desc_offset;
int num_extents;
VmdkExtent *extents;
} BDRVVmdkState;
@@ -126,9 +127,9 @@ static uint32_t vmdk_read_cid(BlockDriverState
*bs, int parent)
uint32_t cid;
const char *p_name, *cid_str;
size_t cid_str_size;
+ BDRVVmdkState *s = bs->opaque;
- /* the descriptor offset = 0x200 */
- if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
+ if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE)
return 0;
if (parent) {
@@ -151,9 +152,9 @@ static int vmdk_write_cid(BlockDriverState *bs,
uint32_t cid)
{
char desc[DESC_SIZE], tmp_desc[DESC_SIZE];
char *p_name, *tmp_str;
+ BDRVVmdkState *s = bs->opaque;
- /* the descriptor offset = 0x200 */
- if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
+ if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE)
return -1;
tmp_str = strstr(desc,"parentCID");
@@ -164,7 +165,7 @@ static int vmdk_write_cid(BlockDriverState *bs,
uint32_t cid)
pstrcat(desc, sizeof(desc), tmp_desc);
}
- if (bdrv_pwrite_sync(bs->file, 0x200, desc, DESC_SIZE) < 0)
+ if (bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE) < 0)
return -1;
return 0;
}
@@ -352,9 +353,9 @@ static int vmdk_parent_open(BlockDriverState *bs)
{
char *p_name;
char desc[DESC_SIZE];
+ BDRVVmdkState *s = bs->opaque;
- /* the descriptor offset = 0x200 */
- if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
+ if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE)
return -1;
if ((p_name = strstr(desc,"parentFileNameHint")) != NULL) {
@@ -441,6 +442,7 @@ static int vmdk_open_vmdk3(BlockDriverState *bs, int flags)
extent->l1_backup_table_offset = 0;
extent->l1_entry_sectors = extent->l2_size * extent->cluster_sectors;
bs->total_sectors = extent->sectors;
+ s->desc_offset = 0x200;
if (vmdk_init_tables(bs, extent)) {
goto fail;
}
@@ -477,6 +479,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, int flags)
extent->l1_table_offset = le64_to_cpu(header.rgd_offset) << 9;
extent->l1_backup_table_offset = le64_to_cpu(header.gd_offset) << 9;
+ s->desc_offset = 0x200;
// try to open parent images, if exist
if (vmdk_parent_open(bs) != 0) {
goto fail;
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2011-06-04 0:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-04 0:41 [Qemu-devel] [PATCH 05/12] VMDK: add field BDRVVmdkState.desc_offset to hold descriptor offset Fam Zheng
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).