mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-11-05 20:35:44 +00:00
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:
parent
550be12730
commit
436e15b827
1 changed files with 30 additions and 20 deletions
50
block-raw.c
50
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue