mirror of
https://github.com/veracrypt/VeraCrypt
synced 2024-12-12 12:53:30 +01:00
Windows: fallback to absolute positioning if relative positioning fails
This can serve as workaround if a disk rejects relative positioning for some reason.
This commit is contained in:
parent
4cfb4b03a7
commit
5e0aec534f
@ -2208,26 +2208,29 @@ BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm,
|
|||||||
// SetFilePointerEx() with FILE_BEGIN as the reference point, reaching the end of large drives
|
// 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
|
// during in-place encryption can cause significant slowdowns. By moving the file pointer
|
||||||
// relatively, these performance issues are mitigated.
|
// relatively, these performance issues are mitigated.
|
||||||
|
//
|
||||||
|
// We fall back to absolute positioning if the relative positioning fails.
|
||||||
BOOL MoveFilePointer (HANDLE dev, LARGE_INTEGER offset)
|
BOOL MoveFilePointer (HANDLE dev, LARGE_INTEGER offset)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER currOffset;
|
LARGE_INTEGER currOffset;
|
||||||
LARGE_INTEGER diffOffset;
|
LARGE_INTEGER diffOffset;
|
||||||
|
|
||||||
currOffset.QuadPart = 0;
|
currOffset.QuadPart = 0;
|
||||||
if (SetFilePointerEx (dev, currOffset, &currOffset, FILE_CURRENT) == 0)
|
if (SetFilePointerEx (dev, currOffset, &currOffset, FILE_CURRENT))
|
||||||
return FALSE;
|
{
|
||||||
|
|
||||||
diffOffset.QuadPart = offset.QuadPart - currOffset.QuadPart;
|
diffOffset.QuadPart = offset.QuadPart - currOffset.QuadPart;
|
||||||
if (diffOffset.QuadPart == 0)
|
if (diffOffset.QuadPart == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
// Moves the file pointer by the difference between current and desired positions
|
// Moves the file pointer by the difference between current and desired positions
|
||||||
if (SetFilePointerEx (dev, diffOffset, NULL, FILE_CURRENT) == 0)
|
if (SetFilePointerEx (dev, diffOffset, NULL, FILE_CURRENT))
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
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.
|
// Repairs damaged sectors (i.e. those with read errors) by zeroing them.
|
||||||
// Note that this operating fails if there are any write errors.
|
// Note that this operating fails if there are any write errors.
|
||||||
int ZeroUnreadableSectors (HANDLE dev, LARGE_INTEGER startOffset, int64 size, int sectorSize, uint64 *zeroedSectorCount)
|
int ZeroUnreadableSectors (HANDLE dev, LARGE_INTEGER startOffset, int64 size, int sectorSize, uint64 *zeroedSectorCount)
|
||||||
|
Loading…
Reference in New Issue
Block a user