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

Windows MBR Bootloader: workaround for SSD disks that don't allow write operations in BIOS mode with buffers less than 4096 bytes

This commit is contained in:
Mounir IDRASSI
2019-11-04 23:21:42 +01:00
parent dc08b69240
commit 21392ef30d
4 changed files with 14 additions and 3 deletions

View File

@@ -24,7 +24,8 @@
enum enum
{ {
BiosResultSuccess = 0x00, BiosResultSuccess = 0x00,
BiosResultInvalidFunction = 0x01 BiosResultInvalidFunction = 0x01,
BiosResultTimeout = 0x80
}; };
typedef byte BiosResult; typedef byte BiosResult;

View File

@@ -237,7 +237,7 @@ static BiosResult ReadWriteSectors (bool write, BiosLbaPacket &dapPacket, byte d
} }
static BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent) BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent)
{ {
BiosLbaPacket dapPacket; BiosLbaPacket dapPacket;
dapPacket.Buffer = (uint32) buffer; dapPacket.Buffer = (uint32) buffer;

View File

@@ -112,6 +112,7 @@ BiosResult ReadSectors (uint16 bufferSegment, uint16 bufferOffset, byte drive, c
BiosResult ReadSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false); BiosResult ReadSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false); BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);
BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 &sector, uint16 sectorCount, bool silent); BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffset, byte drive, const uint64 &sector, uint16 sectorCount, bool silent);
BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent);
BiosResult WriteSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false); BiosResult WriteSectors (byte *buffer, byte drive, const uint64 &sector, uint16 sectorCount, bool silent = false);
BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false); BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent = false);

View File

@@ -108,7 +108,16 @@ BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byt
EncryptDataUnits (SectorBuffer, &dataUnitNo, 1, BootCryptoInfo); EncryptDataUnits (SectorBuffer, &dataUnitNo, 1, BootCryptoInfo);
} }
result = WriteSectors (SectorBuffer, drive, sector + writeOffset, 1); result = ReadWriteSectors (true, SectorBuffer, drive, sector + writeOffset, 1, false);
if (BiosResultTimeout == result)
{
result = ReadWriteSectors (false, TC_BOOT_LOADER_BUFFER_SEGMENT, 0, drive, sector + writeOffset, 8, false);
if (BiosResultSuccess == result)
{
CopyMemory (SectorBuffer, TC_BOOT_LOADER_BUFFER_SEGMENT,0, TC_LB_SIZE);
result = ReadWriteSectors (true, TC_BOOT_LOADER_BUFFER_SEGMENT, 0, drive, sector + writeOffset, 8, false);
}
}
if (result != BiosResultSuccess) if (result != BiosResultSuccess)
break; break;