VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Boot
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2019-11-04 22:21:42 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2019-11-06 23:47:52 (GMT)
commit21392ef30ddb383445783b1786541015cb937b37 (patch)
tree42f9be623866441e2eebb33007896e2951e858dd /src/Boot
parentdc08b692401afdace6de02d81feb68cbf0752e12 (diff)
downloadVeraCrypt-21392ef30ddb383445783b1786541015cb937b37.zip
VeraCrypt-21392ef30ddb383445783b1786541015cb937b37.tar.gz
Windows MBR Bootloader: workaround for SSD disks that don't allow write operations in BIOS mode with buffers less than 4096 bytes
Diffstat (limited to 'src/Boot')
-rw-r--r--src/Boot/Windows/Bios.h3
-rw-r--r--src/Boot/Windows/BootDiskIo.cpp2
-rw-r--r--src/Boot/Windows/BootDiskIo.h1
-rw-r--r--src/Boot/Windows/BootEncryptedIo.cpp11
4 files changed, 14 insertions, 3 deletions
diff --git a/src/Boot/Windows/Bios.h b/src/Boot/Windows/Bios.h
index 4e1cec5..7085e7a 100644
--- a/src/Boot/Windows/Bios.h
+++ b/src/Boot/Windows/Bios.h
@@ -24,7 +24,8 @@
enum
{
BiosResultSuccess = 0x00,
- BiosResultInvalidFunction = 0x01
+ BiosResultInvalidFunction = 0x01,
+ BiosResultTimeout = 0x80
};
typedef byte BiosResult;
diff --git a/src/Boot/Windows/BootDiskIo.cpp b/src/Boot/Windows/BootDiskIo.cpp
index 583840e..437c462 100644
--- a/src/Boot/Windows/BootDiskIo.cpp
+++ b/src/Boot/Windows/BootDiskIo.cpp
@@ -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;
dapPacket.Buffer = (uint32) buffer;
diff --git a/src/Boot/Windows/BootDiskIo.h b/src/Boot/Windows/BootDiskIo.h
index d4e8cf0..621acd8 100644
--- a/src/Boot/Windows/BootDiskIo.h
+++ b/src/Boot/Windows/BootDiskIo.h
@@ -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 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, 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 ChsAddress &chs, byte sectorCount, bool silent = false);
diff --git a/src/Boot/Windows/BootEncryptedIo.cpp b/src/Boot/Windows/BootEncryptedIo.cpp
index 25fe1dc..380d341 100644
--- a/src/Boot/Windows/BootEncryptedIo.cpp
+++ b/src/Boot/Windows/BootEncryptedIo.cpp
@@ -108,7 +108,16 @@ BiosResult WriteEncryptedSectors (uint16 sourceSegment, uint16 sourceOffset, byt
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)
break;