Commit 537a1d4bb02b7c5d21c8f3c853f7c7ae3782bc3f
1 parent
610626af
Fix regression introduced by r6824
The changes introduced by r6824 broke a subtle, and admittedly obscure, aspect of the block API. While bdrv_{pread,pwrite} return the number of bytes read or written upon success, bdrv_{read,write} returns a zero upon success. When using bdrv_pread for bdrv_read, special care must be taken to handle this case. This fixes certain guest images (notably linux-0.2 provided on the qemu website). Reported-by: malc <av1474@comtv.ru> Reported-by: Herve Poussineau <hpoussin@reactos.org> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6828 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
15 additions
and
2 deletions
block-raw-posix.c
... | ... | @@ -361,7 +361,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, |
361 | 361 | static int raw_read(BlockDriverState *bs, int64_t sector_num, |
362 | 362 | uint8_t *buf, int nb_sectors) |
363 | 363 | { |
364 | - return raw_pread(bs, sector_num * 512, buf, (uint64_t)nb_sectors * 512); | |
364 | + int ret; | |
365 | + | |
366 | + ret = raw_pread(bs, sector_num * 512, buf, nb_sectors * 512); | |
367 | + if (ret == (nb_sectors * 512)) | |
368 | + ret = 0; | |
369 | + return ret; | |
365 | 370 | } |
366 | 371 | |
367 | 372 | /* |
... | ... | @@ -445,7 +450,11 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset, |
445 | 450 | static int raw_write(BlockDriverState *bs, int64_t sector_num, |
446 | 451 | const uint8_t *buf, int nb_sectors) |
447 | 452 | { |
448 | - return raw_pwrite(bs, sector_num * 512, buf, (uint64_t)nb_sectors * 512); | |
453 | + int ret; | |
454 | + ret = raw_pwrite(bs, sector_num * 512, buf, nb_sectors * 512); | |
455 | + if (ret == (nb_sectors * 512)) | |
456 | + ret = 0; | |
457 | + return ret; | |
449 | 458 | } |
450 | 459 | |
451 | 460 | #ifdef CONFIG_AIO | ... | ... |
block-raw-win32.c
... | ... | @@ -145,6 +145,8 @@ static int raw_read(BlockDriverState *bs, int64_t sector_num, |
145 | 145 | #endif |
146 | 146 | return ret_count; |
147 | 147 | } |
148 | + if (ret_count == count) | |
149 | + ret_count = 0; | |
148 | 150 | return ret_count; |
149 | 151 | } |
150 | 152 | |
... | ... | @@ -171,6 +173,8 @@ static int raw_write(BlockDriverState *bs, int64_t sector_num, |
171 | 173 | #endif |
172 | 174 | return ret_count; |
173 | 175 | } |
176 | + if (ret_count == count) | |
177 | + ret_count = 0; | |
174 | 178 | return ret_count; |
175 | 179 | } |
176 | 180 | ... | ... |