1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Windows: workaround FormatEx keeping references on formatted volume by adding extra delays.

This commit is contained in:
Mounir IDRASSI
2015-05-29 02:04:13 +02:00
parent 5867250820
commit fdc2143bfa
3 changed files with 18 additions and 7 deletions

View File

@@ -6889,12 +6889,12 @@ retry:
return 1; return 1;
} }
static BOOL UnmountVolumeBase (HWND hwndDlg, int nDosDriveNo, BOOL forceUnmount, BOOL ntfsFormatCase)
BOOL UnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forceUnmount)
{ {
int result; int result;
BOOL forced = forceUnmount; BOOL forced = forceUnmount;
int dismountMaxRetries = UNMOUNT_MAX_AUTO_RETRIES; int dismountMaxRetries = ntfsFormatCase? 5 : UNMOUNT_MAX_AUTO_RETRIES;
DWORD retryDelay = ntfsFormatCase? 2000: UNMOUNT_AUTO_RETRY_DELAY;
retry: retry:
BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, nDosDriveNo, 0); BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, nDosDriveNo, 0);
@@ -6904,7 +6904,7 @@ retry:
result = DriverUnmountVolume (hwndDlg, nDosDriveNo, forced); result = DriverUnmountVolume (hwndDlg, nDosDriveNo, forced);
if (result == ERR_FILES_OPEN) if (result == ERR_FILES_OPEN)
Sleep (UNMOUNT_AUTO_RETRY_DELAY); Sleep (retryDelay);
else else
break; break;
@@ -6940,6 +6940,16 @@ retry:
return TRUE; return TRUE;
} }
BOOL UnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forceUnmount)
{
return UnmountVolumeBase (hwndDlg, nDosDriveNo, forceUnmount, FALSE);
}
BOOL UnmountVolumeAfterFormatExCall (HWND hwndDlg, int nDosDriveNo)
{
return UnmountVolumeBase (hwndDlg, nDosDriveNo, FALSE, TRUE);
}
BOOL IsPasswordCacheEmpty (void) BOOL IsPasswordCacheEmpty (void)
{ {

View File

@@ -334,6 +334,7 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced);
void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap); void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap);
int MountVolume (HWND hwndDlg, int driveNo, char *volumePath, Password *password, int pkcs5, int pin, BOOL truecryptMode, BOOL cachePassword, BOOL sharedAccess, const MountOptions* const mountOptions, BOOL quiet, BOOL bReportWrongPassword); int MountVolume (HWND hwndDlg, int driveNo, char *volumePath, Password *password, int pkcs5, int pin, BOOL truecryptMode, BOOL cachePassword, BOOL sharedAccess, const MountOptions* const mountOptions, BOOL quiet, BOOL bReportWrongPassword);
BOOL UnmountVolume (HWND hwndDlg , int nDosDriveNo, BOOL forceUnmount); BOOL UnmountVolume (HWND hwndDlg , int nDosDriveNo, BOOL forceUnmount);
BOOL UnmountVolumeAfterFormatExCall (HWND hwndDlg, int nDosDriveNo);
BOOL IsPasswordCacheEmpty (void); BOOL IsPasswordCacheEmpty (void);
BOOL IsMountedVolume (const char *volname); BOOL IsMountedVolume (const char *volname);
int GetMountedVolumeDriveNo (char *volname); int GetMountedVolumeDriveNo (char *volname);

View File

@@ -641,7 +641,7 @@ error:
if (retCode != TRUE) if (retCode != TRUE)
{ {
if (!UnmountVolume (volParams->hwndDlg, driveNo, FALSE)) if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo))
MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND); MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND);
if (dataAreaSize <= TC_MAX_FAT_SECTOR_COUNT * FormatSectorSize) if (dataAreaSize <= TC_MAX_FAT_SECTOR_COUNT * FormatSectorSize)
@@ -663,7 +663,7 @@ error:
goto fv_end; goto fv_end;
} }
if (!UnmountVolume (volParams->hwndDlg, driveNo, FALSE)) if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo))
MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND); MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND);
} }
@@ -836,7 +836,7 @@ BOOL FormatNtfs (int driveNo, int clusterSize)
} }
// The device may be referenced for some time after FormatEx() returns // The device may be referenced for some time after FormatEx() returns
Sleep (2000); Sleep (4000);
FreeLibrary (hModule); FreeLibrary (hModule);
return FormatExResult; return FormatExResult;