VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Format/InPlace.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Format/InPlace.c')
-rw-r--r--src/Format/InPlace.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c
index 4549cc53..b1483631 100644
--- a/src/Format/InPlace.c
+++ b/src/Format/InPlace.c
@@ -2208,24 +2208,27 @@ BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm,
// SetFilePointerEx() with FILE_BEGIN as the reference point, reaching the end of large drives
// during in-place encryption can cause significant slowdowns. By moving the file pointer
// relatively, these performance issues are mitigated.
+//
+// We fall back to absolute positioning if the relative positioning fails.
BOOL MoveFilePointer (HANDLE dev, LARGE_INTEGER offset)
{
LARGE_INTEGER currOffset;
LARGE_INTEGER diffOffset;
currOffset.QuadPart = 0;
- if (SetFilePointerEx (dev, currOffset, &currOffset, FILE_CURRENT) == 0)
- return FALSE;
-
- diffOffset.QuadPart = offset.QuadPart - currOffset.QuadPart;
- if (diffOffset.QuadPart == 0)
- return TRUE;
+ if (SetFilePointerEx (dev, currOffset, &currOffset, FILE_CURRENT))
+ {
+ diffOffset.QuadPart = offset.QuadPart - currOffset.QuadPart;
+ if (diffOffset.QuadPart == 0)
+ return TRUE;
- // Moves the file pointer by the difference between current and desired positions
- if (SetFilePointerEx (dev, diffOffset, NULL, FILE_CURRENT) == 0)
- return FALSE;
+ // Moves the file pointer by the difference between current and desired positions
+ if (SetFilePointerEx (dev, diffOffset, NULL, FILE_CURRENT))
+ return TRUE;
+ }
- return TRUE;
+ // An error occurred, fallback to absolute positioning
+ return SetFilePointerEx (dev, offset, NULL, FILE_BEGIN);
}
// Repairs damaged sectors (i.e. those with read errors) by zeroing them.
@@ -2319,7 +2322,7 @@ static int OpenBackupHeader (HANDLE dev, const wchar_t *devicePath, Password *pa
}
- nStatus = ReadVolumeHeader (FALSE, header, password, pkcs5, pim, FALSE, retMasterCryptoInfo, headerCryptoInfo);
+ nStatus = ReadVolumeHeader (FALSE, header, password, pkcs5, pim, retMasterCryptoInfo, headerCryptoInfo);
if (nStatus != ERR_SUCCESS)
goto closing_seq;