VirtualBox

Changeset 102657 in vbox for trunk/src


Ignore:
Timestamp:
Dec 20, 2023 5:10:09 PM (16 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160819
Message:

IPRT/RTFsMountpointsEnum: Dynamically resolve some Windows volume APIs which are not in NT 3.51. ​bugref:10415

File:
1 edited

Legend:

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

    r102649 r102657  
    5050#include <iprt/win/windows.h>
    5151
     52
     53/*********************************************************************************************************************************
     54*   Structures and Typedefs                                                                                                      *
     55*********************************************************************************************************************************/
     56/* kernel32.dll: */
     57typedef HANDLE (WINAPI *PFNFINDFIRSTVOLUMEW(LPWSTR, DWORD);
     58typedef HANDLE (WINAPI *PFNFINDNEXTVOLUMEW(HANDLE, LPWSTR, DWORD);
     59typedef HANDLE (WINAPI *PFNFINDVOLUMECLOSE(HANDLE);
     60typedef HANDLE (WINAPI *PFNGETVOLUMEPATHNAMESFORVOLUMENAMEW(LPCWSTR, LPWCH, DWORD, PDWORD);
     61typedef HANDLE (WINAPI *PFNFINDFIRSTVOLUMEMOUNTPOINTW(LPCWSTR, LPWSTR, DWORD);
     62typedef HANDLE (WINAPI *PFNFINDNEXTVOLUMEMOUNTPOINTW(HANDLE, LPWSTR, DWORD);
     63typedef HANDLE (WINAPI *PFNFINDVOLUMEMOUNTPOINTCLOSE(HANDLE);
     64
     65
     66/*********************************************************************************************************************************
     67*   Global Variables                                                                                                             *
     68*********************************************************************************************************************************/
     69
     70/* kernel32.dll: */
     71static PFNFINDFIRSTVOLUMEW                 g_pfnFindFirstVolumeW                 = NULL;
     72static PFNFINDNEXTVOLUMEW                  g_pfnFindNextVolumeW                  = NULL;
     73static PFNFINDVOLUMECLOSE                  g_pfnFindVolumeClose                  = NULL;
     74static PFNGETVOLUMEPATHNAMESFORVOLUMENAMEW g_pfnGetVolumePathNamesForVolumeNameW = NULL;
     75static PFNFINDFIRSTVOLUMEMOUNTPOINTW       g_pfnFindFirstVolumeMountPointW       = NULL;
     76static PFNFINDNEXTVOLUMEMOUNTPOINTW        g_pfnFindNextVolumeMountPointW        = NULL;
     77static PFNFINDVOLUMEMOUNTPOINTCLOSE        g_pfnFindVolumeMountPointClose        = NULL;
     78
     79/** Init once structure we need. */
     80static RTONCE g_rtFsWinResolveOnce = RTONCE_INITIALIZER;
     81
     82
     83/**
     84 * Initialize the import APIs.
     85 *
     86 * @returns IPRT status code.
     87 * @retval  VERR_NOT_SUPPORTED if not supported.
     88 * @param   pvUser              Ignored.
     89 */
     90static DECLCALLBACK(int) rtFsWinResolveOnce(void *pvUser)
     91{
     92    /*
     93     * kernel32.dll volume APIs introduced after NT4.
     94     */
     95    g_pfnFindFirstVolumeW                 = (PFNFINDFIRSTVOLUMEW                )GetProcAddress(g_hModKernel32, "FindFirstVolumeW");
     96    g_pfnFindNextVolumeW                  = (PFNFINDNEXTVOLUMEW                 )GetProcAddress(g_hModKernel32, "FindNextVolumeW");
     97    g_pfnFindVolumeClose                  = (PFNFINDVOLUMECLOSE                 )GetProcAddress(g_hModKernel32, "FindVolumeClose");
     98    g_pfnGetVolumePathNamesForVolumeNameW = (PFNGETVOLUMEPATHNAMESFORVOLUMENAMEW)GetProcAddress(g_hModKernel32, "GetVolumePathNamesForVolumeNameW");
     99    g_pfnFindFirstVolumeMountPointW       = (PFNFINDFIRSTVOLUMEMOUNTPOINTW      )GetProcAddress(g_hModKernel32, "FindFirstVolumeMountPointW");
     100    g_pfnFindNextVolumeMountPointW        = (PFNFINDNEXTVOLUMEMOUNTPOINTW       )GetProcAddress(g_hModKernel32, "FindNextVolumeMountPointW");
     101    g_pfnFindVolumeMountPointClose        = (PFNFINDVOLUMEMOUNTPOINTCLOSE       )GetProcAddress(g_hModKernel32, "FindVolumeMountPointClose");
     102
     103    if (   !g_pfnFindFirstVolumeW
     104        || !g_pfnFindNextVolumeW
     105        || !g_pfnFindVolumeClose
     106        || !g_pfnGetVolumePathNamesForVolumeNameW
     107        || !g_pfnFindFirstVolumeMountPointW
     108        || !g_pfnFindNextVolumeMountPointW
     109        || !g_pfnFindVolumeMountPointClose)
     110        return VERR_NOT_SUPPORTED;
     111
     112    return VINF_SUCCESS;
     113}
    52114
    53115/**
     
    90152
    91153    WCHAR wszVol[RTPATH_MAX];
    92     HANDLE hVol = FindFirstVolumeW(wszVol, RT_ELEMENTS(wszVol));
     154    HANDLE hVol = g_pfnFindFirstVolumeW(wszVol, RT_ELEMENTS(wszVol));
    93155    if (   hVol
    94156        && hVol != INVALID_HANDLE_VALUE)
     
    97159        {
    98160            WCHAR wszMp[RTPATH_MAX];
    99             HANDLE hMp = FindFirstVolumeMountPointW(wszVol, wszMp, RT_ELEMENTS(wszMp));
     161            HANDLE hMp = g_pfnFindFirstVolumeMountPointW(wszVol, wszMp, RT_ELEMENTS(wszMp));
    100162            if (   hMp
    101163                && hMp != INVALID_HANDLE_VALUE)
     
    107169                        break;
    108170                }
    109                 while (FindNextVolumeMountPointW(hMp, wszMp, RT_ELEMENTS(wszMp)));
    110                 FindVolumeMountPointClose(hMp);
     171                while (g_pfnFindNextVolumeMountPointW(hMp, wszMp, RT_ELEMENTS(wszMp)));
     172                g_pfnFindVolumeMountPointClose(hMp);
    111173            }
    112174            else if (   GetLastError() != ERROR_NO_MORE_FILES
     
    118180            {
    119181                DWORD cwch = 0;
    120                 if (GetVolumePathNamesForVolumeNameW(wszVol, wszMp, RT_ELEMENTS(wszMp), &cwch))
     182                if (g_pfnGetVolumePathNamesForVolumeNameW(wszVol, wszMp, RT_ELEMENTS(wszMp), &cwch))
    121183                {
    122184                    size_t off = 0;
     
    137199            }
    138200
    139         } while (RT_SUCCESS(rc) && FindNextVolumeW(hVol, wszVol, RT_ELEMENTS(wszVol)));
    140         FindVolumeClose(hVol);
     201        } while (RT_SUCCESS(rc) && g_pfnFindNextVolumeW(hVol, wszVol, RT_ELEMENTS(wszVol)));
     202        g_pfnFindVolumeClose(hVol);
    141203    }
    142204    else
     
    184246RTR3DECL(int) RTFsMountpointsEnum(PFNRTFSMOUNTPOINTENUM pfnCallback, void *pvUser)
    185247{
     248    int rc = RTOnce(&g_rtFsWinResolveOnce, rtFsWinResolveOnce, NULL);
     249    if (RT_FAILURE(rc))
     250        return rc;
     251
    186252    return rtFsWinMountpointsEnumWorker(true /* fRemote */, pfnCallback, pvUser);
    187253}
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