From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqfwO-0007Co-IA for qemu-devel@nongnu.org; Tue, 18 Nov 2014 05:23:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqfwI-0008PW-Da for qemu-devel@nongnu.org; Tue, 18 Nov 2014 05:23:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34440) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqfwI-0008PQ-59 for qemu-devel@nongnu.org; Tue, 18 Nov 2014 05:23:14 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAIANDUx024297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 18 Nov 2014 05:23:13 -0500 From: Max Reitz Date: Tue, 18 Nov 2014 11:23:04 +0100 Message-Id: <1416306186-19053-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1416306186-19053-1-git-send-email-mreitz@redhat.com> References: <1416306186-19053-1-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH for-2.2 1/3] block/raw-posix: Fix preallocating write() loop List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?L=C3=A1szl=C3=B3=20=C3=89rsek?= , Stefan Hajnoczi , Max Reitz 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=C3=A1szl=C3=B3 =C3=89rsek Signed-off-by: Max Reitz --- An interesting anecdote: My German man page for write(2) says the following about its return value: > Bei Erfolg wird Null zur=C3=BCckgegeben. Which translates to: > On success, zero is returned. Whereas write(2) for LANG=3DC 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, QemuOpt= s *opts, Error **errp) "Could not write to the new file"); break; } - left -=3D num; + left -=3D result; } fsync(fd); g_free(buf); --=20 1.9.3