diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2015-05-29 02:04:13 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2015-05-29 02:22:08 +0200 |
commit | fdc2143bfabb1e48ea0108fcf12c2e4ad438b44e (patch) | |
tree | c44b8541b125a1c4939ff9f6e63cc2592cc8e625 | |
parent | 5867250820d5676a2c4925aade2baeaa30aa2b12 (diff) | |
download | VeraCrypt-fdc2143bfabb1e48ea0108fcf12c2e4ad438b44e.tar.gz VeraCrypt-fdc2143bfabb1e48ea0108fcf12c2e4ad438b44e.zip |
Windows: workaround FormatEx keeping references on formatted volume by adding extra delays.
-rw-r--r-- | src/Common/Dlgcode.c | 18 | ||||
-rw-r--r-- | src/Common/Dlgcode.h | 1 | ||||
-rw-r--r-- | src/Common/Format.c | 6 |
3 files changed, 18 insertions, 7 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index c9d01290..bfa8a32e 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -6888,14 +6888,14 @@ retry: return 1;
}
-
-BOOL UnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forceUnmount)
+static BOOL UnmountVolumeBase (HWND hwndDlg, int nDosDriveNo, BOOL forceUnmount, BOOL ntfsFormatCase)
{
int result;
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:
BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, nDosDriveNo, 0);
@@ -6903,9 +6903,9 @@ retry: {
result = DriverUnmountVolume (hwndDlg, nDosDriveNo, forced);
if (result == ERR_FILES_OPEN)
- Sleep (UNMOUNT_AUTO_RETRY_DELAY);
+ Sleep (retryDelay);
else
break;
} while (--dismountMaxRetries > 0);
@@ -6939,8 +6939,18 @@ retry: 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)
{
DWORD dw;
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h index 7dee2db5..781efeee 100644 --- a/src/Common/Dlgcode.h +++ b/src/Common/Dlgcode.h @@ -333,8 +333,9 @@ BOOL IsDeviceMounted (char *deviceName); int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced);
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);
BOOL UnmountVolume (HWND hwndDlg , int nDosDriveNo, BOOL forceUnmount);
+BOOL UnmountVolumeAfterFormatExCall (HWND hwndDlg, int nDosDriveNo);
BOOL IsPasswordCacheEmpty (void);
BOOL IsMountedVolume (const char *volname);
int GetMountedVolumeDriveNo (char *volname);
BOOL IsAdmin (void);
diff --git a/src/Common/Format.c b/src/Common/Format.c index 37fa38da..3ebfef1e 100644 --- a/src/Common/Format.c +++ b/src/Common/Format.c @@ -640,9 +640,9 @@ error: retCode = FormatNtfs (driveNo, volParams->clusterSize);
if (retCode != TRUE)
{
- if (!UnmountVolume (volParams->hwndDlg, driveNo, FALSE))
+ if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo))
MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND);
if (dataAreaSize <= TC_MAX_FAT_SECTOR_COUNT * FormatSectorSize)
{
@@ -662,9 +662,9 @@ error: nStatus = ERR_DONT_REPORT;
goto fv_end;
}
- if (!UnmountVolume (volParams->hwndDlg, driveNo, FALSE))
+ if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo))
MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND);
}
fv_end:
@@ -835,9 +835,9 @@ BOOL FormatNtfs (int driveNo, int clusterSize) FormatEx (dir, FMIFS_HARDDISK, L"NTFS", L"", TRUE, clusterSize * FormatSectorSize, FormatExCallback);
}
// The device may be referenced for some time after FormatEx() returns
- Sleep (2000);
+ Sleep (4000);
FreeLibrary (hModule);
return FormatExResult;
}
|