mirror of https://github.com/xemu-project/xemu.git
block: Respect underlying file's EOF
When falling through to the underlying file in bdrv_co_get_block_status(), if it returns that the query offset is beyond the file end (by setting *pnum to 0), return the range to be zero and do not let the number of sectors for which information could be obtained be overwritten. Signed-off-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
7f75a07d50
commit
59c9a95fd2
15
block.c
15
block.c
|
@ -3954,13 +3954,24 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
|
||||||
if (bs->file &&
|
if (bs->file &&
|
||||||
(ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
|
(ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
|
||||||
(ret & BDRV_BLOCK_OFFSET_VALID)) {
|
(ret & BDRV_BLOCK_OFFSET_VALID)) {
|
||||||
|
int file_pnum;
|
||||||
|
|
||||||
ret2 = bdrv_co_get_block_status(bs->file, ret >> BDRV_SECTOR_BITS,
|
ret2 = bdrv_co_get_block_status(bs->file, ret >> BDRV_SECTOR_BITS,
|
||||||
*pnum, pnum);
|
*pnum, &file_pnum);
|
||||||
if (ret2 >= 0) {
|
if (ret2 >= 0) {
|
||||||
/* Ignore errors. This is just providing extra information, it
|
/* Ignore errors. This is just providing extra information, it
|
||||||
* is useful but not necessary.
|
* is useful but not necessary.
|
||||||
*/
|
*/
|
||||||
ret |= (ret2 & BDRV_BLOCK_ZERO);
|
if (!file_pnum) {
|
||||||
|
/* !file_pnum indicates an offset at or beyond the EOF; it is
|
||||||
|
* perfectly valid for the format block driver to point to such
|
||||||
|
* offsets, so catch it and mark everything as zero */
|
||||||
|
ret |= BDRV_BLOCK_ZERO;
|
||||||
|
} else {
|
||||||
|
/* Limit request to the range reported by the protocol driver */
|
||||||
|
*pnum = file_pnum;
|
||||||
|
ret |= (ret2 & BDRV_BLOCK_ZERO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue