--- truecrypt/boot/windows/bootdiskio.cpp 2018/04/24 17:07:44 1.1.1.7 +++ truecrypt/boot/windows/bootdiskio.cpp 2018/04/24 17:13:46 1.1.1.10 @@ -1,7 +1,7 @@ /* - Copyright (c) 2008-2009 TrueCrypt Developers Association. All rights reserved. + Copyright (c) 2008-2011 TrueCrypt Developers Association. All rights reserved. - Governed by the TrueCrypt License 2.8 the full text of which is contained in + Governed by the TrueCrypt License 3.0 the full text of which is contained in the file License.txt included in TrueCrypt binary and source code distribution packages. */ @@ -114,30 +114,39 @@ BiosResult ReadWriteSectors (bool write, sector |= byte (chs.Cylinder >> 2) & 0xc0; byte function = write ? 0x03 : 0x02; - BiosResult result = BiosResultSuccess; - __asm - { - push es - mov ax, bufferSegment - mov es, ax - mov bx, bufferOffset - mov dl, drive - mov ch, cylinderLow - mov si, chs - mov dh, [si].Head - mov cl, sector - mov al, sectorCount - mov ah, function - int 0x13 - jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes - mov result, ah - ok: - pop es - } + BiosResult result; + byte tryCount = TC_MAX_BIOS_DISK_IO_RETRIES; - if (result == BiosResultEccCorrected) + do + { result = BiosResultSuccess; + __asm + { + push es + mov ax, bufferSegment + mov es, ax + mov bx, bufferOffset + mov dl, drive + mov ch, cylinderLow + mov si, chs + mov dh, [si].Head + mov cl, sector + mov al, sectorCount + mov ah, function + int 0x13 + jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes + mov result, ah + ok: + pop es + } + + if (result == BiosResultEccCorrected) + result = BiosResultSuccess; + + // Some BIOSes report I/O errors prematurely in some cases + } while (result != BiosResultSuccess && --tryCount != 0); + if (!silent && result != BiosResultSuccess) PrintDiskError (result, write, drive, nullptr, &chs); @@ -189,23 +198,32 @@ static BiosResult ReadWriteSectors (bool byte function = write ? 0x43 : 0x42; - BiosResult result = BiosResultSuccess; - __asm - { - mov bx, 0x55aa - mov dl, drive - mov si, [dapPacket] - mov ah, function - xor al, al - int 0x13 - jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes - mov result, ah - ok: - } + BiosResult result; + byte tryCount = TC_MAX_BIOS_DISK_IO_RETRIES; - if (result == BiosResultEccCorrected) + do + { result = BiosResultSuccess; + __asm + { + mov bx, 0x55aa + mov dl, drive + mov si, [dapPacket] + mov ah, function + xor al, al + int 0x13 + jnc ok // If CF=0, ignore AH to prevent issues caused by potential bugs in BIOSes + mov result, ah + ok: + } + + if (result == BiosResultEccCorrected) + result = BiosResultSuccess; + + // Some BIOSes report I/O errors prematurely in some cases + } while (result != BiosResultSuccess && --tryCount != 0); + if (!silent && result != BiosResultSuccess) PrintDiskError (result, write, drive, §or); @@ -383,7 +401,7 @@ BiosResult GetDrivePartitions (byte driv continue; partition.Drive = drive; - partition.Number = partitionNumber; + partition.Number = partitionArrayPos; if (partEntry.Type == 0x5 || partEntry.Type == 0xf) // Extended partition { @@ -404,7 +422,7 @@ BiosResult GetDrivePartitions (byte driv PartitionEntryMBRToPartition (extMbr->Partitions[0], logPart); logPart.Drive = drive; - logPart.Number = partitionNumber++; + logPart.Number = partitionArrayPos; logPart.Primary = false; logPart.StartSector.LowPart += extStartLBA.LowPart;