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

Windows: use large output buffer for IOCTL_DISK_GET_DRIVE_GEOMETRY_EX calls to avoid failure with disk drivers that don't support returning only sizeof(DISK_GEOMETRY_EX).

This commit is contained in:
Mounir IDRASSI
2017-07-27 00:02:20 +02:00
parent c29ee8331a
commit 72b7147021
5 changed files with 160 additions and 157 deletions

View File

@@ -8505,11 +8505,14 @@ BOOL GetPhysicalDriveGeometry (int driveNumber, PDISK_GEOMETRY_EX diskGeometry)
DWORD bytesRead = 0;
ZeroMemory (diskGeometry, sizeof (DISK_GEOMETRY_EX));
BYTE dgBuffer[256];
if ( DeviceIoControl (hDev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, diskGeometry, sizeof (DISK_GEOMETRY_EX), &bytesRead, NULL)
&& (bytesRead == sizeof (DISK_GEOMETRY_EX))
&& diskGeometry->Geometry.BytesPerSector)
if ( DeviceIoControl (hDev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, dgBuffer, sizeof (dgBuffer), &bytesRead, NULL)
&& (bytesRead >= (sizeof (DISK_GEOMETRY) + sizeof (LARGE_INTEGER)))
&& ((PDISK_GEOMETRY_EX) dgBuffer)->Geometry.BytesPerSector)
{
memcpy (&diskGeometry->Geometry, &((PDISK_GEOMETRY_EX) dgBuffer)->Geometry, sizeof (DISK_GEOMETRY));
diskGeometry->DiskSize.QuadPart = ((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart;
bResult = TRUE;
}
@@ -10910,15 +10913,15 @@ int OpenVolume (OpenVolumeContext *context, const wchar_t *volumePath, Password
}
else
{
DISK_GEOMETRY_EX driveInfo;
BYTE dgBuffer[256];
if (!DeviceIoControl (context->HostFileHandle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &driveInfo, sizeof (driveInfo), &dwResult, NULL))
if (!DeviceIoControl (context->HostFileHandle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, dgBuffer, sizeof (dgBuffer), &dwResult, NULL))
{
status = ERR_OS_ERROR;
goto error;
}
context->HostSize = driveInfo.DiskSize.QuadPart;
context->HostSize = ((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart;
}
if (context->HostSize == 0)
@@ -11106,10 +11109,10 @@ BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
if (handle == INVALID_HANDLE_VALUE)
continue;
DISK_GEOMETRY_EX driveInfo;
BYTE dgBuffer[256];
DWORD dwResult;
if (!DeviceIoControl (handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &driveInfo, sizeof (driveInfo), &dwResult, NULL))
if (!DeviceIoControl (handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, dgBuffer, sizeof (dgBuffer), &dwResult, NULL))
{
CloseHandle (handle);
continue;

View File

@@ -187,7 +187,6 @@ int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5,
BOOL bTimeStampValid = FALSE;
LARGE_INTEGER headerOffset;
BOOL backupHeader;
DISK_GEOMETRY_EX driveInfo;
if (oldPassword->Length == 0 || newPassword->Length == 0) return -1;
@@ -236,12 +235,13 @@ int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5,
}
else
{
BYTE dgBuffer[256];
PARTITION_INFORMATION diskInfo;
DWORD dwResult;
BOOL bResult;
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0,
&driveInfo, sizeof (driveInfo), &dwResult, NULL);
dgBuffer, sizeof (dgBuffer), &dwResult, NULL);
if (!bResult)
goto error;
@@ -254,7 +254,7 @@ int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5,
}
else
{
hostSize = driveInfo.DiskSize.QuadPart;
hostSize = ((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart;
}
if (hostSize == 0)

View File

@@ -559,17 +559,17 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas
}
else
{
DISK_GEOMETRY_EX driveInfo;
BYTE dgBuffer[256];
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0,
&driveInfo, sizeof (driveInfo), &dwResult, NULL);
dgBuffer, sizeof (dgBuffer), &dwResult, NULL);
if (!bResult)
goto error;
hostSize = driveInfo.DiskSize.QuadPart;
hostSize = ((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart;
HostSectorSize = driveInfo.Geometry.BytesPerSector;
HostSectorSize = ((PDISK_GEOMETRY_EX) dgBuffer)->Geometry.BytesPerSector;
}
if (hostSize == 0)

View File

@@ -772,7 +772,7 @@ int EncryptPartitionInPlaceResume (HANDLE dev,
Password *password = volParams->password;
int pkcs5_prf = volParams->pkcs5;
int pim = volParams->pim;
DISK_GEOMETRY_EX driveGeometry;
DISK_GEOMETRY driveGeometry;
HWND hwndDlg = volParams->hwndDlg;
@@ -855,13 +855,13 @@ int EncryptPartitionInPlaceResume (HANDLE dev,
NULL);
if (!DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &driveGeometry, sizeof (driveGeometry), &dwResult, NULL))
if (!DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &driveGeometry, sizeof (driveGeometry), &dwResult, NULL))
{
nStatus = ERR_OS_ERROR;
goto closing_seq;
}
sectorSize = driveGeometry.Geometry.BytesPerSector;
sectorSize = driveGeometry.BytesPerSector;
nStatus = OpenBackupHeader (dev, devicePath, password, pkcs5_prf, pim, &masterCryptoInfo, headerCryptoInfo, deviceSize);
@@ -1282,7 +1282,7 @@ int DecryptPartitionInPlace (volatile FORMAT_VOL_PARAMETERS *volParams, volatile
HWND hwndDlg = volParams->hwndDlg;
int pkcs5_prf = volParams->pkcs5;
int pim = volParams->pim;
DISK_GEOMETRY_EX driveGeometry;
DISK_GEOMETRY driveGeometry;
buf = (char *) TCalloc (TC_MAX_NONSYS_INPLACE_ENC_WORK_CHUNK_SIZE);
@@ -1357,15 +1357,15 @@ int DecryptPartitionInPlace (volatile FORMAT_VOL_PARAMETERS *volParams, volatile
NULL);
if (!DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &driveGeometry, sizeof (driveGeometry), &dwResult, NULL))
if (!DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &driveGeometry, sizeof (driveGeometry), &dwResult, NULL))
{
nStatus = ERR_OS_ERROR;
goto closing_seq;
}
if ( (driveGeometry.Geometry.BytesPerSector == 0)
|| (driveGeometry.Geometry.BytesPerSector > TC_MAX_VOLUME_SECTOR_SIZE)
|| (driveGeometry.Geometry.BytesPerSector % ENCRYPTION_DATA_UNIT_SIZE != 0)
if ( (driveGeometry.BytesPerSector == 0)
|| (driveGeometry.BytesPerSector > TC_MAX_VOLUME_SECTOR_SIZE)
|| (driveGeometry.BytesPerSector % ENCRYPTION_DATA_UNIT_SIZE != 0)
)
{
Error ("SECTOR_SIZE_UNSUPPORTED", hwndDlg);
@@ -1373,7 +1373,7 @@ int DecryptPartitionInPlace (volatile FORMAT_VOL_PARAMETERS *volParams, volatile
goto closing_seq;
}
sectorSize = driveGeometry.Geometry.BytesPerSector;
sectorSize = driveGeometry.BytesPerSector;
tmpSectorBuf = (byte *) TCalloc (sectorSize);

View File

@@ -10448,15 +10448,15 @@ int RestoreVolumeHeader (HWND hwndDlg, const wchar_t *lpszVolume)
}
else
{
DISK_GEOMETRY_EX driveInfo;
BYTE dgBuffer[256];
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0,
&driveInfo, sizeof (driveInfo), &dwResult, NULL);
dgBuffer, sizeof (dgBuffer), &dwResult, NULL);
if (!bResult)
goto error;
hostSize = driveInfo.DiskSize.QuadPart;
hostSize = ((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart;
}
if (hostSize == 0)