- Timestamp:
- Dec 20, 2023 5:10:09 PM (16 months ago)
- svn:sync-xref-src-repo-rev:
- 160819
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/RTFsMountpointsEnum-win.cpp
r102649 r102657 50 50 #include <iprt/win/windows.h> 51 51 52 53 /********************************************************************************************************************************* 54 * Structures and Typedefs * 55 *********************************************************************************************************************************/ 56 /* kernel32.dll: */ 57 typedef HANDLE (WINAPI *PFNFINDFIRSTVOLUMEW(LPWSTR, DWORD); 58 typedef HANDLE (WINAPI *PFNFINDNEXTVOLUMEW(HANDLE, LPWSTR, DWORD); 59 typedef HANDLE (WINAPI *PFNFINDVOLUMECLOSE(HANDLE); 60 typedef HANDLE (WINAPI *PFNGETVOLUMEPATHNAMESFORVOLUMENAMEW(LPCWSTR, LPWCH, DWORD, PDWORD); 61 typedef HANDLE (WINAPI *PFNFINDFIRSTVOLUMEMOUNTPOINTW(LPCWSTR, LPWSTR, DWORD); 62 typedef HANDLE (WINAPI *PFNFINDNEXTVOLUMEMOUNTPOINTW(HANDLE, LPWSTR, DWORD); 63 typedef HANDLE (WINAPI *PFNFINDVOLUMEMOUNTPOINTCLOSE(HANDLE); 64 65 66 /********************************************************************************************************************************* 67 * Global Variables * 68 *********************************************************************************************************************************/ 69 70 /* kernel32.dll: */ 71 static PFNFINDFIRSTVOLUMEW g_pfnFindFirstVolumeW = NULL; 72 static PFNFINDNEXTVOLUMEW g_pfnFindNextVolumeW = NULL; 73 static PFNFINDVOLUMECLOSE g_pfnFindVolumeClose = NULL; 74 static PFNGETVOLUMEPATHNAMESFORVOLUMENAMEW g_pfnGetVolumePathNamesForVolumeNameW = NULL; 75 static PFNFINDFIRSTVOLUMEMOUNTPOINTW g_pfnFindFirstVolumeMountPointW = NULL; 76 static PFNFINDNEXTVOLUMEMOUNTPOINTW g_pfnFindNextVolumeMountPointW = NULL; 77 static PFNFINDVOLUMEMOUNTPOINTCLOSE g_pfnFindVolumeMountPointClose = NULL; 78 79 /** Init once structure we need. */ 80 static 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 */ 90 static 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 } 52 114 53 115 /** … … 90 152 91 153 WCHAR wszVol[RTPATH_MAX]; 92 HANDLE hVol = FindFirstVolumeW(wszVol, RT_ELEMENTS(wszVol));154 HANDLE hVol = g_pfnFindFirstVolumeW(wszVol, RT_ELEMENTS(wszVol)); 93 155 if ( hVol 94 156 && hVol != INVALID_HANDLE_VALUE) … … 97 159 { 98 160 WCHAR wszMp[RTPATH_MAX]; 99 HANDLE hMp = FindFirstVolumeMountPointW(wszVol, wszMp, RT_ELEMENTS(wszMp));161 HANDLE hMp = g_pfnFindFirstVolumeMountPointW(wszVol, wszMp, RT_ELEMENTS(wszMp)); 100 162 if ( hMp 101 163 && hMp != INVALID_HANDLE_VALUE) … … 107 169 break; 108 170 } 109 while ( FindNextVolumeMountPointW(hMp, wszMp, RT_ELEMENTS(wszMp)));110 FindVolumeMountPointClose(hMp);171 while (g_pfnFindNextVolumeMountPointW(hMp, wszMp, RT_ELEMENTS(wszMp))); 172 g_pfnFindVolumeMountPointClose(hMp); 111 173 } 112 174 else if ( GetLastError() != ERROR_NO_MORE_FILES … … 118 180 { 119 181 DWORD cwch = 0; 120 if ( GetVolumePathNamesForVolumeNameW(wszVol, wszMp, RT_ELEMENTS(wszMp), &cwch))182 if (g_pfnGetVolumePathNamesForVolumeNameW(wszVol, wszMp, RT_ELEMENTS(wszMp), &cwch)) 121 183 { 122 184 size_t off = 0; … … 137 199 } 138 200 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); 141 203 } 142 204 else … … 184 246 RTR3DECL(int) RTFsMountpointsEnum(PFNRTFSMOUNTPOINTENUM pfnCallback, void *pvUser) 185 247 { 248 int rc = RTOnce(&g_rtFsWinResolveOnce, rtFsWinResolveOnce, NULL); 249 if (RT_FAILURE(rc)) 250 return rc; 251 186 252 return rtFsWinMountpointsEnumWorker(true /* fRemote */, pfnCallback, pvUser); 187 253 }
Note:
See TracChangeset
for help on using the changeset viewer.