Commit 7f48fa1f05b0db5583fd191aee60f7b4fb7ffda9
1 parent
062e5527
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
Showing
1 changed file
with
25 additions
and
20 deletions
block-qcow.c
... | ... | @@ -339,28 +339,33 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, |
339 | 339 | return -1; |
340 | 340 | } else { |
341 | 341 | cluster_offset = bdrv_getlength(s->hd); |
342 | - /* round to cluster size */ | |
343 | - cluster_offset = (cluster_offset + s->cluster_size - 1) & | |
344 | - ~(s->cluster_size - 1); | |
345 | - bdrv_truncate(s->hd, cluster_offset + s->cluster_size); | |
346 | - /* if encrypted, we must initialize the cluster | |
347 | - content which won't be written */ | |
348 | - if (s->crypt_method && | |
349 | - (n_end - n_start) < s->cluster_sectors) { | |
350 | - uint64_t start_sect; | |
351 | - start_sect = (offset & ~(s->cluster_size - 1)) >> 9; | |
352 | - memset(s->cluster_data + 512, 0x00, 512); | |
353 | - for(i = 0; i < s->cluster_sectors; i++) { | |
354 | - if (i < n_start || i >= n_end) { | |
355 | - encrypt_sectors(s, start_sect + i, | |
356 | - s->cluster_data, | |
357 | - s->cluster_data + 512, 1, 1, | |
358 | - &s->aes_encrypt_key); | |
359 | - if (bdrv_pwrite(s->hd, cluster_offset + i * 512, | |
360 | - s->cluster_data, 512) != 512) | |
361 | - return -1; | |
342 | + if (allocate == 1) { | |
343 | + /* round to cluster size */ | |
344 | + cluster_offset = (cluster_offset + s->cluster_size - 1) & | |
345 | + ~(s->cluster_size - 1); | |
346 | + bdrv_truncate(s->hd, cluster_offset + s->cluster_size); | |
347 | + /* if encrypted, we must initialize the cluster | |
348 | + content which won't be written */ | |
349 | + if (s->crypt_method && | |
350 | + (n_end - n_start) < s->cluster_sectors) { | |
351 | + uint64_t start_sect; | |
352 | + start_sect = (offset & ~(s->cluster_size - 1)) >> 9; | |
353 | + memset(s->cluster_data + 512, 0x00, 512); | |
354 | + for(i = 0; i < s->cluster_sectors; i++) { | |
355 | + if (i < n_start || i >= n_end) { | |
356 | + encrypt_sectors(s, start_sect + i, | |
357 | + s->cluster_data, | |
358 | + s->cluster_data + 512, 1, 1, | |
359 | + &s->aes_encrypt_key); | |
360 | + if (bdrv_pwrite(s->hd, cluster_offset + i * 512, | |
361 | + s->cluster_data, 512) != 512) | |
362 | + return -1; | |
363 | + } | |
362 | 364 | } |
363 | 365 | } |
366 | + } else if (allocate == 2) { | |
367 | + cluster_offset |= QCOW_OFLAG_COMPRESSED | | |
368 | + (uint64_t)compressed_size << (63 - s->cluster_bits); | |
364 | 369 | } |
365 | 370 | } |
366 | 371 | /* update L2 table */ | ... | ... |