From 008d0503befa55311eb12dbca42a3df25c6f29a0 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Fri, 18 Oct 2019 23:04:59 +0200 Subject: Windows: make VeraCrypt Expander able to resume expansion of volumes whose previous expansion was aborted before it finishes --- src/ExpandVolume/DlgExpandVolume.cpp | 2 +- src/ExpandVolume/ExpandVolume.c | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ExpandVolume/DlgExpandVolume.cpp b/src/ExpandVolume/DlgExpandVolume.cpp index c1acd769..adc8fa0d 100644 --- a/src/ExpandVolume/DlgExpandVolume.cpp +++ b/src/ExpandVolume/DlgExpandVolume.cpp @@ -717,7 +717,7 @@ void ExpandVolumeWizard (HWND hwndDlg, wchar_t *lpszVolume) if ( !bIsDevice ) { - if ( newVolumeSize < hostSize + TC_MINVAL_FS_EXPAND) + if ( (newVolumeSize < hostSize + TC_MINVAL_FS_EXPAND) && ((hostSize == volSize) || (newVolumeSize != hostSize) || ((hostSize - volSize) < TC_MINVAL_FS_EXPAND))) { StringCbPrintfW(szTmp,sizeof(szTmp),L"New volume size too small, must be at least %I64u kB larger than the current size.",TC_MINVAL_FS_EXPAND/BYTES_PER_KB); MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_OK | MB_ICONEXCLAMATION ); diff --git a/src/ExpandVolume/ExpandVolume.c b/src/ExpandVolume/ExpandVolume.c index 5a476ba3..588e7688 100644 --- a/src/ExpandVolume/ExpandVolume.c +++ b/src/ExpandVolume/ExpandVolume.c @@ -750,13 +750,24 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas liNewSize.QuadPart=(LONGLONG)newHostSize; - // Preallocate the file - if (!SetFilePointerEx (dev, liNewSize, NULL, FILE_BEGIN) - || !SetEndOfFile (dev) - || SetFilePointer (dev, 0, NULL, FILE_BEGIN) != 0) + if (hostSize != newHostSize) { - nStatus = ERR_OS_ERROR; - goto error; + // Preallocate the file + if (!SetFilePointerEx (dev, liNewSize, NULL, FILE_BEGIN) + || !SetEndOfFile (dev) + || SetFilePointer (dev, 0, NULL, FILE_BEGIN) != 0) + { + nStatus = ERR_OS_ERROR; + goto error; + } + } + else + { + if (SetFilePointer (dev, 0, NULL, FILE_BEGIN) != 0) + { + nStatus = ERR_OS_ERROR; + goto error; + } } } -- cgit v1.2.3