From 39411cf3c316de0fe3cbb9585774bacfe3bd8efd Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Tue, 18 Nov 2014 11:23:04 +0100 Subject: [PATCH] block/raw-posix: Fix preallocating write() loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- block/raw-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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);