Changeset 37596 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Jun 22, 2011 7:30:06 PM (13 years ago)
- Location:
- trunk/src/VBox/Runtime/r3/win
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/fileaio-win.cpp
r35408 r37596 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 189 189 190 190 pReqInt->enmTransferDirection = enmTransferDirection; 191 pReqInt->hFile = (HANDLE)hFile;191 pReqInt->hFile = RTFileToNative(hFile); 192 192 pReqInt->Overlapped.Offset = (DWORD)(off & 0xffffffff); 193 193 pReqInt->Overlapped.OffsetHigh = (DWORD)(off >> 32); … … 318 318 RTFILEAIOCTX_VALID_RETURN(pCtxInt); 319 319 320 HANDLE hTemp = CreateIoCompletionPort( (HANDLE)hFile, pCtxInt->hIoCompletionPort, 0, 1);320 HANDLE hTemp = CreateIoCompletionPort(RTFileToNative(hFile), pCtxInt->hIoCompletionPort, 0, 1); 321 321 if (hTemp != pCtxInt->hIoCompletionPort) 322 322 rc = RTErrConvertFromWin32(GetLastError()); -
trunk/src/VBox/Runtime/r3/win/fileio-win.cpp
r36601 r37596 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 55 55 * 56 56 * @returns Success indicator. Extended error information obtainable using GetLastError(). 57 * @param FileFilehandle.57 * @param hFile Filehandle. 58 58 * @param offSeek Offset to seek. 59 59 * @param poffNew Where to store the new file offset. NULL allowed. 60 60 * @param uMethod Seek method. (The windows one!) 61 61 */ 62 DECLINLINE(bool) MySetFilePointer(RTFILE File, uint64_t offSeek, uint64_t *poffNew, unsigned uMethod)62 DECLINLINE(bool) MySetFilePointer(RTFILE hFile, uint64_t offSeek, uint64_t *poffNew, unsigned uMethod) 63 63 { 64 64 bool fRc; … … 69 69 if (off.LowPart != INVALID_SET_FILE_POINTER) 70 70 { 71 off.LowPart = SetFilePointer((HANDLE) File, off.LowPart, &off.HighPart, uMethod);71 off.LowPart = SetFilePointer((HANDLE)RTFileToNative(hFile), off.LowPart, &off.HighPart, uMethod); 72 72 fRc = off.LowPart != INVALID_SET_FILE_POINTER; 73 73 } … … 75 75 { 76 76 SetLastError(NO_ERROR); 77 off.LowPart = SetFilePointer( (HANDLE)File, off.LowPart, &off.HighPart, uMethod);77 off.LowPart = SetFilePointer(RTFileToNative(hFile), off.LowPart, &off.HighPart, uMethod); 78 78 fRc = GetLastError() == NO_ERROR; 79 79 } 80 80 #else 81 fRc = SetFilePointerEx((HANDLE) File, off, &off, uMethod);81 fRc = SetFilePointerEx((HANDLE)RTFileToNative(hFile), off, &off, uMethod); 82 82 #endif 83 83 if (fRc && poffNew) … … 92 92 * 93 93 * @returns true for file size limit exceeded. 94 * @param FileFilehandle.94 * @param hFile Filehandle. 95 95 * @param offSeek Offset to seek. 96 96 * @param uMethod The seek method. 97 97 */ 98 DECLINLINE(bool) IsBeyondLimit(RTFILE File, uint64_t offSeek, unsigned uMethod)98 DECLINLINE(bool) IsBeyondLimit(RTFILE hFile, uint64_t offSeek, unsigned uMethod) 99 99 { 100 100 bool fIsBeyondLimit = false; … … 108 108 * file seeking, only at the time of writing (and some other odd ones we cannot make use of). */ 109 109 uint64_t offCurrent; 110 if (MySetFilePointer( File, 0, &offCurrent, FILE_CURRENT))111 { 112 if (!MySetFilePointer( File, offSeek, NULL, uMethod))110 if (MySetFilePointer(hFile, 0, &offCurrent, FILE_CURRENT)) 111 { 112 if (!MySetFilePointer(hFile, offSeek, NULL, uMethod)) 113 113 fIsBeyondLimit = GetLastError() == ERROR_SEEK; 114 114 else /* Restore file pointer on success. */ 115 MySetFilePointer( File, offCurrent, NULL, FILE_BEGIN);115 MySetFilePointer(hFile, offCurrent, NULL, FILE_BEGIN); 116 116 } 117 117 … … 135 135 136 136 137 RTR3DECL(RTHCINTPTR) RTFileToNative(RTFILE File)138 { 139 AssertReturn( File != NIL_RTFILE, (RTHCINTPTR)INVALID_HANDLE_VALUE);140 return (RTHCINTPTR) File;141 } 142 143 144 RTR3DECL(int) RTFileOpen(PRTFILE pFile, const char *pszFilename, uint 32_t fOpen)137 RTR3DECL(RTHCINTPTR) RTFileToNative(RTFILE hFile) 138 { 139 AssertReturn(hFile != NIL_RTFILE, (RTHCINTPTR)INVALID_HANDLE_VALUE); 140 return (RTHCINTPTR)hFile; 141 } 142 143 144 RTR3DECL(int) RTFileOpen(PRTFILE pFile, const char *pszFilename, uint64_t fOpen) 145 145 { 146 146 /* … … 186 186 break; 187 187 default: 188 AssertMsgFailed(("Impossible fOpen=%# x\n", fOpen));188 AssertMsgFailed(("Impossible fOpen=%#llx\n", fOpen)); 189 189 return VERR_INVALID_PARAMETER; 190 190 } … … 207 207 break; 208 208 default: 209 AssertMsgFailed(("Impossible fOpen=%# x\n", fOpen));209 AssertMsgFailed(("Impossible fOpen=%#llx\n", fOpen)); 210 210 return VERR_INVALID_PARAMETER; 211 211 } … … 228 228 case RTFILE_O_READWRITE: dwDesiredAccess |= FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE; break; 229 229 default: 230 AssertMsgFailed(("Impossible fOpen=%# x\n", fOpen));230 AssertMsgFailed(("Impossible fOpen=%#llx\n", fOpen)); 231 231 return VERR_INVALID_PARAMETER; 232 232 } … … 246 246 case RTFILE_O_DENY_NOT_DELETE | RTFILE_O_DENY_READWRITE:dwShareMode = FILE_SHARE_DELETE; break; 247 247 default: 248 AssertMsgFailed(("Impossible fOpen=%# x\n", fOpen));248 AssertMsgFailed(("Impossible fOpen=%#llx\n", fOpen)); 249 249 return VERR_INVALID_PARAMETER; 250 250 } … … 329 329 330 330 331 RTR3DECL(int) RTFileOpenBitBucket(PRTFILE phFile, uint 32_t fAccess)331 RTR3DECL(int) RTFileOpenBitBucket(PRTFILE phFile, uint64_t fAccess) 332 332 { 333 333 AssertReturn( fAccess == RTFILE_O_READ … … 339 339 340 340 341 RTR3DECL(int) RTFileClose(RTFILE File)342 { 343 if ( File == NIL_RTFILE)344 return VINF_SUCCESS; 345 if (CloseHandle((HANDLE) File))341 RTR3DECL(int) RTFileClose(RTFILE hFile) 342 { 343 if (hFile == NIL_RTFILE) 344 return VINF_SUCCESS; 345 if (CloseHandle((HANDLE)RTFileToNative(hFile))) 346 346 return VINF_SUCCESS; 347 347 return RTErrConvertFromWin32(GetLastError()); … … 372 372 373 373 374 RTR3DECL(int) RTFileSeek(RTFILE File, int64_t offSeek, unsigned uMethod, uint64_t *poffActual)374 RTR3DECL(int) RTFileSeek(RTFILE hFile, int64_t offSeek, unsigned uMethod, uint64_t *poffActual) 375 375 { 376 376 static ULONG aulSeekRecode[] = … … 393 393 * Execute the seek. 394 394 */ 395 if (MySetFilePointer( File, offSeek, poffActual, aulSeekRecode[uMethod]))395 if (MySetFilePointer(hFile, offSeek, poffActual, aulSeekRecode[uMethod])) 396 396 return VINF_SUCCESS; 397 397 return RTErrConvertFromWin32(GetLastError()); … … 399 399 400 400 401 RTR3DECL(int) RTFileRead(RTFILE File, void *pvBuf, size_t cbToRead, size_t *pcbRead)401 RTR3DECL(int) RTFileRead(RTFILE hFile, void *pvBuf, size_t cbToRead, size_t *pcbRead) 402 402 { 403 403 if (cbToRead <= 0) … … 407 407 408 408 ULONG cbRead = 0; 409 if (ReadFile((HANDLE) File, pvBuf, cbToReadAdj, &cbRead, NULL))409 if (ReadFile((HANDLE)RTFileToNative(hFile), pvBuf, cbToReadAdj, &cbRead, NULL)) 410 410 { 411 411 if (pcbRead) … … 418 418 { 419 419 ULONG cbReadPart = 0; 420 if (!ReadFile((HANDLE) File, (char*)pvBuf + cbRead, cbToReadAdj - cbRead, &cbReadPart, NULL))420 if (!ReadFile((HANDLE)RTFileToNative(hFile), (char*)pvBuf + cbRead, cbToReadAdj - cbRead, &cbReadPart, NULL)) 421 421 return RTErrConvertFromWin32(GetLastError()); 422 422 if (cbReadPart == 0) … … 446 446 ULONG cbToRead = RT_MIN(cbChunk, cbToReadAdj - cbRead); 447 447 ULONG cbReadPart = 0; 448 if (!ReadFile((HANDLE) File, (char *)pvBuf + cbRead, cbToRead, &cbReadPart, NULL))448 if (!ReadFile((HANDLE)RTFileToNative(hFile), (char *)pvBuf + cbRead, cbToRead, &cbReadPart, NULL)) 449 449 { 450 450 /* If we failed because the buffer is too big, shrink it and … … 478 478 479 479 480 RTR3DECL(int) RTFileWrite(RTFILE File, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)480 RTR3DECL(int) RTFileWrite(RTFILE hFile, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten) 481 481 { 482 482 if (cbToWrite <= 0) … … 486 486 487 487 ULONG cbWritten = 0; 488 if (WriteFile((HANDLE) File, pvBuf, cbToWriteAdj, &cbWritten, NULL))488 if (WriteFile((HANDLE)RTFileToNative(hFile), pvBuf, cbToWriteAdj, &cbWritten, NULL)) 489 489 { 490 490 if (pcbWritten) … … 497 497 { 498 498 ULONG cbWrittenPart = 0; 499 if (!WriteFile((HANDLE)File, (char*)pvBuf + cbWritten, cbToWriteAdj - cbWritten, &cbWrittenPart, NULL)) 499 if (!WriteFile((HANDLE)RTFileToNative(hFile), (char*)pvBuf + cbWritten, 500 cbToWriteAdj - cbWritten, &cbWrittenPart, NULL)) 500 501 { 501 502 int rc = RTErrConvertFromWin32(GetLastError()); 502 503 if ( rc == VERR_DISK_FULL 503 && IsBeyondLimit( File, cbToWriteAdj - cbWritten, FILE_CURRENT)504 && IsBeyondLimit(RTFileToNative(hFile), cbToWriteAdj - cbWritten, FILE_CURRENT) 504 505 ) 505 506 rc = VERR_FILE_TOO_BIG; … … 532 533 ULONG cbToWrite = RT_MIN(cbChunk, cbToWriteAdj - cbWritten); 533 534 ULONG cbWrittenPart = 0; 534 if (!WriteFile((HANDLE) File, (const char *)pvBuf + cbWritten, cbToWrite, &cbWrittenPart, NULL))535 if (!WriteFile((HANDLE)RTFileToNative(hFile), (const char *)pvBuf + cbWritten, cbToWrite, &cbWrittenPart, NULL)) 535 536 { 536 537 /* If we failed because the buffer is too big, shrink it and … … 545 546 int rc = RTErrConvertFromWin32(dwErr); 546 547 if ( rc == VERR_DISK_FULL 547 && IsBeyondLimit( File, cbToWriteAdj - cbWritten, FILE_CURRENT))548 && IsBeyondLimit(hFile, cbToWriteAdj - cbWritten, FILE_CURRENT)) 548 549 rc = VERR_FILE_TOO_BIG; 549 550 return rc; … … 566 567 int rc = RTErrConvertFromWin32(dwErr); 567 568 if ( rc == VERR_DISK_FULL 568 && IsBeyondLimit( File, cbToWriteAdj - cbWritten, FILE_CURRENT))569 && IsBeyondLimit(hFile, cbToWriteAdj - cbWritten, FILE_CURRENT)) 569 570 rc = VERR_FILE_TOO_BIG; 570 571 return rc; … … 572 573 573 574 574 RTR3DECL(int) RTFileFlush(RTFILE File)575 { 576 if (!FlushFileBuffers((HANDLE) File))575 RTR3DECL(int) RTFileFlush(RTFILE hFile) 576 { 577 if (!FlushFileBuffers((HANDLE)RTFileToNative(hFile))) 577 578 { 578 579 int rc = GetLastError(); … … 584 585 585 586 586 RTR3DECL(int) RTFileSetSize(RTFILE File, uint64_t cbSize)587 RTR3DECL(int) RTFileSetSize(RTFILE hFile, uint64_t cbSize) 587 588 { 588 589 /* … … 591 592 int rc; 592 593 uint64_t offCurrent; 593 if (MySetFilePointer( File, 0, &offCurrent, FILE_CURRENT))594 if (MySetFilePointer(hFile, 0, &offCurrent, FILE_CURRENT)) 594 595 { 595 596 /* 596 597 * Set new file pointer. 597 598 */ 598 if (MySetFilePointer( File, cbSize, NULL, FILE_BEGIN))599 if (MySetFilePointer(hFile, cbSize, NULL, FILE_BEGIN)) 599 600 { 600 601 /* set file pointer */ 601 if (SetEndOfFile((HANDLE) File))602 if (SetEndOfFile((HANDLE)RTFileToNative(hFile))) 602 603 { 603 604 /* … … 605 606 * If the old pointer was beyond the new file end, ignore failure. 606 607 */ 607 if ( MySetFilePointer( File, offCurrent, NULL, FILE_BEGIN)608 if ( MySetFilePointer(hFile, offCurrent, NULL, FILE_BEGIN) 608 609 || offCurrent > cbSize) 609 610 return VINF_SUCCESS; … … 614 615 */ 615 616 rc = GetLastError(); 616 MySetFilePointer( File, offCurrent, NULL, FILE_BEGIN);617 MySetFilePointer(hFile, offCurrent, NULL, FILE_BEGIN); 617 618 } 618 619 else … … 626 627 627 628 628 RTR3DECL(int) RTFileGetSize(RTFILE File, uint64_t *pcbSize)629 RTR3DECL(int) RTFileGetSize(RTFILE hFile, uint64_t *pcbSize) 629 630 { 630 631 ULARGE_INTEGER Size; 631 Size.LowPart = GetFileSize((HANDLE) File, &Size.HighPart);632 Size.LowPart = GetFileSize((HANDLE)RTFileToNative(hFile), &Size.HighPart); 632 633 if (Size.LowPart != INVALID_FILE_SIZE) 633 634 { … … 641 642 642 643 643 RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE File, PRTFOFF pcbMax)644 RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE hFile, PRTFOFF pcbMax) 644 645 { 645 646 /** @todo r=bird: … … 653 654 654 655 655 RTR3DECL(bool) RTFileIsValid(RTFILE File)656 { 657 if ( File != NIL_RTFILE)658 { 659 DWORD dwType = GetFileType((HANDLE) File);656 RTR3DECL(bool) RTFileIsValid(RTFILE hFile) 657 { 658 if (hFile != NIL_RTFILE) 659 { 660 DWORD dwType = GetFileType((HANDLE)RTFileToNative(hFile)); 660 661 switch (dwType) 661 662 { … … 679 680 #define HIGH_DWORD(u64) (((DWORD *)&u64)[1]) 680 681 681 RTR3DECL(int) RTFileLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock)682 RTR3DECL(int) RTFileLock(RTFILE hFile, unsigned fLock, int64_t offLock, uint64_t cbLock) 682 683 { 683 684 Assert(offLock >= 0); … … 704 705 705 706 /* Note: according to Microsoft, LockFileEx API call is available starting from NT 3.5 */ 706 if (LockFileEx((HANDLE) File, dwFlags, 0, LOW_DWORD(cbLock), HIGH_DWORD(cbLock), &Overlapped))707 if (LockFileEx((HANDLE)RTFileToNative(hFile), dwFlags, 0, LOW_DWORD(cbLock), HIGH_DWORD(cbLock), &Overlapped)) 707 708 return VINF_SUCCESS; 708 709 … … 711 712 712 713 713 RTR3DECL(int) RTFileChangeLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock)714 RTR3DECL(int) RTFileChangeLock(RTFILE hFile, unsigned fLock, int64_t offLock, uint64_t cbLock) 714 715 { 715 716 Assert(offLock >= 0); … … 723 724 724 725 /* Remove old lock. */ 725 int rc = RTFileUnlock( File, offLock, cbLock);726 int rc = RTFileUnlock(hFile, offLock, cbLock); 726 727 if (RT_FAILURE(rc)) 727 728 return rc; 728 729 729 730 /* Set new lock. */ 730 rc = RTFileLock( File, fLock, offLock, cbLock);731 rc = RTFileLock(hFile, fLock, offLock, cbLock); 731 732 if (RT_SUCCESS(rc)) 732 733 return rc; … … 734 735 /* Try to restore old lock. */ 735 736 unsigned fLockOld = (fLock & RTFILE_LOCK_WRITE) ? fLock & ~RTFILE_LOCK_WRITE : fLock | RTFILE_LOCK_WRITE; 736 rc = RTFileLock( File, fLockOld, offLock, cbLock);737 rc = RTFileLock(hFile, fLockOld, offLock, cbLock); 737 738 if (RT_SUCCESS(rc)) 738 739 return VERR_FILE_LOCK_VIOLATION; … … 742 743 743 744 744 RTR3DECL(int) RTFileUnlock(RTFILE File, int64_t offLock, uint64_t cbLock)745 RTR3DECL(int) RTFileUnlock(RTFILE hFile, int64_t offLock, uint64_t cbLock) 745 746 { 746 747 Assert(offLock >= 0); 747 748 748 if (UnlockFile((HANDLE)File, LOW_DWORD(offLock), HIGH_DWORD(offLock), LOW_DWORD(cbLock), HIGH_DWORD(cbLock))) 749 if (UnlockFile((HANDLE)RTFileToNative(hFile), 750 LOW_DWORD(offLock), HIGH_DWORD(offLock), 751 LOW_DWORD(cbLock), HIGH_DWORD(cbLock))) 749 752 return VINF_SUCCESS; 750 753 … … 754 757 755 758 756 RTR3DECL(int) RTFileQueryInfo(RTFILE File, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)759 RTR3DECL(int) RTFileQueryInfo(RTFILE hFile, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs) 757 760 { 758 761 /* 759 762 * Validate input. 760 763 */ 761 if ( File == NIL_RTFILE)762 { 763 AssertMsgFailed(("Invalid File=%RTfile\n",File));764 if (hFile == NIL_RTFILE) 765 { 766 AssertMsgFailed(("Invalid hFile=%RTfile\n", hFile)); 764 767 return VERR_INVALID_PARAMETER; 765 768 } … … 780 783 */ 781 784 BY_HANDLE_FILE_INFORMATION Data; 782 if (!GetFileInformationByHandle((HANDLE) File, &Data))785 if (!GetFileInformationByHandle((HANDLE)RTFileToNative(hFile), &Data)) 783 786 { 784 787 DWORD dwErr = GetLastError(); … … 851 854 852 855 853 RTR3DECL(int) RTFileSetTimes(RTFILE File, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,856 RTR3DECL(int) RTFileSetTimes(RTFILE hFile, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime, 854 857 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime) 855 858 { … … 873 876 874 877 int rc = VINF_SUCCESS; 875 if (!SetFileTime((HANDLE) File, pCreationTimeFT, pLastAccessTimeFT, pLastWriteTimeFT))878 if (!SetFileTime((HANDLE)RTFileToNative(hFile), pCreationTimeFT, pLastAccessTimeFT, pLastWriteTimeFT)) 876 879 { 877 880 DWORD Err = GetLastError(); 878 881 rc = RTErrConvertFromWin32(Err); 879 882 Log(("RTFileSetTimes(%RTfile, %p, %p, %p, %p): SetFileTime failed with lasterr %d (%Rrc)\n", 880 File, pAccessTime, pModificationTime, pChangeTime, pBirthTime, Err, rc));883 hFile, pAccessTime, pModificationTime, pChangeTime, pBirthTime, Err, rc)); 881 884 } 882 885 return rc; … … 890 893 891 894 892 RTR3DECL(int) RTFileSetMode(RTFILE File, RTFMODE fMode)895 RTR3DECL(int) RTFileSetMode(RTFILE hFile, RTFMODE fMode) 893 896 { 894 897 /* … … 900 903 901 904 ULONG FileAttributes = (fMode & RTFS_DOS_MASK) >> RTFS_DOS_SHIFT; 902 int Err = rtFileNativeSetAttributes((HANDLE) File, FileAttributes);905 int Err = rtFileNativeSetAttributes((HANDLE)hFile, FileAttributes); 903 906 if (Err != ERROR_SUCCESS) 904 907 { 905 908 int rc = RTErrConvertFromWin32(Err); 906 909 Log(("RTFileSetMode(%RTfile, %RTfmode): rtFileNativeSetAttributes (0x%08X) failed with err %d (%Rrc)\n", 907 File, fMode, FileAttributes, Err, rc));910 hFile, fMode, FileAttributes, Err, rc)); 908 911 return rc; 909 912 } -
trunk/src/VBox/Runtime/r3/win/rtFileNativeSetAttributes-win.cpp
r28800 r37596 60 60 61 61 /** @todo resolve dynamically to avoid dragging in NtDll? */ 62 NTSTATUS Status = NtSetInformationFile( hFile,62 NTSTATUS Status = NtSetInformationFile(RTFileToNative(hFile), 63 63 &IoStatusBlock, 64 64 &Info,
Note:
See TracChangeset
for help on using the changeset viewer.