From: Max Reitz Date: Tue, 18 Nov 2014 10:23:04 +0000 (+0100) Subject: block/raw-posix: Fix preallocating write() loop X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=39411cf3c316de0fe3cbb9585774bacfe3bd8efd;p=qemu.git block/raw-posix: Fix preallocating write() loop write() may write less bytes than requested; in this case, the number of bytes written is returned. This is the byte count we should be subtracting from the number of bytes still to be written, and not the byte count we requested to write. Reported-by: László Érsek Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- diff --git a/block/raw-posix.c b/block/raw-posix.c index 414e6d1e91..e0e48c5f51 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1451,7 +1451,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp) "Could not write to the new file"); break; } - left -= num; + left -= result; } fsync(fd); g_free(buf);