VirtualBox

Changeset 37596 in vbox for trunk/src/VBox/Runtime/r3/win


Ignore:
Timestamp:
Jun 22, 2011 7:30:06 PM (13 years ago)
Author:
vboxsync
Message:

*: RTFILE becomes a pointer, RTFileOpen++ expands it's flags paramter from uint32_t to uint64_t.

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  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    189189
    190190    pReqInt->enmTransferDirection  = enmTransferDirection;
    191     pReqInt->hFile                 = (HANDLE)hFile;
     191    pReqInt->hFile                 = RTFileToNative(hFile);
    192192    pReqInt->Overlapped.Offset     = (DWORD)(off & 0xffffffff);
    193193    pReqInt->Overlapped.OffsetHigh = (DWORD)(off >> 32);
     
    318318    RTFILEAIOCTX_VALID_RETURN(pCtxInt);
    319319
    320     HANDLE hTemp = CreateIoCompletionPort((HANDLE)hFile, pCtxInt->hIoCompletionPort, 0, 1);
     320    HANDLE hTemp = CreateIoCompletionPort(RTFileToNative(hFile), pCtxInt->hIoCompletionPort, 0, 1);
    321321    if (hTemp != pCtxInt->hIoCompletionPort)
    322322        rc = RTErrConvertFromWin32(GetLastError());
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r36601 r37596  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    5555 *
    5656 * @returns Success indicator. Extended error information obtainable using GetLastError().
    57  * @param   File        Filehandle.
     57 * @param   hFile       Filehandle.
    5858 * @param   offSeek     Offset to seek.
    5959 * @param   poffNew     Where to store the new file offset. NULL allowed.
    6060 * @param   uMethod     Seek method. (The windows one!)
    6161 */
    62 DECLINLINE(bool) MySetFilePointer(RTFILE File, uint64_t offSeek, uint64_t *poffNew, unsigned uMethod)
     62DECLINLINE(bool) MySetFilePointer(RTFILE hFile, uint64_t offSeek, uint64_t *poffNew, unsigned uMethod)
    6363{
    6464    bool            fRc;
     
    6969    if (off.LowPart != INVALID_SET_FILE_POINTER)
    7070    {
    71         off.LowPart = SetFilePointer((HANDLE)File, off.LowPart, &off.HighPart, uMethod);
     71        off.LowPart = SetFilePointer((HANDLE)RTFileToNative(hFile), off.LowPart, &off.HighPart, uMethod);
    7272        fRc = off.LowPart != INVALID_SET_FILE_POINTER;
    7373    }
     
    7575    {
    7676        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);
    7878        fRc = GetLastError() == NO_ERROR;
    7979    }
    8080#else
    81     fRc = SetFilePointerEx((HANDLE)File, off, &off, uMethod);
     81    fRc = SetFilePointerEx((HANDLE)RTFileToNative(hFile), off, &off, uMethod);
    8282#endif
    8383    if (fRc && poffNew)
     
    9292 *
    9393 * @returns true for file size limit exceeded.
    94  * @param   File        Filehandle.
     94 * @param   hFile       Filehandle.
    9595 * @param   offSeek     Offset to seek.
    9696 * @param   uMethod     The seek method.
    9797 */
    98 DECLINLINE(bool) IsBeyondLimit(RTFILE File, uint64_t offSeek, unsigned uMethod)
     98DECLINLINE(bool) IsBeyondLimit(RTFILE hFile, uint64_t offSeek, unsigned uMethod)
    9999{
    100100    bool fIsBeyondLimit = false;
     
    108108 * file seeking, only at the time of writing (and some other odd ones we cannot make use of). */
    109109    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))
    113113            fIsBeyondLimit = GetLastError() == ERROR_SEEK;
    114114        else /* Restore file pointer on success. */
    115             MySetFilePointer(File, offCurrent, NULL, FILE_BEGIN);
     115            MySetFilePointer(hFile, offCurrent, NULL, FILE_BEGIN);
    116116    }
    117117
     
    135135
    136136
    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, uint32_t fOpen)
     137RTR3DECL(RTHCINTPTR) RTFileToNative(RTFILE hFile)
     138{
     139    AssertReturn(hFile != NIL_RTFILE, (RTHCINTPTR)INVALID_HANDLE_VALUE);
     140    return (RTHCINTPTR)hFile;
     141}
     142
     143
     144RTR3DECL(int) RTFileOpen(PRTFILE pFile, const char *pszFilename, uint64_t fOpen)
    145145{
    146146    /*
     
    186186            break;
    187187        default:
    188             AssertMsgFailed(("Impossible fOpen=%#x\n", fOpen));
     188            AssertMsgFailed(("Impossible fOpen=%#llx\n", fOpen));
    189189            return VERR_INVALID_PARAMETER;
    190190    }
     
    207207            break;
    208208        default:
    209             AssertMsgFailed(("Impossible fOpen=%#x\n", fOpen));
     209            AssertMsgFailed(("Impossible fOpen=%#llx\n", fOpen));
    210210            return VERR_INVALID_PARAMETER;
    211211    }
     
    228228                case RTFILE_O_READWRITE:     dwDesiredAccess |= FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE; break;
    229229                default:
    230                     AssertMsgFailed(("Impossible fOpen=%#x\n", fOpen));
     230                    AssertMsgFailed(("Impossible fOpen=%#llx\n", fOpen));
    231231                    return VERR_INVALID_PARAMETER;
    232232            }
     
    246246        case RTFILE_O_DENY_NOT_DELETE | RTFILE_O_DENY_READWRITE:dwShareMode = FILE_SHARE_DELETE; break;
    247247        default:
    248             AssertMsgFailed(("Impossible fOpen=%#x\n", fOpen));
     248            AssertMsgFailed(("Impossible fOpen=%#llx\n", fOpen));
    249249            return VERR_INVALID_PARAMETER;
    250250    }
     
    329329
    330330
    331 RTR3DECL(int)  RTFileOpenBitBucket(PRTFILE phFile, uint32_t fAccess)
     331RTR3DECL(int)  RTFileOpenBitBucket(PRTFILE phFile, uint64_t fAccess)
    332332{
    333333    AssertReturn(   fAccess == RTFILE_O_READ
     
    339339
    340340
    341 RTR3DECL(int)  RTFileClose(RTFILE File)
    342 {
    343     if (File == NIL_RTFILE)
    344         return VINF_SUCCESS;
    345     if (CloseHandle((HANDLE)File))
     341RTR3DECL(int)  RTFileClose(RTFILE hFile)
     342{
     343    if (hFile == NIL_RTFILE)
     344        return VINF_SUCCESS;
     345    if (CloseHandle((HANDLE)RTFileToNative(hFile)))
    346346        return VINF_SUCCESS;
    347347    return RTErrConvertFromWin32(GetLastError());
     
    372372
    373373
    374 RTR3DECL(int)  RTFileSeek(RTFILE File, int64_t offSeek, unsigned uMethod, uint64_t *poffActual)
     374RTR3DECL(int)  RTFileSeek(RTFILE hFile, int64_t offSeek, unsigned uMethod, uint64_t *poffActual)
    375375{
    376376    static ULONG aulSeekRecode[] =
     
    393393     * Execute the seek.
    394394     */
    395     if (MySetFilePointer(File, offSeek, poffActual, aulSeekRecode[uMethod]))
     395    if (MySetFilePointer(hFile, offSeek, poffActual, aulSeekRecode[uMethod]))
    396396        return VINF_SUCCESS;
    397397    return RTErrConvertFromWin32(GetLastError());
     
    399399
    400400
    401 RTR3DECL(int)  RTFileRead(RTFILE File, void *pvBuf, size_t cbToRead, size_t *pcbRead)
     401RTR3DECL(int)  RTFileRead(RTFILE hFile, void *pvBuf, size_t cbToRead, size_t *pcbRead)
    402402{
    403403    if (cbToRead <= 0)
     
    407407
    408408    ULONG cbRead = 0;
    409     if (ReadFile((HANDLE)File, pvBuf, cbToReadAdj, &cbRead, NULL))
     409    if (ReadFile((HANDLE)RTFileToNative(hFile), pvBuf, cbToReadAdj, &cbRead, NULL))
    410410    {
    411411        if (pcbRead)
     
    418418            {
    419419                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))
    421421                    return RTErrConvertFromWin32(GetLastError());
    422422                if (cbReadPart == 0)
     
    446446            ULONG cbToRead   = RT_MIN(cbChunk, cbToReadAdj - cbRead);
    447447            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))
    449449            {
    450450                /* If we failed because the buffer is too big, shrink it and
     
    478478
    479479
    480 RTR3DECL(int)  RTFileWrite(RTFILE File, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)
     480RTR3DECL(int)  RTFileWrite(RTFILE hFile, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)
    481481{
    482482    if (cbToWrite <= 0)
     
    486486
    487487    ULONG cbWritten = 0;
    488     if (WriteFile((HANDLE)File, pvBuf, cbToWriteAdj, &cbWritten, NULL))
     488    if (WriteFile((HANDLE)RTFileToNative(hFile), pvBuf, cbToWriteAdj, &cbWritten, NULL))
    489489    {
    490490        if (pcbWritten)
     
    497497            {
    498498                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))
    500501                {
    501502                    int rc = RTErrConvertFromWin32(GetLastError());
    502503                    if (   rc == VERR_DISK_FULL
    503                         && IsBeyondLimit(File, cbToWriteAdj - cbWritten, FILE_CURRENT)
     504                        && IsBeyondLimit(RTFileToNative(hFile), cbToWriteAdj - cbWritten, FILE_CURRENT)
    504505                       )
    505506                        rc = VERR_FILE_TOO_BIG;
     
    532533            ULONG cbToWrite     = RT_MIN(cbChunk, cbToWriteAdj - cbWritten);
    533534            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))
    535536            {
    536537                /* If we failed because the buffer is too big, shrink it and
     
    545546                int rc = RTErrConvertFromWin32(dwErr);
    546547                if (   rc == VERR_DISK_FULL
    547                     && IsBeyondLimit(File, cbToWriteAdj - cbWritten, FILE_CURRENT))
     548                    && IsBeyondLimit(hFile, cbToWriteAdj - cbWritten, FILE_CURRENT))
    548549                    rc = VERR_FILE_TOO_BIG;
    549550                return rc;
     
    566567    int rc = RTErrConvertFromWin32(dwErr);
    567568    if (   rc == VERR_DISK_FULL
    568         && IsBeyondLimit(File, cbToWriteAdj - cbWritten, FILE_CURRENT))
     569        && IsBeyondLimit(hFile, cbToWriteAdj - cbWritten, FILE_CURRENT))
    569570        rc = VERR_FILE_TOO_BIG;
    570571    return rc;
     
    572573
    573574
    574 RTR3DECL(int)  RTFileFlush(RTFILE File)
    575 {
    576     if (!FlushFileBuffers((HANDLE)File))
     575RTR3DECL(int)  RTFileFlush(RTFILE hFile)
     576{
     577    if (!FlushFileBuffers((HANDLE)RTFileToNative(hFile)))
    577578    {
    578579        int rc = GetLastError();
     
    584585
    585586
    586 RTR3DECL(int)  RTFileSetSize(RTFILE File, uint64_t cbSize)
     587RTR3DECL(int)  RTFileSetSize(RTFILE hFile, uint64_t cbSize)
    587588{
    588589    /*
     
    591592    int         rc;
    592593    uint64_t    offCurrent;
    593     if (MySetFilePointer(File, 0, &offCurrent, FILE_CURRENT))
     594    if (MySetFilePointer(hFile, 0, &offCurrent, FILE_CURRENT))
    594595    {
    595596        /*
    596597         * Set new file pointer.
    597598         */
    598         if (MySetFilePointer(File, cbSize, NULL, FILE_BEGIN))
     599        if (MySetFilePointer(hFile, cbSize, NULL, FILE_BEGIN))
    599600        {
    600601            /* set file pointer */
    601             if (SetEndOfFile((HANDLE)File))
     602            if (SetEndOfFile((HANDLE)RTFileToNative(hFile)))
    602603            {
    603604                /*
     
    605606                 * If the old pointer was beyond the new file end, ignore failure.
    606607                 */
    607                 if (    MySetFilePointer(File, offCurrent, NULL, FILE_BEGIN)
     608                if (    MySetFilePointer(hFile, offCurrent, NULL, FILE_BEGIN)
    608609                    ||  offCurrent > cbSize)
    609610                    return VINF_SUCCESS;
     
    614615             */
    615616            rc = GetLastError();
    616             MySetFilePointer(File, offCurrent, NULL, FILE_BEGIN);
     617            MySetFilePointer(hFile, offCurrent, NULL, FILE_BEGIN);
    617618        }
    618619        else
     
    626627
    627628
    628 RTR3DECL(int)  RTFileGetSize(RTFILE File, uint64_t *pcbSize)
     629RTR3DECL(int)  RTFileGetSize(RTFILE hFile, uint64_t *pcbSize)
    629630{
    630631    ULARGE_INTEGER  Size;
    631     Size.LowPart = GetFileSize((HANDLE)File, &Size.HighPart);
     632    Size.LowPart = GetFileSize((HANDLE)RTFileToNative(hFile), &Size.HighPart);
    632633    if (Size.LowPart != INVALID_FILE_SIZE)
    633634    {
     
    641642
    642643
    643 RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE File, PRTFOFF pcbMax)
     644RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE hFile, PRTFOFF pcbMax)
    644645{
    645646    /** @todo r=bird:
     
    653654
    654655
    655 RTR3DECL(bool) RTFileIsValid(RTFILE File)
    656 {
    657     if (File != NIL_RTFILE)
    658     {
    659         DWORD dwType = GetFileType((HANDLE)File);
     656RTR3DECL(bool) RTFileIsValid(RTFILE hFile)
     657{
     658    if (hFile != NIL_RTFILE)
     659    {
     660        DWORD dwType = GetFileType((HANDLE)RTFileToNative(hFile));
    660661        switch (dwType)
    661662        {
     
    679680#define HIGH_DWORD(u64) (((DWORD *)&u64)[1])
    680681
    681 RTR3DECL(int)  RTFileLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock)
     682RTR3DECL(int)  RTFileLock(RTFILE hFile, unsigned fLock, int64_t offLock, uint64_t cbLock)
    682683{
    683684    Assert(offLock >= 0);
     
    704705
    705706    /* 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))
    707708        return VINF_SUCCESS;
    708709
     
    711712
    712713
    713 RTR3DECL(int)  RTFileChangeLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock)
     714RTR3DECL(int)  RTFileChangeLock(RTFILE hFile, unsigned fLock, int64_t offLock, uint64_t cbLock)
    714715{
    715716    Assert(offLock >= 0);
     
    723724
    724725    /* Remove old lock. */
    725     int rc = RTFileUnlock(File, offLock, cbLock);
     726    int rc = RTFileUnlock(hFile, offLock, cbLock);
    726727    if (RT_FAILURE(rc))
    727728        return rc;
    728729
    729730    /* Set new lock. */
    730     rc = RTFileLock(File, fLock, offLock, cbLock);
     731    rc = RTFileLock(hFile, fLock, offLock, cbLock);
    731732    if (RT_SUCCESS(rc))
    732733        return rc;
     
    734735    /* Try to restore old lock. */
    735736    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);
    737738    if (RT_SUCCESS(rc))
    738739        return VERR_FILE_LOCK_VIOLATION;
     
    742743
    743744
    744 RTR3DECL(int)  RTFileUnlock(RTFILE File, int64_t offLock, uint64_t cbLock)
     745RTR3DECL(int)  RTFileUnlock(RTFILE hFile, int64_t offLock, uint64_t cbLock)
    745746{
    746747    Assert(offLock >= 0);
    747748
    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)))
    749752        return VINF_SUCCESS;
    750753
     
    754757
    755758
    756 RTR3DECL(int) RTFileQueryInfo(RTFILE File, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)
     759RTR3DECL(int) RTFileQueryInfo(RTFILE hFile, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)
    757760{
    758761    /*
    759762     * Validate input.
    760763     */
    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));
    764767        return VERR_INVALID_PARAMETER;
    765768    }
     
    780783     */
    781784    BY_HANDLE_FILE_INFORMATION Data;
    782     if (!GetFileInformationByHandle((HANDLE)File, &Data))
     785    if (!GetFileInformationByHandle((HANDLE)RTFileToNative(hFile), &Data))
    783786    {
    784787        DWORD dwErr = GetLastError();
     
    851854
    852855
    853 RTR3DECL(int) RTFileSetTimes(RTFILE File, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
     856RTR3DECL(int) RTFileSetTimes(RTFILE hFile, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
    854857                             PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
    855858{
     
    873876
    874877    int rc = VINF_SUCCESS;
    875     if (!SetFileTime((HANDLE)File, pCreationTimeFT, pLastAccessTimeFT, pLastWriteTimeFT))
     878    if (!SetFileTime((HANDLE)RTFileToNative(hFile), pCreationTimeFT, pLastAccessTimeFT, pLastWriteTimeFT))
    876879    {
    877880        DWORD Err = GetLastError();
    878881        rc = RTErrConvertFromWin32(Err);
    879882        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));
    881884    }
    882885    return rc;
     
    890893
    891894
    892 RTR3DECL(int) RTFileSetMode(RTFILE File, RTFMODE fMode)
     895RTR3DECL(int) RTFileSetMode(RTFILE hFile, RTFMODE fMode)
    893896{
    894897    /*
     
    900903
    901904    ULONG FileAttributes = (fMode & RTFS_DOS_MASK) >> RTFS_DOS_SHIFT;
    902     int Err = rtFileNativeSetAttributes((HANDLE)File, FileAttributes);
     905    int Err = rtFileNativeSetAttributes((HANDLE)hFile, FileAttributes);
    903906    if (Err != ERROR_SUCCESS)
    904907    {
    905908        int rc = RTErrConvertFromWin32(Err);
    906909        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));
    908911        return rc;
    909912    }
  • trunk/src/VBox/Runtime/r3/win/rtFileNativeSetAttributes-win.cpp

    r28800 r37596  
    6060
    6161    /** @todo resolve dynamically to avoid dragging in NtDll? */
    62     NTSTATUS Status = NtSetInformationFile(hFile,
     62    NTSTATUS Status = NtSetInformationFile(RTFileToNative(hFile),
    6363                                           &IoStatusBlock,
    6464                                           &Info,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette