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 <ler...@redhat.com> Signed-off-by: Max Reitz <mre...@redhat.com> --- An interesting anecdote: My German man page for write(2) says the following about its return value: > Bei Erfolg wird Null zurückgegeben. Which translates to: > On success, zero is returned. Whereas write(2) for LANG=C says the following (which is correct): > On success, the number of bytes written is returned (zero indicates > nothing was written). I think I know why I somehow prefer the English versions... --- 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 e100ae2..4e6552f 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1457,7 +1457,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); -- 1.9.3