win32 fixes (initial patch by kazu)

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2078 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
bellard 2006-08-03 09:07:19 +00:00
parent 550be12730
commit 436e15b827
1 changed files with 30 additions and 20 deletions

View File

@ -518,7 +518,6 @@ BlockDriver bdrv_raw = {
#else /* _WIN32 */ #else /* _WIN32 */
/* XXX: use another file ? */ /* XXX: use another file ? */
#include <windows.h>
#include <winioctl.h> #include <winioctl.h>
typedef struct BDRVRawState { typedef struct BDRVRawState {
@ -600,12 +599,14 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
memset(&ov, 0, sizeof(ov)); memset(&ov, 0, sizeof(ov));
ov.Offset = offset; ov.Offset = offset;
ov.OffsetHigh = offset >> 32; ov.OffsetHigh = offset >> 32;
ret = ReadFile(s->hfile, buf, count, NULL, &ov); ret = ReadFile(s->hfile, buf, count, &ret_count, &ov);
if (!ret) if (!ret) {
return -EIO;
ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE);
if (!ret) if (!ret)
return -EIO; return -EIO;
else
return ret_count;
}
return ret_count; return ret_count;
} }
@ -620,30 +621,31 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
memset(&ov, 0, sizeof(ov)); memset(&ov, 0, sizeof(ov));
ov.Offset = offset; ov.Offset = offset;
ov.OffsetHigh = offset >> 32; ov.OffsetHigh = offset >> 32;
ret = WriteFile(s->hfile, buf, count, NULL, &ov); ret = WriteFile(s->hfile, buf, count, &ret_count, &ov);
if (!ret) if (!ret) {
return -EIO;
ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE);
if (!ret) if (!ret)
return -EIO; return -EIO;
else
return ret_count;
}
return ret_count; return ret_count;
} }
static int raw_aio_new(BlockDriverAIOCB *acb) static int raw_aio_new(BlockDriverAIOCB *acb)
{ {
RawAIOCB *acb1; RawAIOCB *acb1;
BDRVRawState *s = acb->bs->opaque;
acb1 = qemu_mallocz(sizeof(RawAIOCB)); acb1 = qemu_mallocz(sizeof(RawAIOCB));
if (!acb1) if (!acb1)
return -ENOMEM; return -ENOMEM;
acb->opaque = acb1; acb->opaque = acb1;
s->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); acb1->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!s->hEvent) if (!acb1->hEvent)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
} }
#ifndef QEMU_TOOL
static void raw_aio_cb(void *opaque) static void raw_aio_cb(void *opaque)
{ {
BlockDriverAIOCB *acb = opaque; BlockDriverAIOCB *acb = opaque;
@ -660,7 +662,7 @@ static void raw_aio_cb(void *opaque)
acb->cb(acb->cb_opaque, 0); acb->cb(acb->cb_opaque, 0);
} }
} }
#endif
static int raw_aio_read(BlockDriverAIOCB *acb, int64_t sector_num, static int raw_aio_read(BlockDriverAIOCB *acb, int64_t sector_num,
uint8_t *buf, int nb_sectors) 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.OffsetHigh = offset >> 32;
acb1->ov.hEvent = acb1->hEvent; acb1->ov.hEvent = acb1->hEvent;
acb1->count = nb_sectors * 512; acb1->count = nb_sectors * 512;
#ifndef QEMU_TOOL
qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb); qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb);
#endif
ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov); ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov);
if (!ret) if (!ret)
return -EIO; return -EIO;
@ -698,7 +702,9 @@ static int raw_aio_write(BlockDriverAIOCB *acb, int64_t sector_num,
acb1->ov.OffsetHigh = offset >> 32; acb1->ov.OffsetHigh = offset >> 32;
acb1->ov.hEvent = acb1->hEvent; acb1->ov.hEvent = acb1->hEvent;
acb1->count = nb_sectors * 512; acb1->count = nb_sectors * 512;
#ifndef QEMU_TOOL
qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb); qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb);
#endif
ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov); ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov);
if (!ret) if (!ret)
return -EIO; return -EIO;
@ -709,9 +715,11 @@ static void raw_aio_cancel(BlockDriverAIOCB *acb)
{ {
BlockDriverState *bs = acb->bs; BlockDriverState *bs = acb->bs;
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
#ifndef QEMU_TOOL
RawAIOCB *acb1 = acb->opaque; RawAIOCB *acb1 = acb->opaque;
qemu_del_wait_object(acb1->ov.hEvent, raw_aio_cb, acb); qemu_del_wait_object(acb1->ov.hEvent, raw_aio_cb, acb);
#endif
/* XXX: if more than one async I/O it is not correct */ /* XXX: if more than one async I/O it is not correct */
CancelIo(s->hfile); CancelIo(s->hfile);
} }
@ -753,7 +761,9 @@ static int64_t raw_getlength(BlockDriverState *bs)
{ {
BDRVRawState *s = bs->opaque; BDRVRawState *s = bs->opaque;
LARGE_INTEGER l; LARGE_INTEGER l;
if (!GetFileSizeEx(s->hfile, &l))
l.LowPart = GetFileSize(s->hfile, &l.HighPart);
if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR)
return -EIO; return -EIO;
return l.QuadPart; return l.QuadPart;
} }