qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Fix error code checking for SetFilePointer() call
@ 2012-12-10 11:56 Fabien Chouteau
  2012-12-11  9:21 ` Stefan Hajnoczi
  0 siblings, 1 reply; 4+ messages in thread
From: Fabien Chouteau @ 2012-12-10 11:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, blauwirbel, stefanha

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 <chouteau@adacore.com>
---
 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;
 }
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Fix error code checking for SetFilePointer() call
  2012-12-10 11:56 [Qemu-devel] [PATCH] Fix error code checking for SetFilePointer() call Fabien Chouteau
@ 2012-12-11  9:21 ` Stefan Hajnoczi
  2012-12-11 10:37   ` Kevin Wolf
  2012-12-11 17:44   ` Fabien Chouteau
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2012-12-11  9:21 UTC (permalink / raw)
  To: Fabien Chouteau; +Cc: kwolf, blauwirbel, qemu-devel

On Mon, Dec 10, 2012 at 12:56:22PM +0100, Fabien Chouteau wrote:
> 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 <chouteau@adacore.com>
> ---
>  block/raw-win32.c |   17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)

The fprintf() is kind of iffy but we only return -EIO so I guess it
helps to print the full error.

Acked-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Fix error code checking for SetFilePointer() call
  2012-12-11  9:21 ` Stefan Hajnoczi
@ 2012-12-11 10:37   ` Kevin Wolf
  2012-12-11 17:44   ` Fabien Chouteau
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2012-12-11 10:37 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: blauwirbel, qemu-devel, Fabien Chouteau

Am 11.12.2012 10:21, schrieb Stefan Hajnoczi:
> On Mon, Dec 10, 2012 at 12:56:22PM +0100, Fabien Chouteau wrote:
>> 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 <chouteau@adacore.com>
>> ---
>>  block/raw-win32.c |   17 ++++++++++++++---
>>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> The fprintf() is kind of iffy but we only return -EIO so I guess it
> helps to print the full error.
> 
> Acked-by: Stefan Hajnoczi <stefanha@redhat.com>

Thanks, applied to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Fix error code checking for SetFilePointer() call
  2012-12-11  9:21 ` Stefan Hajnoczi
  2012-12-11 10:37   ` Kevin Wolf
@ 2012-12-11 17:44   ` Fabien Chouteau
  1 sibling, 0 replies; 4+ messages in thread
From: Fabien Chouteau @ 2012-12-11 17:44 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: kwolf, blauwirbel, qemu-devel

On 12/11/2012 10:21 AM, Stefan Hajnoczi wrote:
> The fprintf() is kind of iffy but we only return -EIO so I guess it
> helps to print the full error.

I add it because it took me a while to get to the actual error. Without
it the error message is even more cryptic:

qemu-system-ppc.exe: -hda fat:no-mbr:rw:.: could not open disk image fat:no-mbr:rw:.: Operation not permitted

At least it helps to find where the error comes from.

-- 
Fabien Chouteau

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-11 17:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-10 11:56 [Qemu-devel] [PATCH] Fix error code checking for SetFilePointer() call Fabien Chouteau
2012-12-11  9:21 ` Stefan Hajnoczi
2012-12-11 10:37   ` Kevin Wolf
2012-12-11 17:44   ` Fabien Chouteau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).