As BDRV_SECTOR_SIZE is of type uint64_t, the expression will automatically convert the @ret to uint64_t. When an error code returned from bdrv_nb_sectors(), the promoted @ret will be a very large number, as a result the -EFBIG will be returned which is not the real error code.
Signed-off-by: Guoyi Tu <tu.gu...@h3c.com> --- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block.c b/block.c index 430edf7..f14254c 100644 --- a/block.c +++ b/block.c @@ -5082,7 +5082,7 @@ int64_t bdrv_getlength(BlockDriverState *bs) { int64_t ret = bdrv_nb_sectors(bs); - ret = ret > INT64_MAX / BDRV_SECTOR_SIZE ? -EFBIG : ret; + ret = ret > INT64_MAX / (int64_t)BDRV_SECTOR_SIZE ? -EFBIG : ret; return ret < 0 ? ret : ret * BDRV_SECTOR_SIZE; } -- 2.7.4 Please ignore the [PATCH] block: Return the real error code in bdrv_getlength -- Best regards, Guoyi