X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=block.c;h=9549b9eff9f3034fdfae86e239851db459b9c0da;hb=021a1318604e0898cee3800d5b13033e68191f4e;hp=24a25d569be8149f10b153e4fdbbc7c21b1c2f21;hpb=924f766af9be3ff036a419fc85ed740aa01f8eac;p=qemu.git diff --git a/block.c b/block.c index 24a25d569..9549b9eff 100644 --- a/block.c +++ b/block.c @@ -1146,6 +1146,25 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset) return ret; } +/** + * Length of a allocated file in bytes. Sparse files are counted by actual + * allocated space. Return < 0 if error or unknown. + */ +int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) +{ + BlockDriver *drv = bs->drv; + if (!drv) { + return -ENOMEDIUM; + } + if (drv->bdrv_get_allocated_file_size) { + return drv->bdrv_get_allocated_file_size(bs); + } + if (bs->file) { + return bdrv_get_allocated_file_size(bs->file); + } + return -ENOTSUP; +} + /** * Length of a file in bytes. Return < 0 if error or unknown. */