1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2026-01-04 04:38:12 -06:00

Windows: handle case of some disk drivers not supporting IOCTL_DISK_GET_DRIVE_GEOMETRY_EX IOCTL.

This commit is contained in:
Mounir IDRASSI
2018-09-01 00:28:27 +02:00
parent 36129ec5af
commit 95748751df
4 changed files with 135 additions and 9 deletions

View File

@@ -244,7 +244,33 @@ int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5,
dgBuffer, sizeof (dgBuffer), &dwResult, NULL);
if (!bResult)
goto error;
{
DISK_GEOMETRY geo;
if (DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, (LPVOID) &geo, sizeof (geo), &dwResult, NULL))
{
((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart = geo.Cylinders.QuadPart * geo.SectorsPerTrack * geo.TracksPerCylinder * geo.BytesPerSector;
if (CurrentOSMajor >= 6)
{
STORAGE_READ_CAPACITY storage = {0};
storage.Version = sizeof (STORAGE_READ_CAPACITY);
storage.Size = sizeof (STORAGE_READ_CAPACITY);
if (DeviceIoControl (dev, IOCTL_STORAGE_READ_CAPACITY, NULL, 0, (LPVOID) &storage, sizeof (storage), &bytesRead, NULL)
&& (bytesRead >= sizeof (storage))
&& (storage.Size == sizeof (STORAGE_READ_CAPACITY))
)
{
((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart = storage.DiskLength.QuadPart;
}
}
}
else
{
goto error;
}
}
bResult = GetPartitionInfo (lpszVolume, &diskInfo);