aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2006-08-03 09:07:19 +0000
committerbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2006-08-03 09:07:19 +0000
commit436e15b827be64cf29b2154863af39f71e5ea7d9 (patch)
treeee19347787b2b934c8f905b70b77416a3ede6a35
parent550be12730cfe3c2374deed6189bad281f476ec7 (diff)
win32 fixes (initial patch by kazu)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2078 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--block-raw.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/block-raw.c b/block-raw.c
index 413a8c4732..33ad647414 100644
--- a/block-raw.c
+++ b/block-raw.c
@@ -518,7 +518,6 @@ BlockDriver bdrv_raw = {
#else /* _WIN32 */
/* XXX: use another file ? */
-#include <windows.h>
#include <winioctl.h>
typedef struct BDRVRawState {
@@ -600,12 +599,14 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
memset(&ov, 0, sizeof(ov));
ov.Offset = offset;
ov.OffsetHigh = offset >> 32;
- ret = ReadFile(s->hfile, buf, count, NULL, &ov);
- if (!ret)
- return -EIO;
- ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE);
- if (!ret)
- return -EIO;
+ ret = ReadFile(s->hfile, buf, count, &ret_count, &ov);
+ if (!ret) {
+ ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE);
+ if (!ret)
+ return -EIO;
+ else
+ return ret_count;
+ }
return ret_count;
}
@@ -620,30 +621,31 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
memset(&ov, 0, sizeof(ov));
ov.Offset = offset;
ov.OffsetHigh = offset >> 32;
- ret = WriteFile(s->hfile, buf, count, NULL, &ov);
- if (!ret)
- return -EIO;
- ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE);
- if (!ret)
- return -EIO;
+ ret = WriteFile(s->hfile, buf, count, &ret_count, &ov);
+ if (!ret) {
+ ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE);
+ if (!ret)
+ return -EIO;
+ else
+ return ret_count;
+ }
return ret_count;
}
static int raw_aio_new(BlockDriverAIOCB *acb)
{
RawAIOCB *acb1;
- BDRVRawState *s = acb->bs->opaque;
acb1 = qemu_mallocz(sizeof(RawAIOCB));
if (!acb1)
return -ENOMEM;
acb->opaque = acb1;
- s->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (!s->hEvent)
+ acb1->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (!acb1->hEvent)
return -ENOMEM;
return 0;
}
-
+#ifndef QEMU_TOOL
static void raw_aio_cb(void *opaque)
{
BlockDriverAIOCB *acb = opaque;
@@ -660,7 +662,7 @@ static void raw_aio_cb(void *opaque)
acb->cb(acb->cb_opaque, 0);
}
}
-
+#endif
static int raw_aio_read(BlockDriverAIOCB *acb, int64_t sector_num,
uint8_t *buf, int nb_sectors)
{
@@ -676,7 +678,9 @@ static int raw_aio_read(BlockDriverAIOCB *acb, int64_t sector_num,
acb1->ov.OffsetHigh = offset >> 32;
acb1->ov.hEvent = acb1->hEvent;
acb1->count = nb_sectors * 512;
+#ifndef QEMU_TOOL
qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb);
+#endif
ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov);
if (!ret)
return -EIO;
@@ -698,7 +702,9 @@ static int raw_aio_write(BlockDriverAIOCB *acb, int64_t sector_num,
acb1->ov.OffsetHigh = offset >> 32;
acb1->ov.hEvent = acb1->hEvent;
acb1->count = nb_sectors * 512;
+#ifndef QEMU_TOOL
qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb);
+#endif
ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov);
if (!ret)
return -EIO;
@@ -709,9 +715,11 @@ static void raw_aio_cancel(BlockDriverAIOCB *acb)
{
BlockDriverState *bs = acb->bs;
BDRVRawState *s = bs->opaque;
+#ifndef QEMU_TOOL
RawAIOCB *acb1 = acb->opaque;
qemu_del_wait_object(acb1->ov.hEvent, raw_aio_cb, acb);
+#endif
/* XXX: if more than one async I/O it is not correct */
CancelIo(s->hfile);
}
@@ -753,8 +761,10 @@ static int64_t raw_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
LARGE_INTEGER l;
- if (!GetFileSizeEx(s->hfile, &l))
- return -EIO;
+
+ l.LowPart = GetFileSize(s->hfile, &l.HighPart);
+ if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR)
+ return -EIO;
return l.QuadPart;
}