diff options
author | Fam Zheng <famz@redhat.com> | 2013-05-02 10:25:26 +0800 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2013-05-03 10:33:46 +0200 |
commit | e304e8e5a05bc54c71c5f6fc76abd47410e59857 (patch) | |
tree | 801d5d2a2d5834c91146fe8271e042ec41b75218 /block | |
parent | 95b0aa4231dfc827ddc189138d6502cbca66d2b6 (diff) | |
download | qemu-e304e8e5a05bc54c71c5f6fc76abd47410e59857.tar.gz qemu-e304e8e5a05bc54c71c5f6fc76abd47410e59857.tar.bz2 qemu-e304e8e5a05bc54c71c5f6fc76abd47410e59857.zip |
vmdk: store fields of VmdkMetaData in cpu endian
Previously VmdkMetaData.offset is stored little endian while other
fields are cpu endian. This changes offset to cpu endian and convert
before writing to image.
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/vmdk.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/block/vmdk.c b/block/vmdk.c index 0463d3b36d..d98f304591 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -813,14 +813,15 @@ static int get_whole_cluster(BlockDriverState *bs, static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data) { + uint32_t offset; + QEMU_BUILD_BUG_ON(sizeof(offset) != sizeof(m_data->offset)); + offset = cpu_to_le32(m_data->offset); /* update L2 table */ if (bdrv_pwrite_sync( extent->file, ((int64_t)m_data->l2_offset * 512) + (m_data->l2_index * sizeof(m_data->offset)), - &(m_data->offset), - sizeof(m_data->offset) - ) < 0) { + &offset, sizeof(offset)) < 0) { return VMDK_ERROR; } /* update backup L2 table */ @@ -830,8 +831,7 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data) extent->file, ((int64_t)m_data->l2_offset * 512) + (m_data->l2_index * sizeof(m_data->offset)), - &(m_data->offset), sizeof(m_data->offset) - ) < 0) { + &offset, sizeof(offset)) < 0) { return VMDK_ERROR; } } @@ -848,7 +848,7 @@ static int get_cluster_offset(BlockDriverState *bs, { unsigned int l1_index, l2_offset, l2_index; int min_index, i, j; - uint32_t min_count, *l2_table, tmp = 0; + uint32_t min_count, *l2_table; bool zeroed = false; if (m_data) { @@ -924,8 +924,7 @@ static int get_cluster_offset(BlockDriverState *bs, } *cluster_offset >>= 9; - tmp = cpu_to_le32(*cluster_offset); - l2_table[l2_index] = tmp; + l2_table[l2_index] = cpu_to_le32(*cluster_offset); /* First of all we write grain itself, to avoid race condition * that may to corrupt the image. @@ -938,7 +937,7 @@ static int get_cluster_offset(BlockDriverState *bs, } if (m_data) { - m_data->offset = tmp; + m_data->offset = *cluster_offset; m_data->l1_index = l1_index; m_data->l2_index = l2_index; m_data->l2_offset = l2_offset; |