Commit 436e15b827be64cf29b2154863af39f71e5ea7d9

Authored by bellard
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,7 +518,6 @@ BlockDriver bdrv_raw = {
518 #else /* _WIN32 */ 518 #else /* _WIN32 */
519 519
520 /* XXX: use another file ? */ 520 /* XXX: use another file ? */
521 -#include <windows.h>  
522 #include <winioctl.h> 521 #include <winioctl.h>
523 522
524 typedef struct BDRVRawState { 523 typedef struct BDRVRawState {
@@ -600,12 +599,14 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, @@ -600,12 +599,14 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
600 memset(&ov, 0, sizeof(ov)); 599 memset(&ov, 0, sizeof(ov));
601 ov.Offset = offset; 600 ov.Offset = offset;
602 ov.OffsetHigh = offset >> 32; 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 return ret_count; 610 return ret_count;
610 } 611 }
611 612
@@ -620,30 +621,31 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset, @@ -620,30 +621,31 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
620 memset(&ov, 0, sizeof(ov)); 621 memset(&ov, 0, sizeof(ov));
621 ov.Offset = offset; 622 ov.Offset = offset;
622 ov.OffsetHigh = offset >> 32; 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 return ret_count; 632 return ret_count;
630 } 633 }
631 634
632 static int raw_aio_new(BlockDriverAIOCB *acb) 635 static int raw_aio_new(BlockDriverAIOCB *acb)
633 { 636 {
634 RawAIOCB *acb1; 637 RawAIOCB *acb1;
635 - BDRVRawState *s = acb->bs->opaque;  
636 638
637 acb1 = qemu_mallocz(sizeof(RawAIOCB)); 639 acb1 = qemu_mallocz(sizeof(RawAIOCB));
638 if (!acb1) 640 if (!acb1)
639 return -ENOMEM; 641 return -ENOMEM;
640 acb->opaque = acb1; 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 return -ENOMEM; 645 return -ENOMEM;
644 return 0; 646 return 0;
645 } 647 }
646 - 648 +#ifndef QEMU_TOOL
647 static void raw_aio_cb(void *opaque) 649 static void raw_aio_cb(void *opaque)
648 { 650 {
649 BlockDriverAIOCB *acb = opaque; 651 BlockDriverAIOCB *acb = opaque;
@@ -660,7 +662,7 @@ static void raw_aio_cb(void *opaque) @@ -660,7 +662,7 @@ static void raw_aio_cb(void *opaque)
660 acb->cb(acb->cb_opaque, 0); 662 acb->cb(acb->cb_opaque, 0);
661 } 663 }
662 } 664 }
663 - 665 +#endif
664 static int raw_aio_read(BlockDriverAIOCB *acb, int64_t sector_num, 666 static int raw_aio_read(BlockDriverAIOCB *acb, int64_t sector_num,
665 uint8_t *buf, int nb_sectors) 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,7 +678,9 @@ static int raw_aio_read(BlockDriverAIOCB *acb, int64_t sector_num,
676 acb1->ov.OffsetHigh = offset >> 32; 678 acb1->ov.OffsetHigh = offset >> 32;
677 acb1->ov.hEvent = acb1->hEvent; 679 acb1->ov.hEvent = acb1->hEvent;
678 acb1->count = nb_sectors * 512; 680 acb1->count = nb_sectors * 512;
  681 +#ifndef QEMU_TOOL
679 qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb); 682 qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb);
  683 +#endif
680 ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov); 684 ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov);
681 if (!ret) 685 if (!ret)
682 return -EIO; 686 return -EIO;
@@ -698,7 +702,9 @@ static int raw_aio_write(BlockDriverAIOCB *acb, int64_t sector_num, @@ -698,7 +702,9 @@ static int raw_aio_write(BlockDriverAIOCB *acb, int64_t sector_num,
698 acb1->ov.OffsetHigh = offset >> 32; 702 acb1->ov.OffsetHigh = offset >> 32;
699 acb1->ov.hEvent = acb1->hEvent; 703 acb1->ov.hEvent = acb1->hEvent;
700 acb1->count = nb_sectors * 512; 704 acb1->count = nb_sectors * 512;
  705 +#ifndef QEMU_TOOL
701 qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb); 706 qemu_add_wait_object(acb1->ov.hEvent, raw_aio_cb, acb);
  707 +#endif
702 ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov); 708 ret = ReadFile(s->hfile, buf, acb1->count, NULL, &acb1->ov);
703 if (!ret) 709 if (!ret)
704 return -EIO; 710 return -EIO;
@@ -709,9 +715,11 @@ static void raw_aio_cancel(BlockDriverAIOCB *acb) @@ -709,9 +715,11 @@ static void raw_aio_cancel(BlockDriverAIOCB *acb)
709 { 715 {
710 BlockDriverState *bs = acb->bs; 716 BlockDriverState *bs = acb->bs;
711 BDRVRawState *s = bs->opaque; 717 BDRVRawState *s = bs->opaque;
  718 +#ifndef QEMU_TOOL
712 RawAIOCB *acb1 = acb->opaque; 719 RawAIOCB *acb1 = acb->opaque;
713 720
714 qemu_del_wait_object(acb1->ov.hEvent, raw_aio_cb, acb); 721 qemu_del_wait_object(acb1->ov.hEvent, raw_aio_cb, acb);
  722 +#endif
715 /* XXX: if more than one async I/O it is not correct */ 723 /* XXX: if more than one async I/O it is not correct */
716 CancelIo(s->hfile); 724 CancelIo(s->hfile);
717 } 725 }
@@ -753,8 +761,10 @@ static int64_t raw_getlength(BlockDriverState *bs) @@ -753,8 +761,10 @@ static int64_t raw_getlength(BlockDriverState *bs)
753 { 761 {
754 BDRVRawState *s = bs->opaque; 762 BDRVRawState *s = bs->opaque;
755 LARGE_INTEGER l; 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 return l.QuadPart; 768 return l.QuadPart;
759 } 769 }
760 770