From patchwork Mon Dec 10 11:56:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabien Chouteau X-Patchwork-Id: 204858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9EADF2C01FB for ; Mon, 10 Dec 2012 22:56:42 +1100 (EST) Received: from localhost ([::1]:54460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ti1yQ-0004fg-Si for incoming@patchwork.ozlabs.org; Mon, 10 Dec 2012 06:56:38 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ti1yI-0004fA-Qn for qemu-devel@nongnu.org; Mon, 10 Dec 2012 06:56:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ti1yH-0000oR-1s for qemu-devel@nongnu.org; Mon, 10 Dec 2012 06:56:30 -0500 Received: from mel.act-europe.fr ([194.98.77.210]:53615) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ti1yG-0000oA-S8 for qemu-devel@nongnu.org; Mon, 10 Dec 2012 06:56:28 -0500 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 1A287CB3CAD; Mon, 10 Dec 2012 12:56:33 +0100 (CET) X-Virus-Scanned: amavisd-new at eu.adacore.com Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZTQEi43-O1ev; Mon, 10 Dec 2012 12:56:33 +0100 (CET) Received: from PomPomGalli.act-europe.fr (pompomgalli.act-europe.fr [10.10.1.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id D0D82CB313E; Mon, 10 Dec 2012 12:56:32 +0100 (CET) From: Fabien Chouteau To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2012 12:56:22 +0100 Message-Id: <1355140582-5354-1-git-send-email-chouteau@adacore.com> X-Mailer: git-send-email 1.7.9.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 194.98.77.210 Cc: kwolf@redhat.com, blauwirbel@gmail.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH] Fix error code checking for SetFilePointer() call X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org An error has occurred if the return value is invalid_set_file_pointer and getlasterror doesn't return no_error. Signed-off-by: Fabien Chouteau Acked-by: Stefan Hajnoczi --- block/raw-win32.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/block/raw-win32.c b/block/raw-win32.c index 0c05c58..ce207a3 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -303,13 +303,24 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset) { BDRVRawState *s = bs->opaque; LONG low, high; + DWORD dwPtrLow; low = offset; high = offset >> 32; - if (!SetFilePointer(s->hfile, low, &high, FILE_BEGIN)) - return -EIO; - if (!SetEndOfFile(s->hfile)) + + /* + * An error has occurred if the return value is INVALID_SET_FILE_POINTER + * and GetLastError doesn't return NO_ERROR. + */ + dwPtrLow = SetFilePointer(s->hfile, low, &high, FILE_BEGIN); + if (dwPtrLow == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) { + fprintf(stderr, "SetFilePointer error: %d\n", GetLastError()); + return -EIO; + } + if (SetEndOfFile(s->hfile) == 0) { + fprintf(stderr, "SetEndOfFile error: %d\n", GetLastError()); return -EIO; + } return 0; }