Commit 436e15b827be64cf29b2154863af39f71e5ea7d9
1 parent
550be127
win32 fixes (initial patch by kazu)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2078 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
30 additions
and
20 deletions
block-raw.c
| ... | ... | @@ -518,7 +518,6 @@ BlockDriver bdrv_raw = { |
| 518 | 518 | #else /* _WIN32 */ |
| 519 | 519 | |
| 520 | 520 | /* XXX: use another file ? */ |
| 521 | -#include <windows.h> | |
| 522 | 521 | #include <winioctl.h> |
| 523 | 522 | |
| 524 | 523 | typedef struct BDRVRawState { |
| ... | ... | @@ -600,12 +599,14 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, |
| 600 | 599 | memset(&ov, 0, sizeof(ov)); |
| 601 | 600 | ov.Offset = offset; |
| 602 | 601 | ov.OffsetHigh = offset >> 32; |
| 603 | - ret = ReadFile(s->hfile, buf, count, NULL, &ov); | |
| 604 | - if (!ret) | |
| 605 | - return -EIO; | |
| 606 | - ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); | |
| 607 | - if (!ret) | |
| 608 | - return -EIO; | |
| 602 | + ret = ReadFile(s->hfile, buf, count, &ret_count, &ov); | |
| 603 | + if (!ret) { | |
| 604 | + ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); | |
| 605 | + if (!ret) | |
| 606 | + return -EIO; | |
| 607 | + else | |
| 608 | + return ret_count; | |
| 609 | + } | |
| 609 | 610 | return ret_count; |
| 610 | 611 | } |
| 611 | 612 | |
| ... | ... | @@ -620,30 +621,31 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset, |
| 620 | 621 | memset(&ov, 0, sizeof(ov)); |
| 621 | 622 | ov.Offset = offset; |
| 622 | 623 | ov.OffsetHigh = offset >> 32; |
| 623 | - ret = WriteFile(s->hfile, buf, count, NULL, &ov); | |
| 624 | - if (!ret) | |
| 625 | - return -EIO; | |
| 626 | - ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); | |
| 627 | - if (!ret) | |
| 628 | - return -EIO; | |
| 624 | + ret = WriteFile(s->hfile, buf, count, &ret_count, &ov); | |
| 625 | + if (!ret) { | |
| 626 | + ret = GetOverlappedResult(s->hfile, &ov, &ret_count, TRUE); | |
| 627 | + if (!ret) | |
| 628 | + return -EIO; | |
| 629 | + else | |
| 630 | + return ret_count; | |
| 631 | + } | |
| 629 | 632 | return ret_count; |
| 630 | 633 | } |
| 631 | 634 | |
| 632 | 635 | static int raw_aio_new(BlockDriverAIOCB *acb) |
| 633 | 636 | { |
| 634 | 637 | RawAIOCB *acb1; |
| 635 | - BDRVRawState *s = acb->bs->opaque; | |
| 636 | 638 | |
| 637 | 639 | acb1 = qemu_mallocz(sizeof(RawAIOCB)); |
| 638 | 640 | if (!acb1) |
| 639 | 641 | return -ENOMEM; |
| 640 | 642 | acb->opaque = acb1; |
| 641 | - s->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); | |
| 642 | - if (!s->hEvent) | |
| 643 | + acb1->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); | |
| 644 | + if (!acb1->hEvent) | |
| 643 | 645 | return -ENOMEM; |
| 644 | 646 | return 0; |
| 645 | 647 | } |
| 646 | - | |
| 648 | +#ifndef QEMU_TOOL | |
| 647 | 649 | static void raw_aio_cb(void *opaque) |
| 648 | 650 | { |
| 649 | 651 | BlockDriverAIOCB *acb = opaque; |
| ... | ... | @@ -660,7 +662,7 @@ static void raw_aio_cb(void *opaque) |
| 660 | 662 | acb->cb(acb->cb_opaque, 0); |
| 661 | 663 | } |
| 662 | 664 | } |
| 663 | - | |
| 665 | +#endif | |
| 664 | 666 | static int raw_aio_read(BlockDriverAIOCB *acb, int64_t sector_num, |
| 665 | 667 | uint8_t *buf, int nb_sectors) |
| 666 | 668 | { |
| ... | ... | @@ -676,7 +678,9 @@ static int raw_aio_read(BlockDriverAIOCB *acb, int64_t sector_num, |
| 676 | 678 | acb1->ov.OffsetHigh = offset >> 32; |
| 677 | 679 | acb1->ov.hEvent = acb1->hEvent; |
| 678 | 680 | acb1->count = nb_sectors * 512; |
| 681 | +#ifndef QEMU_TOOL | |
| 679 | 682 | qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb); |
| 683 | +#endif | |
| 680 | 684 | ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov); |
| 681 | 685 | if (!ret) |
| 682 | 686 | return -EIO; |
| ... | ... | @@ -698,7 +702,9 @@ static int raw_aio_write(BlockDriverAIOCB *acb, int64_t sector_num, |
| 698 | 702 | acb1->ov.OffsetHigh = offset >> 32; |
| 699 | 703 | acb1->ov.hEvent = acb1->hEvent; |
| 700 | 704 | acb1->count = nb_sectors * 512; |
| 705 | +#ifndef QEMU_TOOL | |
| 701 | 706 | qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb); |
| 707 | +#endif | |
| 702 | 708 | ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov); |
| 703 | 709 | if (!ret) |
| 704 | 710 | return -EIO; |
| ... | ... | @@ -709,9 +715,11 @@ static void raw_aio_cancel(BlockDriverAIOCB *acb) |
| 709 | 715 | { |
| 710 | 716 | BlockDriverState *bs = acb->bs; |
| 711 | 717 | BDRVRawState *s = bs->opaque; |
| 718 | +#ifndef QEMU_TOOL | |
| 712 | 719 | RawAIOCB *acb1 = acb->opaque; |
| 713 | 720 | |
| 714 | 721 | qemu_del_wait_object(acb1->ov.hEvent, raw_aio_cb, acb); |
| 722 | +#endif | |
| 715 | 723 | /* XXX: if more than one async I/O it is not correct */ |
| 716 | 724 | CancelIo(s->hfile); |
| 717 | 725 | } |
| ... | ... | @@ -753,8 +761,10 @@ static int64_t raw_getlength(BlockDriverState *bs) |
| 753 | 761 | { |
| 754 | 762 | BDRVRawState *s = bs->opaque; |
| 755 | 763 | LARGE_INTEGER l; |
| 756 | - if (!GetFileSizeEx(s->hfile, &l)) | |
| 757 | - return -EIO; | |
| 764 | + | |
| 765 | + l.LowPart = GetFileSize(s->hfile, &l.HighPart); | |
| 766 | + if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR) | |
| 767 | + return -EIO; | |
| 758 | 768 | return l.QuadPart; |
| 759 | 769 | } |
| 760 | 770 | ... | ... |