VirtualBox

Changeset 74460 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Sep 25, 2018 3:42:33 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
125313
Message:

IPRT: Implemented long filename support for windows (except for LoadLibrary). bugref:9248

Location:
trunk/src/VBox/Runtime/r3/win
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/dir-win.cpp

    r69111 r74460  
    5858         */
    5959        PRTUTF16 pwszString;
    60         rc = RTStrToUtf16(pszPath, &pwszString);
     60        rc = RTPathWinFromUtf8(&pwszString, pszPath, 0 /*fFlags*/);
    6161        AssertRC(rc);
    6262        if (RT_SUCCESS(rc))
     
    8989            }
    9090
    91             RTUtf16Free(pwszString);
     91            RTPathWinFree(pwszString);
    9292        }
    9393    }
     
    109109     */
    110110    PRTUTF16 pwszString;
    111     int rc = RTStrToUtf16(pszPath, &pwszString);
     111    int rc = RTPathWinFromUtf8(&pwszString, pszPath, 0 /*fFlags*/);
    112112    AssertRC(rc);
    113113    if (RT_SUCCESS(rc))
     
    121121            rc = RTErrConvertFromWin32(GetLastError());
    122122
    123         RTUtf16Free(pwszString);
     123        RTPathWinFree(pwszString);
    124124    }
    125125
  • trunk/src/VBox/Runtime/r3/win/direnum-win.cpp

    r73097 r74460  
    8282     * Attempt opening the search.
    8383     */
    84     int rc = VINF_SUCCESS;
    8584    PRTUTF16 pwszName;
    86     rc = RTStrToUtf16(pszPathBuf, &pwszName);
     85    int rc = RTPathWinFromUtf8(pwszPathBuf, &pwszName, 0 /*fFlags*/);
    8786    if (RT_SUCCESS(rc))
    8887    {
     
    10099                rc = RTErrConvertFromWin32(GetLastError());
    101100        }
    102         RTUtf16Free(pwszName);
     101        RTPathWinFree(pwszName);
    103102    }
    104103
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r74368 r74460  
    289289    /*
    290290     * Open/Create the file.
    291      *
    292      * When opening files with paths longer than 260 chars, CreateFileW() will fail, unless
    293      * you explicitly specify a prefix (see [1], RTPATH_WIN_LONG_PATH_PREFIX).
    294      *
    295      * Note: Relative paths are not supported, so check for this.
    296      *
    297      * [1] https://docs.microsoft.com/en-gb/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
    298      */
    299     PRTUTF16 pwszFilename = NULL;
    300 #if 0 /** @todo r=bird: This stuff just isn't up to scratch. Sorry.  RTStrAPrintf2? WTF?!?  When using the long path prefix,
    301        * the path is just passed right thru to the NT API, so we need to fix unix slashes, resolve '.' and '..' components,
    302        * and probably also get rid of extra slashes.  Finally, the 260 limit (there is a \#define for it btw) actually
    303        * applies to the  converted filename (UTF-16), not the UTF-8 one, so this may break stuff (think asian languages)
    304        * that isn't over the 260 limit.  */
    305     if (g_enmWinVer >= kRTWinOSType_XP) /* Not sure since when the prefix is available, so play safe by default. */
    306     {
    307 #define RTPATH_WIN_LONG_PATH_PREFIX "\\\\?\\"
    308 
    309         if (   strlen(pszFilename) > 260
    310             && !RTPathStartsWith(pszFilename, RTPATH_WIN_LONG_PATH_PREFIX)
    311             && RTPathStartsWithRoot(pszFilename))
     291     */
     292    PRTUTF16 pwszFilename;
     293    rc = RTPathWinFromUtf8(&pwszFilename, pszFilename, 0 /*fFlags*/);
     294    if (RT_SUCCESS(rc))
     295    {
     296        HANDLE hFile = CreateFileW(pwszFilename,
     297                                   dwDesiredAccess,
     298                                   dwShareMode,
     299                                   pSecurityAttributes,
     300                                   dwCreationDisposition,
     301                                   dwFlagsAndAttributes,
     302                                   NULL);
     303        if (hFile != INVALID_HANDLE_VALUE)
    312304        {
    313             char *pszFilenameWithPrefix = RTStrAPrintf2("%s%s", RTPATH_WIN_LONG_PATH_PREFIX, pszFilename);
    314             if (pszFilenameWithPrefix)
    315             {
    316                 rc = RTStrToUtf16(pszFilenameWithPrefix, &pwszFilename);
    317                 RTStrFree(pszFilenameWithPrefix);
    318             }
    319             else
    320                 rc = VERR_NO_MEMORY;
     305            bool fCreated = dwCreationDisposition == CREATE_ALWAYS
     306                         || dwCreationDisposition == CREATE_NEW
     307                         || (dwCreationDisposition == OPEN_ALWAYS && GetLastError() == 0);
     308
     309            /*
     310             * Turn off indexing of directory through Windows Indexing Service.
     311             */
     312            if (    fCreated
     313                &&  (fOpen & RTFILE_O_NOT_CONTENT_INDEXED))
     314            {
     315                if (!SetFileAttributesW(pwszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
     316                    rc = RTErrConvertFromWin32(GetLastError());
     317            }
     318            /*
     319             * Do we need to truncate the file?
     320             */
     321            else if (    !fCreated
     322                     &&     (fOpen & (RTFILE_O_TRUNCATE | RTFILE_O_ACTION_MASK))
     323                         == (RTFILE_O_TRUNCATE | RTFILE_O_OPEN_CREATE))
     324            {
     325                if (!SetEndOfFile(hFile))
     326                    rc = RTErrConvertFromWin32(GetLastError());
     327            }
     328            if (RT_SUCCESS(rc))
     329            {
     330                *pFile = (RTFILE)hFile;
     331                Assert((HANDLE)*pFile == hFile);
     332                RTPathWinFree(pwszFilename);
     333                return VINF_SUCCESS;
     334            }
     335
     336            CloseHandle(hFile);
    321337        }
    322 #undef RTPATH_WIN_LONG_PATH_PREFIX
    323     }
    324 
    325     if (   RT_SUCCESS(rc)
    326         && !pwszFilename)
    327 #endif
    328         rc = RTStrToUtf16(pszFilename, &pwszFilename);
    329 
    330     if (RT_FAILURE(rc))
    331         return rc;
    332 
    333     HANDLE hFile = CreateFileW(pwszFilename,
    334                                dwDesiredAccess,
    335                                dwShareMode,
    336                                pSecurityAttributes,
    337                                dwCreationDisposition,
    338                                dwFlagsAndAttributes,
    339                                NULL);
    340     if (hFile != INVALID_HANDLE_VALUE)
    341     {
    342         bool fCreated = dwCreationDisposition == CREATE_ALWAYS
    343                      || dwCreationDisposition == CREATE_NEW
    344                      || (dwCreationDisposition == OPEN_ALWAYS && GetLastError() == 0);
    345 
    346         /*
    347          * Turn off indexing of directory through Windows Indexing Service.
    348          */
    349         if (    fCreated
    350             &&  (fOpen & RTFILE_O_NOT_CONTENT_INDEXED))
    351         {
    352             if (!SetFileAttributesW(pwszFilename, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
    353                 rc = RTErrConvertFromWin32(GetLastError());
    354         }
    355         /*
    356          * Do we need to truncate the file?
    357          */
    358         else if (    !fCreated
    359                  &&     (fOpen & (RTFILE_O_TRUNCATE | RTFILE_O_ACTION_MASK))
    360                      == (RTFILE_O_TRUNCATE | RTFILE_O_OPEN_CREATE))
    361         {
    362             if (!SetEndOfFile(hFile))
    363                 rc = RTErrConvertFromWin32(GetLastError());
    364         }
    365         if (RT_SUCCESS(rc))
    366         {
    367             *pFile = (RTFILE)hFile;
    368             Assert((HANDLE)*pFile == hFile);
    369             RTUtf16Free(pwszFilename);
    370             return VINF_SUCCESS;
    371         }
    372 
    373         CloseHandle(hFile);
    374     }
    375     else
    376         rc = RTErrConvertFromWin32(GetLastError());
    377     RTUtf16Free(pwszFilename);
     338        else
     339            rc = RTErrConvertFromWin32(GetLastError());
     340        RTPathWinFree(pwszFilename);
     341    }
    378342    return rc;
    379343}
     
    10491013{
    10501014    PRTUTF16 pwszFilename;
    1051     int rc = RTStrToUtf16(pszFilename, &pwszFilename);
     1015    int rc = RTPathWinFromUtf8(&pwszFilename, pszFilename, 0 /*fFlags*/);
    10521016    if (RT_SUCCESS(rc))
    10531017    {
    10541018        if (!DeleteFileW(pwszFilename))
    10551019            rc = RTErrConvertFromWin32(GetLastError());
    1056         RTUtf16Free(pwszFilename);
     1020        RTPathWinFree(pwszFilename);
    10571021    }
    10581022
  • trunk/src/VBox/Runtime/r3/win/fs-win.cpp

    r69111 r74460  
    281281    }
    282282
    283     RTUtf16Free(pwszFsRoot);
     283    rtFsFreeRoot(pwszFsRoot);
    284284    return rc;
    285285}
     
    333333    }
    334334
    335     RTUtf16Free(pwszFsRoot);
     335    rtFsFreeRoot(pwszFsRoot);
    336336    return rc;
    337337}
     
    379379     */
    380380    PRTUTF16 pwszFsPath;
    381     int rc = RTStrToUtf16(pszFsPath, &pwszFsPath);
     381    int rc = RTPathWinFromUtf8(&pwszFsPath, pszFsPath, 0 /*fFlags*/);
    382382    if (RT_SUCCESS(rc))
    383383    {
     
    422422        else
    423423            rc = RTErrConvertFromWin32(GetLastError());
    424         RTUtf16Free(pwszFsPath);
     424        RTPathWinFree(pwszFsPath);
    425425    }
    426426    return rc;
  • trunk/src/VBox/Runtime/r3/win/ldrNative-win.cpp

    r74458 r74460  
    6969     * Convert to UTF-16 and make sure it got a .DLL suffix.
    7070     */
     71    /** @todo Implement long path support for native DLL loading on windows. @bugref{9248} */
    7172    int rc;
    7273    RTUTF16 *pwszNative = NULL;
  • trunk/src/VBox/Runtime/r3/win/localipc-win.cpp

    r73097 r74460  
    366366 *
    367367 * @returns IPRT status code.
    368  * @param   pszName         The user supplied name.
     368 * @param   pszName         The user supplied name.  ASSUMES reasonable length
     369 *                          for now, so no long path prefixing needed.
    369370 * @param   pwszFullName    The output buffer.
    370371 * @param   cwcFullName     The output buffer size excluding the terminator.
  • trunk/src/VBox/Runtime/r3/win/path-win.cpp

    r69111 r74460  
    6363     */
    6464    PRTUTF16 pwszPath;
    65     int rc = RTStrToUtf16(pszPath, &pwszPath);
    66     if (!RT_SUCCESS(rc))
    67         return (rc);
    68 
    69     LPWSTR lpFile;
    70     WCHAR  wsz[RTPATH_MAX];
    71     rc = GetFullPathNameW((LPCWSTR)pwszPath, RT_ELEMENTS(wsz), &wsz[0], &lpFile);
    72     if (rc > 0 && rc < RT_ELEMENTS(wsz))
    73     {
    74         /* Check that it exists. (Use RTPathAbs() to just resolve the name.) */
    75         DWORD dwAttr = GetFileAttributesW(wsz);
    76         if (dwAttr != INVALID_FILE_ATTRIBUTES)
    77             rc = RTUtf16ToUtf8Ex((PRTUTF16)&wsz[0], RTSTR_MAX, &pszRealPath, cchRealPath, NULL);
     65    int rc = RTPathWinFromUtf8(&pwszPath, pszPath, 0 /*fFlags*/);
     66    if (RT_SUCCESS(rc))
     67    {
     68        LPWSTR lpFile;
     69        WCHAR  wsz[RTPATH_MAX];
     70        rc = GetFullPathNameW((LPCWSTR)pwszPath, RT_ELEMENTS(wsz), &wsz[0], &lpFile);
     71        if (rc > 0 && rc < RT_ELEMENTS(wsz))
     72        {
     73            /* Check that it exists. (Use RTPathAbs() to just resolve the name.) */
     74            DWORD dwAttr = GetFileAttributesW(wsz);
     75            if (dwAttr != INVALID_FILE_ATTRIBUTES)
     76                rc = RTUtf16ToUtf8Ex((PRTUTF16)&wsz[0], RTSTR_MAX, &pszRealPath, cchRealPath, NULL);
     77            else
     78                rc = RTErrConvertFromWin32(GetLastError());
     79        }
     80        else if (rc <= 0)
     81            rc = RTErrConvertFromWin32(GetLastError());
    7882        else
    79             rc = RTErrConvertFromWin32(GetLastError());
    80     }
    81     else if (rc <= 0)
    82         rc = RTErrConvertFromWin32(GetLastError());
    83     else
    84         rc = VERR_FILENAME_TOO_LONG;
    85 
    86     RTUtf16Free(pwszPath);
    87 
     83            rc = VERR_FILENAME_TOO_LONG;
     84
     85        RTPathWinFree(pwszPath);
     86    }
    8887    return rc;
    8988}
     
    442441     */
    443442    PRTUTF16 pwszPath;
    444     int rc = RTStrToUtf16(pszPath, &pwszPath);
     443    int rc = RTPathWinFromUtf8(&pwszPath, pszPath, 0 /*fFlags*/);
    445444    if (RT_SUCCESS(rc))
    446445    {
     
    523522        }
    524523
    525         RTUtf16Free(pwszPath);
     524        RTPathWinFree(pwszPath);
    526525    }
    527526
     
    553552     */
    554553    PRTUTF16 pwszSrc;
    555     int rc = RTStrToUtf16(pszSrc, &pwszSrc);
     554    int rc = RTPathWinFromUtf8(&pwszSrc, pszSrc, 0 /*fFlags*/);
    556555    if (RT_SUCCESS(rc))
    557556    {
    558557        PRTUTF16 pwszDst;
    559         rc = RTStrToUtf16(pszDst, &pwszDst);
     558        rc = RTPathWinFromUtf8(&pwszDst, pszDst, 0 /*fFlags*/);
    560559        if (RT_SUCCESS(rc))
    561560        {
     
    586585                }
    587586            }
    588             RTUtf16Free(pwszDst);
    589         }
    590         RTUtf16Free(pwszSrc);
     587            RTPathWinFree(pwszDst);
     588        }
     589        RTPathWinFree(pwszSrc);
    591590    }
    592591    return rc;
     
    642641    DWORD dwAttr;
    643642    PRTUTF16 pwszPath;
    644     int rc = RTStrToUtf16(pszPath, &pwszPath);
     643    int rc = RTPathWinFromUtf8(&pwszPath, pszPath, 0 /*fFlags*/);
    645644    if (RT_SUCCESS(rc))
    646645    {
    647646        dwAttr = GetFileAttributesW(pwszPath);
    648         RTUtf16Free(pwszPath);
     647        RTPathWinFree(pwszPath);
    649648    }
    650649    else
     
    702701     */
    703702    PRTUTF16 pwszPath;
    704     int rc = RTStrToUtf16(pszPath, &pwszPath);
     703    int rc = RTPathWinFromUtf8(&pwszPath, pszPath, 0 /*fFlags*/);
    705704    if (RT_SUCCESS(rc))
    706705    {
     
    716715            rc = RTErrConvertFromWin32(GetLastError());
    717716
    718         RTUtf16Free(pwszPath);
     717        RTPathWinFree(pwszPath);
    719718    }
    720719    return rc;
  • trunk/src/VBox/Runtime/r3/win/process-win.cpp

    r73097 r74460  
    21192119         * Replace the executable string.
    21202120         */
    2121         RTUtf16Free(*ppwszExec);
     2121        RTPathWinFree(*ppwszExec);
    21222122        *ppwszExec = NULL;
    2123         rc = RTStrToUtf16(szRealExec, ppwszExec);
     2123        rc = RTPathWinFromUtf8(ppwszExec, szRealExec, 0 /*fFlags*/);
    21242124    }
    21252125    else if (rc == VERR_END_OF_STRING)
     
    23652365    {
    23662366        PRTUTF16 pwszExec;
    2367         rc = RTStrToUtf16(pszExec, &pwszExec);
     2367        rc = RTPathWinFromUtf8(&pwszExec, pszExec, 0 /*fFlags*/);
    23682368        if (RT_SUCCESS(rc))
    23692369        {
     
    24492449                rc = VINF_SUCCESS;
    24502450            }
    2451             RTUtf16Free(pwszExec);
     2451            RTPathWinFree(pwszExec);
    24522452        }
    24532453        RTUtf16Free(pwszCmdLine);
  • trunk/src/VBox/Runtime/r3/win/symlink-win.cpp

    r69111 r74460  
    152152     */
    153153    PRTUTF16 pwszNativeSymlink;
    154     int rc = RTStrToUtf16(pszSymlink, &pwszNativeSymlink);
     154    int rc = RTPathWinFromUtf8(&pwszNativeSymlink, pszSymlink, 0 /*fFlags*/);
    155155    if (RT_SUCCESS(rc))
    156156    {
    157157        PRTUTF16 pwszNativeTarget;
    158         rc = RTStrToUtf16(pszTarget, &pwszNativeTarget);
     158        rc = RTPathWinFromUtf8(&pwszNativeTarget, pszTarget, 0 /*fFlags*/);
    159159        if (RT_SUCCESS(rc))
    160160        {
     
    219219                rc = RTErrConvertFromWin32(GetLastError());
    220220
    221             RTUtf16Free(pwszNativeTarget);
     221            RTPathWinFree(pwszNativeTarget);
    222222        }
    223         RTUtf16Free(pwszNativeSymlink);
     223        RTPathWinFree(pwszNativeSymlink);
    224224    }
    225225
     
    237237     */
    238238    PRTUTF16 pwszNativeSymlink;
    239     int rc = RTStrToUtf16(pszSymlink, &pwszNativeSymlink);
     239    int rc = RTPathWinFromUtf8(&pwszNativeSymlink, pszSymlink, 0 /*fFlags*/);
    240240    if (RT_SUCCESS(rc))
    241241    {
     
    266266        else
    267267            rc = RTErrConvertFromWin32(GetLastError());
    268         RTUtf16Free(pwszNativeSymlink);
     268        RTPathWinFree(pwszNativeSymlink);
    269269    }
    270270
     
    294294    AssertPtr(ppszTarget);
    295295    PRTUTF16 pwszNativeSymlink;
    296     int rc = RTStrToUtf16(pszSymlink, &pwszNativeSymlink);
     296    int rc = RTPathWinFromUtf8(&pwszNativeSymlink, pszSymlink, 0 /*fFlags*/);
    297297    if (RT_SUCCESS(rc))
    298298    {
     
    345345        else
    346346            rc = RTErrConvertFromWin32(GetLastError());
    347         RTUtf16Free(pwszNativeSymlink);
     347        RTPathWinFree(pwszNativeSymlink);
    348348    }
    349349
Note: See TracChangeset for help on using the changeset viewer.

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