mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Windows: handle case of some disk drivers not supporting IOCTL_DISK_GET_DRIVE_GEOMETRY_EX IOCTL.
This commit is contained in:
@@ -565,11 +565,38 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas
|
||||
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))
|
||||
{
|
||||
hostSize = geo.Cylinders.QuadPart * geo.SectorsPerTrack * geo.TracksPerCylinder * geo.BytesPerSector;
|
||||
HostSectorSize = geo.BytesPerSector;
|
||||
|
||||
hostSize = ((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart;
|
||||
if (CurrentOSMajor >= 6)
|
||||
{
|
||||
STORAGE_READ_CAPACITY storage = {0};
|
||||
|
||||
HostSectorSize = ((PDISK_GEOMETRY_EX) dgBuffer)->Geometry.BytesPerSector;
|
||||
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), &dwResult, NULL)
|
||||
&& (dwResult >= sizeof (storage))
|
||||
&& (storage.Size == sizeof (STORAGE_READ_CAPACITY))
|
||||
)
|
||||
{
|
||||
hostSize = storage.DiskLength.QuadPart;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hostSize = ((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart;
|
||||
HostSectorSize = ((PDISK_GEOMETRY_EX) dgBuffer)->Geometry.BytesPerSector;
|
||||
}
|
||||
}
|
||||
|
||||
if (hostSize == 0)
|
||||
|
||||
Reference in New Issue
Block a user