This patch fixes the qemu-img info bug to return the right format of an extent. Changes applicable to both VMDK3 and VMDK4 type headers. Signed-off-by: Shwetha Mathangi Chandra Choodamani <saphira.brightsca...@gmail.com> --- block/vmdk.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
diff --git a/block/vmdk.c b/block/vmdk.c index b69988d..81fcb92 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -515,6 +515,28 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs, le32_to_cpu(header.granularity), &extent, errp); + char access[11]; + char type[11]; + char fname[512]; + int64_t sectors = 0; + int64_t flat_offset; + int64_t size; + size = bdrv_getlength(file); + char *buf; + buf = g_malloc0(size + 1); + bdrv_pread(file, sizeof(magic), buf, size); + while (strcmp(access, "RW")) { + while (*buf) { + sscanf(buf, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64, + access, §ors, type, fname, &flat_offset); + if (*buf == '\n') { + buf++; + break; + } + buf++; + } + } + extent->type = g_strdup(type); if (ret < 0) { return ret; } @@ -566,6 +588,12 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, VmdkExtent *extent; BDRVVmdkState *s = bs->opaque; int64_t l1_backup_offset = 0; + char access[11]; + char type[11]; + char fname[512]; + int64_t sectors = 0; + int64_t flat_offset; + ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header)); if (ret < 0) { @@ -589,6 +617,19 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, if (!s->create_type) { s->create_type = g_strdup("monolithicSparse"); + uint64_t desc_offset = le64_to_cpu(header.desc_offset); + char *buf = vmdk_read_desc(file, desc_offset<<9, errp); + while (strcmp(access, "RW")) { + while (*buf) { + sscanf(buf, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64, + access, §ors, type, fname, &flat_offset); + if (*buf == '\n') { + buf++; + break; + } + buf++; + } + } } if (le64_to_cpu(header.gd_offset) == VMDK4_GD_AT_END) { @@ -697,6 +738,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, extent->has_marker = le32_to_cpu(header.flags) & VMDK4_FLAG_MARKER; extent->version = le32_to_cpu(header.version); extent->has_zero_grain = le32_to_cpu(header.flags) & VMDK4_FLAG_ZERO_GRAIN; + extent->type = g_strdup(type); ret = vmdk_init_tables(bs, extent, errp); if (ret) { /* free extent allocated by vmdk_add_extent */ -- 1.7.9.5