VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/ExpandVolume
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2018-08-31 22:28:27 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2018-08-31 23:15:30 (GMT)
commit95748751dfcfce1a885dfa4974ca3761ed0f7dbb (patch)
treedf0acf591180d08ed0eb2536d05cc58a159e1abb /src/ExpandVolume
parent36129ec5af14ffb33c7c7124405b336e7c7b6fdb (diff)
downloadVeraCrypt-95748751dfcfce1a885dfa4974ca3761ed0f7dbb.zip
VeraCrypt-95748751dfcfce1a885dfa4974ca3761ed0f7dbb.tar.gz
Windows: handle case of some disk drivers not supporting IOCTL_DISK_GET_DRIVE_GEOMETRY_EX IOCTL.
Diffstat (limited to 'src/ExpandVolume')
-rw-r--r--src/ExpandVolume/ExpandVolume.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/ExpandVolume/ExpandVolume.c b/src/ExpandVolume/ExpandVolume.c
index 9e9252c..0a9733a 100644
--- a/src/ExpandVolume/ExpandVolume.c
+++ b/src/ExpandVolume/ExpandVolume.c
@@ -565,11 +565,38 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas
dgBuffer, sizeof (dgBuffer), &dwResult, NULL);
if (!bResult)
- goto error;
-
- hostSize = ((PDISK_GEOMETRY_EX) dgBuffer)->DiskSize.QuadPart;
-
- HostSectorSize = ((PDISK_GEOMETRY_EX) dgBuffer)->Geometry.BytesPerSector;
+ {
+ 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;
+
+ 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), &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)