diff options
Diffstat (limited to 'block/file-posix.c')
-rw-r--r-- | block/file-posix.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/block/file-posix.c b/block/file-posix.c index 0c4896876e..1941fb6749 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -25,8 +25,6 @@ #include "qapi/error.h" #include "qemu/cutils.h" #include "qemu/error-report.h" -#include "qemu/timer.h" -#include "qemu/log.h" #include "block/block_int.h" #include "qemu/module.h" #include "trace.h" @@ -1409,24 +1407,31 @@ static void raw_close(BlockDriverState *bs) } } -static int raw_truncate(BlockDriverState *bs, int64_t offset) +static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) { BDRVRawState *s = bs->opaque; struct stat st; + int ret; if (fstat(s->fd, &st)) { - return -errno; + ret = -errno; + error_setg_errno(errp, -ret, "Failed to fstat() the file"); + return ret; } if (S_ISREG(st.st_mode)) { if (ftruncate(s->fd, offset) < 0) { - return -errno; + ret = -errno; + error_setg_errno(errp, -ret, "Failed to resize the file"); + return ret; } } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { - if (offset > raw_getlength(bs)) { - return -EINVAL; - } + if (offset > raw_getlength(bs)) { + error_setg(errp, "Cannot grow device files"); + return -EINVAL; + } } else { + error_setg(errp, "Resizing this file is not supported"); return -ENOTSUP; } |