qcow1: Fix compressed images (Kevin Wolf)

Revert r4673, the removed dead code wasn't dead in fact.

Additionally, change the misleading else which tricks the reader into
believing that allocate is a boolean to else if (allocate == 2).

Signed-off-by: Kevin Wolf <kwolf@suse.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6244 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
aliguori 2009-01-08 19:29:03 +00:00
parent 062e55272e
commit 7f48fa1f05

View File

@ -339,28 +339,33 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
return -1; return -1;
} else { } else {
cluster_offset = bdrv_getlength(s->hd); cluster_offset = bdrv_getlength(s->hd);
/* round to cluster size */ if (allocate == 1) {
cluster_offset = (cluster_offset + s->cluster_size - 1) & /* round to cluster size */
~(s->cluster_size - 1); cluster_offset = (cluster_offset + s->cluster_size - 1) &
bdrv_truncate(s->hd, cluster_offset + s->cluster_size); ~(s->cluster_size - 1);
/* if encrypted, we must initialize the cluster bdrv_truncate(s->hd, cluster_offset + s->cluster_size);
content which won't be written */ /* if encrypted, we must initialize the cluster
if (s->crypt_method && content which won't be written */
(n_end - n_start) < s->cluster_sectors) { if (s->crypt_method &&
uint64_t start_sect; (n_end - n_start) < s->cluster_sectors) {
start_sect = (offset & ~(s->cluster_size - 1)) >> 9; uint64_t start_sect;
memset(s->cluster_data + 512, 0x00, 512); start_sect = (offset & ~(s->cluster_size - 1)) >> 9;
for(i = 0; i < s->cluster_sectors; i++) { memset(s->cluster_data + 512, 0x00, 512);
if (i < n_start || i >= n_end) { for(i = 0; i < s->cluster_sectors; i++) {
encrypt_sectors(s, start_sect + i, if (i < n_start || i >= n_end) {
s->cluster_data, encrypt_sectors(s, start_sect + i,
s->cluster_data + 512, 1, 1, s->cluster_data,
&s->aes_encrypt_key); s->cluster_data + 512, 1, 1,
if (bdrv_pwrite(s->hd, cluster_offset + i * 512, &s->aes_encrypt_key);
s->cluster_data, 512) != 512) if (bdrv_pwrite(s->hd, cluster_offset + i * 512,
return -1; s->cluster_data, 512) != 512)
return -1;
}
} }
} }
} else if (allocate == 2) {
cluster_offset |= QCOW_OFLAG_COMPRESSED |
(uint64_t)compressed_size << (63 - s->cluster_bits);
} }
} }
/* update L2 table */ /* update L2 table */