From c2eb918e3299f930fd0d0ae48d002cf2599de250 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Wed, 10 Sep 2014 17:05:45 +0800 Subject: block: round up file size to nearest sector Currently the file size requested by user is rounded down to nearest sector, causing the actual file size could be a bit less than the size user requested. Since some formats (like qcow2) record virtual disk size in bytes, this can make the last few bytes cannot be accessed. This patch fixes it by rounding up file size to nearest sector so that the actual file size is no less than the requested file size. Signed-off-by: Hu Tao Reviewed-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vhdx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'block/vhdx.c') diff --git a/block/vhdx.c b/block/vhdx.c index 87c99fc260..796b7bd884 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1766,7 +1766,8 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp) VHDXImageType image_type; Error *local_err = NULL; - image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); + image_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), + BDRV_SECTOR_SIZE); log_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_LOG_SIZE, 0); block_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_BLOCK_SIZE, 0); type = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); -- cgit v1.2.1