mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 19:08:26 -06:00
Windows: when mounting system favorites using VolumeID feature, query all disks each time instead of caching previous call results. This is not efficient but it should fix rare cases where issues happen.
This commit is contained in:
@@ -7659,7 +7659,7 @@ static BOOL PerformMountIoctl (MOUNT_STRUCT* pmount, LPDWORD pdwResult, BOOL use
|
|||||||
{
|
{
|
||||||
if (useVolumeID)
|
if (useVolumeID)
|
||||||
{
|
{
|
||||||
wstring devicePath = FindDeviceByVolumeID (volumeID);
|
wstring devicePath = FindDeviceByVolumeID (volumeID, FALSE);
|
||||||
if (devicePath == L"")
|
if (devicePath == L"")
|
||||||
{
|
{
|
||||||
if (pdwResult)
|
if (pdwResult)
|
||||||
@@ -11882,11 +11882,8 @@ void AddDeviceToList (std::vector<HostDevice>& devices, int devNumber, int partN
|
|||||||
devices.push_back (device);
|
devices.push_back (device);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector <HostDevice> GetHostRawDeviceList (bool bFromService)
|
std::vector <HostDevice> GetHostRawDeviceList ()
|
||||||
{
|
{
|
||||||
if (bFromService)
|
|
||||||
return GetAvailableHostDevices (true, false, true, true);
|
|
||||||
|
|
||||||
std::vector <HostDevice> list;
|
std::vector <HostDevice> list;
|
||||||
HDEVINFO diskClassDevices;
|
HDEVINFO diskClassDevices;
|
||||||
GUID diskClassDeviceInterfaceGuid = GUID_DEVINTERFACE_DISK;
|
GUID diskClassDeviceInterfaceGuid = GUID_DEVINTERFACE_DISK;
|
||||||
@@ -11999,7 +11996,7 @@ bool CompareDeviceList (const std::vector<HostDevice>& list1, const std::vector<
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateMountableHostDeviceList (bool bFromService)
|
void UpdateMountableHostDeviceList ()
|
||||||
{
|
{
|
||||||
ByteArray buffer(4096);
|
ByteArray buffer(4096);
|
||||||
DWORD bytesReturned;
|
DWORD bytesReturned;
|
||||||
@@ -12008,7 +12005,7 @@ void UpdateMountableHostDeviceList (bool bFromService)
|
|||||||
EnterCriticalSection (&csMountableDevices);
|
EnterCriticalSection (&csMountableDevices);
|
||||||
finally_do ({ LeaveCriticalSection (&csMountableDevices); });
|
finally_do ({ LeaveCriticalSection (&csMountableDevices); });
|
||||||
|
|
||||||
std::vector<HostDevice> newList = GetHostRawDeviceList (bFromService);
|
std::vector<HostDevice> newList = GetHostRawDeviceList ();
|
||||||
std::map<DWORD, bool> existingDevicesMap;
|
std::map<DWORD, bool> existingDevicesMap;
|
||||||
|
|
||||||
if (CompareDeviceList (newList, rawHostDeviceList))
|
if (CompareDeviceList (newList, rawHostDeviceList))
|
||||||
@@ -12051,21 +12048,6 @@ void UpdateMountableHostDeviceList (bool bFromService)
|
|||||||
if (existingDevicesMap[It->SystemNumber])
|
if (existingDevicesMap[It->SystemNumber])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (bFromService)
|
|
||||||
{
|
|
||||||
if (It->Partitions.empty())
|
|
||||||
mountableDevices.push_back (*It);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (std::vector<HostDevice>::iterator partIt = It->Partitions.begin(); partIt != It->Partitions.end(); partIt++)
|
|
||||||
{
|
|
||||||
if (!partIt->ContainsSystem && !partIt->HasUnencryptedFilesystem)
|
|
||||||
mountableDevices.push_back (*partIt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HANDLE disk = CreateFile( It->Path.c_str(),
|
HANDLE disk = CreateFile( It->Path.c_str(),
|
||||||
0,
|
0,
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
@@ -12159,12 +12141,11 @@ void UpdateMountableHostDeviceList (bool bFromService)
|
|||||||
CloseHandle (disk);
|
CloseHandle (disk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
rawHostDeviceList = newList;
|
rawHostDeviceList = newList;
|
||||||
|
|
||||||
// Starting from Vista, Windows does not create partition links for dynamic volumes so it is necessary to scan \\Device\\HarddiskVolumeX devices
|
// Starting from Vista, Windows does not create partition links for dynamic volumes so it is necessary to scan \\Device\\HarddiskVolumeX devices
|
||||||
if (!bFromService && dynamicVolumesPresent && (CurrentOSMajor >= 6))
|
if (dynamicVolumesPresent && (CurrentOSMajor >= 6))
|
||||||
{
|
{
|
||||||
for (int devNumber = 0; devNumber < 256; devNumber++)
|
for (int devNumber = 0; devNumber < 256; devNumber++)
|
||||||
{
|
{
|
||||||
@@ -12190,10 +12171,8 @@ void UpdateMountableHostDeviceList (bool bFromService)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE])
|
wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE], BOOL bFromService)
|
||||||
{
|
{
|
||||||
static std::vector<HostDevice> volumeIdCandidates;
|
|
||||||
|
|
||||||
/* if it is already mounted, get the real path name used for mounting */
|
/* if it is already mounted, get the real path name used for mounting */
|
||||||
MOUNT_LIST_STRUCT mlist;
|
MOUNT_LIST_STRUCT mlist;
|
||||||
DWORD dwResult;
|
DWORD dwResult;
|
||||||
@@ -12224,6 +12203,36 @@ wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE])
|
|||||||
|
|
||||||
/* not mounted. Look for it in the local drives*/
|
/* not mounted. Look for it in the local drives*/
|
||||||
|
|
||||||
|
if (bFromService)
|
||||||
|
{
|
||||||
|
for (int devNumber = 0; devNumber < MAX_HOST_DRIVE_NUMBER; devNumber++)
|
||||||
|
{
|
||||||
|
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
|
||||||
|
{
|
||||||
|
wstringstream strm;
|
||||||
|
strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
|
||||||
|
wstring devPathStr (strm.str());
|
||||||
|
const wchar_t *devPath = devPathStr.c_str();
|
||||||
|
|
||||||
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
|
if (OpenDevice (devPath, &openTest, TRUE, TRUE)
|
||||||
|
&& (openTest.VolumeIDComputed[TC_VOLUME_TYPE_NORMAL] && openTest.VolumeIDComputed[TC_VOLUME_TYPE_HIDDEN])
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if ( (0 == memcmp (volumeID, openTest.volumeIDs[TC_VOLUME_TYPE_NORMAL], VOLUME_ID_SIZE))
|
||||||
|
|| (0 == memcmp (volumeID, openTest.volumeIDs[TC_VOLUME_TYPE_HIDDEN], VOLUME_ID_SIZE))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return devPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static std::vector<HostDevice> volumeIdCandidates;
|
||||||
|
|
||||||
EnterCriticalSection (&csMountableDevices);
|
EnterCriticalSection (&csMountableDevices);
|
||||||
std::vector<HostDevice> newDevices = mountableDevices;
|
std::vector<HostDevice> newDevices = mountableDevices;
|
||||||
LeaveCriticalSection (&csMountableDevices);
|
LeaveCriticalSection (&csMountableDevices);
|
||||||
@@ -12297,6 +12306,7 @@ wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE])
|
|||||||
return It->Path;
|
return It->Path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return L"";
|
return L"";
|
||||||
}
|
}
|
||||||
@@ -12924,7 +12934,7 @@ BOOL TranslateVolumeID (HWND hwndDlg, wchar_t* pathValue, size_t cchPathValue)
|
|||||||
&& (arr.size() == VOLUME_ID_SIZE)
|
&& (arr.size() == VOLUME_ID_SIZE)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
std::wstring devicePath = FindDeviceByVolumeID (&arr[0]);
|
std::wstring devicePath = FindDeviceByVolumeID (&arr[0], FALSE);
|
||||||
if (devicePath.length() > 0)
|
if (devicePath.length() > 0)
|
||||||
StringCchCopyW (pathValue, cchPathValue, devicePath.c_str());
|
StringCchCopyW (pathValue, cchPathValue, devicePath.c_str());
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -621,7 +621,7 @@ std::wstring GetUserFriendlyVersionString (int version);
|
|||||||
std::wstring IntToWideString (int val);
|
std::wstring IntToWideString (int val);
|
||||||
std::wstring ArrayToHexWideString (const unsigned char* pbData, int cbData);
|
std::wstring ArrayToHexWideString (const unsigned char* pbData, int cbData);
|
||||||
bool HexWideStringToArray (const wchar_t* hexStr, std::vector<byte>& arr);
|
bool HexWideStringToArray (const wchar_t* hexStr, std::vector<byte>& arr);
|
||||||
std::wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE]);
|
std::wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE], BOOL bFromService);
|
||||||
void RegisterDriverInf (bool registerFilter, const std::string& filter, const std::string& filterReg, HWND ParentWindow, HKEY regKey);
|
void RegisterDriverInf (bool registerFilter, const std::string& filter, const std::string& filterReg, HWND ParentWindow, HKEY regKey);
|
||||||
std::wstring GetTempPathString ();
|
std::wstring GetTempPathString ();
|
||||||
void CorrectFileName (std::wstring& fileName);
|
void CorrectFileName (std::wstring& fileName);
|
||||||
@@ -629,7 +629,7 @@ inline std::wstring AppendSrcPos (const wchar_t* msg, const char* srcPos)
|
|||||||
{
|
{
|
||||||
return std::wstring (msg? msg : L"") + L"\n\nSource: " + SingleStringToWide (srcPos);
|
return std::wstring (msg? msg : L"") + L"\n\nSource: " + SingleStringToWide (srcPos);
|
||||||
}
|
}
|
||||||
void UpdateMountableHostDeviceList (bool bFromService);
|
void UpdateMountableHostDeviceList ();
|
||||||
INT_PTR TextEditDialogBox (BOOL readOnly, HWND parent, const WCHAR* Title, std::string& text);
|
INT_PTR TextEditDialogBox (BOOL readOnly, HWND parent, const WCHAR* Title, std::string& text);
|
||||||
|
|
||||||
// Display a wait dialog while calling the provided callback with the given parameter
|
// Display a wait dialog while calling the provided callback with the given parameter
|
||||||
|
|||||||
@@ -495,7 +495,7 @@ static void InitMainDialog (HWND hwndDlg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// initialize the list of devices available for mounting as early as possible
|
// initialize the list of devices available for mounting as early as possible
|
||||||
UpdateMountableHostDeviceList (false);
|
UpdateMountableHostDeviceList ();
|
||||||
|
|
||||||
// Resize the logo bitmap if the user has a non-default DPI
|
// Resize the logo bitmap if the user has a non-default DPI
|
||||||
if (ScreenDPI != USER_DEFAULT_SCREEN_DPI
|
if (ScreenDPI != USER_DEFAULT_SCREEN_DPI
|
||||||
@@ -7119,7 +7119,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
{
|
{
|
||||||
if (wParam == TIMER_ID_UPDATE_DEVICE_LIST)
|
if (wParam == TIMER_ID_UPDATE_DEVICE_LIST)
|
||||||
{
|
{
|
||||||
UpdateMountableHostDeviceList (false);
|
UpdateMountableHostDeviceList ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -7195,7 +7195,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
if (IsMountedVolumeID (favorite.VolumeID))
|
if (IsMountedVolumeID (favorite.VolumeID))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::wstring volDevPath = FindDeviceByVolumeID (favorite.VolumeID);
|
std::wstring volDevPath = FindDeviceByVolumeID (favorite.VolumeID, FALSE);
|
||||||
if (volDevPath.length() > 0)
|
if (volDevPath.length() > 0)
|
||||||
{
|
{
|
||||||
favorite.Path = volDevPath;
|
favorite.Path = volDevPath;
|
||||||
@@ -8486,7 +8486,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
|
|||||||
std::wstring volName;
|
std::wstring volName;
|
||||||
WaitCursor();
|
WaitCursor();
|
||||||
if (FavoriteVolumes[favoriteIndex].UseVolumeID)
|
if (FavoriteVolumes[favoriteIndex].UseVolumeID)
|
||||||
volName = FindDeviceByVolumeID (FavoriteVolumes[favoriteIndex].VolumeID);
|
volName = FindDeviceByVolumeID (FavoriteVolumes[favoriteIndex].VolumeID, FALSE);
|
||||||
else
|
else
|
||||||
volName = FavoriteVolumes[favoriteIndex].Path;
|
volName = FavoriteVolumes[favoriteIndex].Path;
|
||||||
OpenVolumeExplorerWindow (GetMountedVolumeDriveNo ((wchar_t*) FavoriteVolumes[favoriteIndex].Path.c_str()));
|
OpenVolumeExplorerWindow (GetMountedVolumeDriveNo ((wchar_t*) FavoriteVolumes[favoriteIndex].Path.c_str()));
|
||||||
@@ -9172,7 +9172,7 @@ static VOID WINAPI SystemFavoritesServiceMain (DWORD argc, LPTSTR *argv)
|
|||||||
|
|
||||||
SystemFavoritesServiceLogInfo (wstring (L"Initializing list of host devices"));
|
SystemFavoritesServiceLogInfo (wstring (L"Initializing list of host devices"));
|
||||||
// initialize the list of devices available for mounting as early as possible
|
// initialize the list of devices available for mounting as early as possible
|
||||||
UpdateMountableHostDeviceList (true);
|
UpdateMountableHostDeviceList ();
|
||||||
|
|
||||||
SystemFavoritesServiceLogInfo (wstring (L"Starting System Favorites mounting process"));
|
SystemFavoritesServiceLogInfo (wstring (L"Starting System Favorites mounting process"));
|
||||||
|
|
||||||
@@ -9479,7 +9479,7 @@ static BOOL MountFavoriteVolumeBase (HWND hwnd, const FavoriteVolume &favorite,
|
|||||||
|
|
||||||
if (favorite.UseVolumeID && !IsRepeatedByteArray (0, favorite.VolumeID, sizeof (favorite.VolumeID)))
|
if (favorite.UseVolumeID && !IsRepeatedByteArray (0, favorite.VolumeID, sizeof (favorite.VolumeID)))
|
||||||
{
|
{
|
||||||
effectiveVolumePath = FindDeviceByVolumeID (favorite.VolumeID);
|
effectiveVolumePath = FindDeviceByVolumeID (favorite.VolumeID, (ServiceMode && systemFavorites)? TRUE : FALSE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
effectiveVolumePath = favorite.Path;
|
effectiveVolumePath = favorite.Path;
|
||||||
@@ -9645,7 +9645,7 @@ BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOO
|
|||||||
{
|
{
|
||||||
if (favorite->UseVolumeID)
|
if (favorite->UseVolumeID)
|
||||||
{
|
{
|
||||||
std::wstring path = FindDeviceByVolumeID (favorite->VolumeID);
|
std::wstring path = FindDeviceByVolumeID (favorite->VolumeID, TRUE);
|
||||||
if (path.empty ())
|
if (path.empty ())
|
||||||
{
|
{
|
||||||
favorite->DisconnectedDevice = true;
|
favorite->DisconnectedDevice = true;
|
||||||
@@ -9706,7 +9706,7 @@ BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOO
|
|||||||
Sleep (5000);
|
Sleep (5000);
|
||||||
|
|
||||||
SystemFavoritesServiceLogInfo (wstring (L"Updating list of host devices"));
|
SystemFavoritesServiceLogInfo (wstring (L"Updating list of host devices"));
|
||||||
UpdateMountableHostDeviceList (true);
|
UpdateMountableHostDeviceList ();
|
||||||
|
|
||||||
SystemFavoritesServiceLogInfo (wstring (L"Trying to mount skipped system favorites"));
|
SystemFavoritesServiceLogInfo (wstring (L"Trying to mount skipped system favorites"));
|
||||||
|
|
||||||
@@ -9723,7 +9723,7 @@ BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOO
|
|||||||
wstring resolvedPath;
|
wstring resolvedPath;
|
||||||
if (favorite->UseVolumeID)
|
if (favorite->UseVolumeID)
|
||||||
{
|
{
|
||||||
resolvedPath = FindDeviceByVolumeID (favorite->VolumeID);
|
resolvedPath = FindDeviceByVolumeID (favorite->VolumeID, TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
resolvedPath = VolumeGuidPathToDevicePath (favorite->Path);
|
resolvedPath = VolumeGuidPathToDevicePath (favorite->Path);
|
||||||
|
|||||||
Reference in New Issue
Block a user