diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2018-09-01 00:28:27 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2018-09-01 01:15:30 +0200 |
commit | 95748751dfcfce1a885dfa4974ca3761ed0f7dbb (patch) | |
tree | df0acf591180d08ed0eb2536d05cc58a159e1abb /src/Common/Password.c | |
parent | 36129ec5af14ffb33c7c7124405b336e7c7b6fdb (diff) | |
download | VeraCrypt-95748751dfcfce1a885dfa4974ca3761ed0f7dbb.tar.gz VeraCrypt-95748751dfcfce1a885dfa4974ca3761ed0f7dbb.zip |
Windows: handle case of some disk drivers not supporting IOCTL_DISK_GET_DRIVE_GEOMETRY_EX IOCTL.
Diffstat (limited to 'src/Common/Password.c')
-rw-r--r-- | src/Common/Password.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/Common/Password.c b/src/Common/Password.c index 5643cef0..a5050d75 100644 --- a/src/Common/Password.c +++ b/src/Common/Password.c @@ -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); |