On Mon, 03/31 12:05, Shwetha Mathangi Chandra Choodamani wrote: > 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;
Please put variable declarations in the beginning of code block. > + buf = g_malloc0(size + 1); buf is allocated and incremented, but the buffer is never released. > + bdrv_pread(file, sizeof(magic), buf, size); > + while (strcmp(access, "RW")) { access is used before initialization. Does this work? > + while (*buf) { > + sscanf(buf, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64, > + access, §ors, type, fname, &flat_offset); Better to align the parameters with first line: access, §ors, ...); However I don't think VMDK3 needs this fix, what we care here is monolithicSparse, which is specifically VMDK4. > + 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"); For VMDK4, this duplicates with vmdk_parse_extents(). I think this patch can be simplified by moving this if block after vmdk_add_extent, where the "extent" variable is set and we can set its type field safely. And please fix in the same way for streamOptimized. Thanks, Fam > + 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 >