On Wed, Jul 27, 2011 at 10:27 AM, Fam Zheng <famc...@gmail.com> wrote: > @@ -863,6 +884,9 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t > cluster_offset, > } > ret = 0; > out: > + if (data) { > + qemu_free(data); > + }
qemu_free(NULL) is a nop, you don't need the if statement. Just call qemu_free(data). > return ret; > } > > @@ -871,15 +895,65 @@ static int vmdk_read_extent(VmdkExtent *extent, int64_t > cluster_offset, > int nb_sectors) > { > int ret; > - > + int cluster_bytes, buf_bytes; > + uint8_t *cluster_buf, *compressed_data; > + uint8_t *uncomp_buf; > + uint32_t data_len; > + VmdkGrainMarker *marker; > + uLongf buf_len; > + > + > + if (!extent->compressed) { > + ret = bdrv_pread(extent->file, > + cluster_offset + offset_in_cluster, > + buf, nb_sectors * 512); > + if (ret == nb_sectors * 512) { > + return 0; > + } else { > + return -EIO; > + } > + } > + cluster_bytes = extent->cluster_sectors * 512; > + /* Read two clusters in case GrainMarker + compressed data > one cluster > */ > + buf_bytes = cluster_bytes * 2; > + cluster_buf = qemu_mallocz(buf_bytes); > + uncomp_buf = qemu_mallocz(cluster_bytes); Do these really need to be zeroed? > ret = bdrv_pread(extent->file, > - cluster_offset + offset_in_cluster, > - buf, nb_sectors * 512); > - if (ret == nb_sectors * 512) { > - return 0; > - } else { > - return -EIO; > + cluster_offset, > + cluster_buf, buf_bytes); > + if (ret < 0) { > + goto out; > + } > + compressed_data = cluster_buf; > + buf_len = cluster_bytes; > + data_len = cluster_bytes; > + if (extent->has_marker) { > + marker = (VmdkGrainMarker *)cluster_buf; > + compressed_data = marker->data; > + data_len = marker->size; Endianness? Stefan