Windows: use IOCTL_DISK_GET_DRIVE_GEOMETRY_EX instead of the deprecated IOCTL_DISK_GET_DRIVE_GEOMETRY in order to get accurate disk size value.

This commit is contained in:
Mounir IDRASSI 2017-05-15 16:22:48 +02:00
parent ce4e7fd64d
commit 74b82118d5
No known key found for this signature in database
GPG Key ID: DD0C382D5FCFB8FC
13 changed files with 133 additions and 83 deletions

View File

@ -119,6 +119,9 @@
#define TC_IOCTL_REREAD_DRIVER_CONFIG TC_IOCTL (37) #define TC_IOCTL_REREAD_DRIVER_CONFIG TC_IOCTL (37)
#define TC_IOCTL_GET_SYSTEM_DRIVE_DUMP_CONFIG TC_IOCTL (38) #define TC_IOCTL_GET_SYSTEM_DRIVE_DUMP_CONFIG TC_IOCTL (38)
#define VC_IOCTL_GET_BOOT_LOADER_FINGERPRINT TC_IOCTL (39) #define VC_IOCTL_GET_BOOT_LOADER_FINGERPRINT TC_IOCTL (39)
// result IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
// IN OUT - DISK_GEOMETRY_EX_STRUCT
#define VC_IOCTL_GET_DRIVE_GEOMETRY_EX TC_IOCTL (40)
// Legacy IOCTLs used before version 5.0 // Legacy IOCTLs used before version 5.0
#define TC_IOCTL_LEGACY_GET_DRIVER_VERSION 466968 #define TC_IOCTL_LEGACY_GET_DRIVER_VERSION 466968
@ -238,6 +241,14 @@ typedef struct
} }
DISK_GEOMETRY_STRUCT; DISK_GEOMETRY_STRUCT;
typedef struct
{
WCHAR deviceName[TC_MAX_PATH];
DISK_GEOMETRY diskGeometry;
LARGE_INTEGER DiskSize;
}
DISK_GEOMETRY_EX_STRUCT;
typedef struct typedef struct
{ {
WCHAR DeviceName[TC_MAX_PATH]; WCHAR DeviceName[TC_MAX_PATH];

View File

@ -1053,16 +1053,18 @@ namespace VeraCrypt
} }
DISK_GEOMETRY BootEncryption::GetDriveGeometry (int driveNumber) #ifndef SETUP
DISK_GEOMETRY_EX BootEncryption::GetDriveGeometry (int driveNumber)
{ {
wstringstream devName; wstringstream devName;
devName << L"\\Device\\Harddisk" << driveNumber << L"\\Partition0"; devName << L"\\Device\\Harddisk" << driveNumber << L"\\Partition0";
DISK_GEOMETRY geometry; DISK_GEOMETRY_EX geometry;
throw_sys_if (!::GetDriveGeometry (devName.str().c_str(), &geometry)); throw_sys_if (!::GetDriveGeometry (devName.str().c_str(), &geometry));
return geometry; return geometry;
} }
#endif // !SETUP
wstring BootEncryption::GetWindowsDirectory () wstring BootEncryption::GetWindowsDirectory ()
{ {
@ -3999,9 +4001,9 @@ namespace VeraCrypt
if (config.InitialUnallocatedSpace < TC_BOOT_LOADER_AREA_SIZE) if (config.InitialUnallocatedSpace < TC_BOOT_LOADER_AREA_SIZE)
throw ErrorException ("NO_SPACE_FOR_BOOT_LOADER", SRC_POS); throw ErrorException ("NO_SPACE_FOR_BOOT_LOADER", SRC_POS);
DISK_GEOMETRY geometry = GetDriveGeometry (config.DriveNumber); DISK_GEOMETRY_EX geometry = GetDriveGeometry (config.DriveNumber);
if (geometry.BytesPerSector != TC_SECTOR_SIZE_BIOS) if (geometry.Geometry.BytesPerSector != TC_SECTOR_SIZE_BIOS)
throw ErrorException ("SYSENC_UNSUPPORTED_SECTOR_SIZE_BIOS", SRC_POS); throw ErrorException ("SYSENC_UNSUPPORTED_SECTOR_SIZE_BIOS", SRC_POS);
bool activePartitionFound = false; bool activePartitionFound = false;
@ -4425,17 +4427,17 @@ namespace VeraCrypt
// Some chipset drivers may prevent access to the last sector of the drive // Some chipset drivers may prevent access to the last sector of the drive
if (!systemPartitionOnly) if (!systemPartitionOnly)
{ {
DISK_GEOMETRY geometry = GetDriveGeometry (config.DriveNumber); DISK_GEOMETRY_EX geometry = GetDriveGeometry (config.DriveNumber);
if ((geometry.BytesPerSector > 0) && (geometry.BytesPerSector < TC_MAX_VOLUME_SECTOR_SIZE)) if ((geometry.Geometry.BytesPerSector > 0) && (geometry.Geometry.BytesPerSector < TC_MAX_VOLUME_SECTOR_SIZE))
{ {
Buffer sector (geometry.BytesPerSector); Buffer sector (geometry.Geometry.BytesPerSector);
Device device (config.DevicePath); Device device (config.DevicePath);
device.CheckOpened (SRC_POS); device.CheckOpened (SRC_POS);
try try
{ {
device.SeekAt (config.DrivePartition.Info.PartitionLength.QuadPart - geometry.BytesPerSector); device.SeekAt (config.DrivePartition.Info.PartitionLength.QuadPart - geometry.Geometry.BytesPerSector);
device.Read (sector.Ptr(), (DWORD) sector.Size()); device.Read (sector.Ptr(), (DWORD) sector.Size());
} }
catch (SystemException &e) catch (SystemException &e)

View File

@ -310,7 +310,7 @@ namespace VeraCrypt
void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5, int pim); void CreateVolumeHeader (uint64 volumeSize, uint64 encryptedAreaStart, Password *password, int ea, int mode, int pkcs5, int pim);
wstring GetSystemLoaderBackupPath (); wstring GetSystemLoaderBackupPath ();
uint32 GetChecksum (byte *data, size_t size); uint32 GetChecksum (byte *data, size_t size);
DISK_GEOMETRY GetDriveGeometry (int driveNumber); DISK_GEOMETRY_EX GetDriveGeometry (int driveNumber);
PartitionList GetDrivePartitions (int driveNumber); PartitionList GetDrivePartitions (int driveNumber);
wstring GetRemarksOnHiddenOS (); wstring GetRemarksOnHiddenOS ();
wstring GetWindowsDirectory (); wstring GetWindowsDirectory ();

View File

@ -3102,6 +3102,7 @@ BOOL GetDriveLabel (int driveNo, wchar_t *label, int labelSize)
return GetVolumeInformationW (root, label, labelSize / 2, NULL, NULL, &fileSystemFlags, NULL, 0); return GetVolumeInformationW (root, label, labelSize / 2, NULL, NULL, &fileSystemFlags, NULL, 0);
} }
#ifndef SETUP
/* Stores the device path of the system partition in SysPartitionDevicePath and the device path of the system drive /* Stores the device path of the system partition in SysPartitionDevicePath and the device path of the system drive
in SysDriveDevicePath. in SysDriveDevicePath.
@ -3254,6 +3255,7 @@ int IsNonSysPartitionOnSysDrive (const wchar_t *path)
} }
} }
#endif //!SETUP
wstring GetSysEncryptionPretestInfo2String (void) wstring GetSysEncryptionPretestInfo2String (void)
{ {
@ -3477,6 +3479,7 @@ char * GetLegalNotices ()
return buf; return buf;
} }
#ifndef SETUP
BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
@ -3835,6 +3838,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
return 0; return 0;
} }
#endif //!SETUP
BOOL DoDriverInstall (HWND hwndDlg) BOOL DoDriverInstall (HWND hwndDlg)
{ {
@ -7266,6 +7270,8 @@ BOOL GetPhysicalDriveAlignment(UINT nDriveNumber, STORAGE_ACCESS_ALIGNMENT_DESCR
return TRUE; return TRUE;
} }
#ifndef SETUP
/************************************************************/ /************************************************************/
// implementation of the generic wait dialog mechanism // implementation of the generic wait dialog mechanism
@ -7980,6 +7986,7 @@ BOOL UnmountVolumeAfterFormatExCall (HWND hwndDlg, int nDosDriveNo)
return UnmountVolumeBase (hwndDlg, nDosDriveNo, FALSE, TRUE); return UnmountVolumeBase (hwndDlg, nDosDriveNo, FALSE, TRUE);
} }
#endif //!SETUP
BOOL IsPasswordCacheEmpty (void) BOOL IsPasswordCacheEmpty (void)
{ {
@ -8176,29 +8183,31 @@ BOOL GetDeviceInfo (const wchar_t *deviceName, DISK_PARTITION_INFO_STRUCT *info)
return DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, info, sizeof (*info), info, sizeof (*info), &dwResult, NULL); return DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, info, sizeof (*info), info, sizeof (*info), &dwResult, NULL);
} }
#ifndef SETUP
BOOL GetDriveGeometry (const wchar_t *deviceName, PDISK_GEOMETRY diskGeometry) BOOL GetDriveGeometry (const wchar_t *deviceName, PDISK_GEOMETRY_EX diskGeometry)
{ {
BOOL bResult; BOOL bResult;
DWORD dwResult; DWORD dwResult;
DISK_GEOMETRY_STRUCT dg; DISK_GEOMETRY_EX_STRUCT dg;
memset (&dg, 0, sizeof(dg)); memset (&dg, 0, sizeof(dg));
StringCbCopyW ((PWSTR) &dg.deviceName, sizeof(dg.deviceName), deviceName); StringCbCopyW ((PWSTR) &dg.deviceName, sizeof(dg.deviceName), deviceName);
bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_GEOMETRY, &dg, bResult = DeviceIoControl (hDriver, VC_IOCTL_GET_DRIVE_GEOMETRY_EX, &dg,
sizeof (dg), &dg, sizeof (dg), &dwResult, NULL); sizeof (dg), &dg, sizeof (dg), &dwResult, NULL);
if (bResult && (dwResult == sizeof (dg)) && dg.diskGeometry.BytesPerSector) if (bResult && (dwResult == sizeof (dg)) && dg.diskGeometry.BytesPerSector)
{ {
memcpy (diskGeometry, &dg.diskGeometry, sizeof (DISK_GEOMETRY)); ZeroMemory (diskGeometry, sizeof (PDISK_GEOMETRY_EX));
memcpy (&diskGeometry->Geometry, &dg.diskGeometry, sizeof (DISK_GEOMETRY));
diskGeometry->DiskSize.QuadPart = dg.DiskSize.QuadPart;
return TRUE; return TRUE;
} }
else else
return FALSE; return FALSE;
} }
BOOL GetPhysicalDriveGeometry (int driveNumber, PDISK_GEOMETRY diskGeometry) BOOL GetPhysicalDriveGeometry (int driveNumber, PDISK_GEOMETRY_EX diskGeometry)
{ {
HANDLE hDev; HANDLE hDev;
BOOL bResult = FALSE; BOOL bResult = FALSE;
@ -8210,11 +8219,11 @@ BOOL GetPhysicalDriveGeometry (int driveNumber, PDISK_GEOMETRY diskGeometry)
{ {
DWORD bytesRead = 0; DWORD bytesRead = 0;
ZeroMemory (diskGeometry, sizeof (DISK_GEOMETRY)); ZeroMemory (diskGeometry, sizeof (DISK_GEOMETRY_EX));
if ( DeviceIoControl (hDev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, diskGeometry, sizeof (DISK_GEOMETRY), &bytesRead, NULL) if ( DeviceIoControl (hDev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, diskGeometry, sizeof (DISK_GEOMETRY_EX), &bytesRead, NULL)
&& (bytesRead == sizeof (DISK_GEOMETRY)) && (bytesRead == sizeof (DISK_GEOMETRY_EX))
&& diskGeometry->BytesPerSector) && diskGeometry->Geometry.BytesPerSector)
{ {
bResult = TRUE; bResult = TRUE;
} }
@ -8224,7 +8233,7 @@ BOOL GetPhysicalDriveGeometry (int driveNumber, PDISK_GEOMETRY diskGeometry)
return bResult; return bResult;
} }
#endif
// Returns drive letter number assigned to device (-1 if none) // Returns drive letter number assigned to device (-1 if none)
int GetDiskDeviceDriveLetter (PWSTR deviceName) int GetDiskDeviceDriveLetter (PWSTR deviceName)
@ -10534,7 +10543,7 @@ int OpenVolume (OpenVolumeContext *context, const wchar_t *volumePath, Password
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE]; char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
LARGE_INTEGER headerOffset; LARGE_INTEGER headerOffset;
DWORD dwResult; DWORD dwResult;
DISK_GEOMETRY deviceGeometry; DISK_GEOMETRY_EX deviceGeometry;
context->VolumeIsOpen = FALSE; context->VolumeIsOpen = FALSE;
context->CryptoInfo = NULL; context->CryptoInfo = NULL;
@ -10602,15 +10611,15 @@ int OpenVolume (OpenVolumeContext *context, const wchar_t *volumePath, Password
} }
else else
{ {
DISK_GEOMETRY driveInfo; DISK_GEOMETRY_EX driveInfo;
if (!DeviceIoControl (context->HostFileHandle, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &driveInfo, sizeof (driveInfo), &dwResult, NULL)) if (!DeviceIoControl (context->HostFileHandle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &driveInfo, sizeof (driveInfo), &dwResult, NULL))
{ {
status = ERR_OS_ERROR; status = ERR_OS_ERROR;
goto error; goto error;
} }
context->HostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector * driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder; context->HostSize = driveInfo.DiskSize.QuadPart;
} }
if (context->HostSize == 0) if (context->HostSize == 0)
@ -10798,10 +10807,10 @@ BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
if (handle == INVALID_HANDLE_VALUE) if (handle == INVALID_HANDLE_VALUE)
continue; continue;
DISK_GEOMETRY driveInfo; DISK_GEOMETRY_EX driveInfo;
DWORD dwResult; DWORD dwResult;
if (!DeviceIoControl (handle, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &driveInfo, sizeof (driveInfo), &dwResult, NULL)) if (!DeviceIoControl (handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &driveInfo, sizeof (driveInfo), &dwResult, NULL))
{ {
CloseHandle (handle); CloseHandle (handle);
continue; continue;
@ -11398,8 +11407,6 @@ BOOL InitSecurityTokenLibrary (HWND hwndDlg)
return TRUE; return TRUE;
} }
#endif // !SETUP
std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool singleList, bool noFloppy, bool detectUnencryptedFilesystems) std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool singleList, bool noFloppy, bool detectUnencryptedFilesystems)
{ {
vector <HostDevice> devices; vector <HostDevice> devices;
@ -11436,14 +11443,13 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
} }
else else
{ {
// retrieve size using DISK_GEOMETRY // retrieve size using DISK_GEOMETRY_EX
DISK_GEOMETRY deviceGeometry = {0}; DISK_GEOMETRY_EX deviceGeometry = {0};
if ( GetDriveGeometry (devPath, &deviceGeometry) if ( GetDriveGeometry (devPath, &deviceGeometry)
|| ((partNumber == 0) && GetPhysicalDriveGeometry (devNumber, &deviceGeometry)) || ((partNumber == 0) && GetPhysicalDriveGeometry (devNumber, &deviceGeometry))
) )
{ {
device.Size = deviceGeometry.Cylinders.QuadPart * (LONGLONG) deviceGeometry.BytesPerSector device.Size = (uint64) deviceGeometry.DiskSize.QuadPart;
* (LONGLONG) deviceGeometry.SectorsPerTrack * (LONGLONG) deviceGeometry.TracksPerCylinder;
} }
} }
@ -11451,7 +11457,7 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
if (!noDeviceProperties) if (!noDeviceProperties)
{ {
DISK_GEOMETRY geometry; DISK_GEOMETRY_EX geometry;
int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str()); int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str());
@ -11469,7 +11475,7 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
} }
if (partNumber == 0 && GetDriveGeometry (devPath, &geometry)) if (partNumber == 0 && GetDriveGeometry (devPath, &geometry))
device.Removable = (geometry.MediaType == RemovableMedia); device.Removable = (geometry.Geometry.MediaType == RemovableMedia);
} }
if (partNumber == 0) if (partNumber == 0)
@ -11601,6 +11607,8 @@ wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE])
return L""; return L"";
} }
#endif // !SETUP
BOOL FileHasReadOnlyAttribute (const wchar_t *path) BOOL FileHasReadOnlyAttribute (const wchar_t *path)
{ {
DWORD attributes = GetFileAttributes (path); DWORD attributes = GetFileAttributes (path);
@ -12207,6 +12215,8 @@ BOOL IsRepeatedByteArray (byte value, const byte* buffer, size_t bufferSize)
return FALSE; return FALSE;
} }
#ifndef SETUP
BOOL TranslateVolumeID (HWND hwndDlg, wchar_t* pathValue, size_t cchPathValue) BOOL TranslateVolumeID (HWND hwndDlg, wchar_t* pathValue, size_t cchPathValue)
{ {
BOOL bRet = TRUE; BOOL bRet = TRUE;
@ -12243,6 +12253,8 @@ BOOL TranslateVolumeID (HWND hwndDlg, wchar_t* pathValue, size_t cchPathValue)
return bRet; return bRet;
} }
#endif
BOOL CopyTextToClipboard (LPCWSTR txtValue) BOOL CopyTextToClipboard (LPCWSTR txtValue)
{ {
size_t txtLen = wcslen(txtValue); size_t txtLen = wcslen(txtValue);

View File

@ -463,7 +463,7 @@ BOOL SelectMultipleFilesNext (wchar_t *lpszFileName, size_t cbFileName);
void OpenOnlineHelp (); void OpenOnlineHelp ();
BOOL GetPartitionInfo (const wchar_t *deviceName, PPARTITION_INFORMATION rpartInfo); BOOL GetPartitionInfo (const wchar_t *deviceName, PPARTITION_INFORMATION rpartInfo);
BOOL GetDeviceInfo (const wchar_t *deviceName, DISK_PARTITION_INFO_STRUCT *info); BOOL GetDeviceInfo (const wchar_t *deviceName, DISK_PARTITION_INFO_STRUCT *info);
BOOL GetDriveGeometry (const wchar_t *deviceName, PDISK_GEOMETRY diskGeometry); BOOL GetDriveGeometry (const wchar_t *deviceName, PDISK_GEOMETRY_EX diskGeometry);
BOOL GetPhysicalDriveGeometry (int driveNumber, PDISK_GEOMETRY diskGeometry); BOOL GetPhysicalDriveGeometry (int driveNumber, PDISK_GEOMETRY diskGeometry);
BOOL IsVolumeDeviceHosted (const wchar_t *lpszDiskFile); BOOL IsVolumeDeviceHosted (const wchar_t *lpszDiskFile);
int CompensateXDPI (int val); int CompensateXDPI (int val);

View File

@ -186,7 +186,7 @@ int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5,
BOOL bTimeStampValid = FALSE; BOOL bTimeStampValid = FALSE;
LARGE_INTEGER headerOffset; LARGE_INTEGER headerOffset;
BOOL backupHeader; BOOL backupHeader;
DISK_GEOMETRY driveInfo; DISK_GEOMETRY_EX driveInfo;
if (oldPassword->Length == 0 || newPassword->Length == 0) return -1; if (oldPassword->Length == 0 || newPassword->Length == 0) return -1;
@ -239,7 +239,7 @@ int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5,
DWORD dwResult; DWORD dwResult;
BOOL bResult; BOOL bResult;
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0,
&driveInfo, sizeof (driveInfo), &dwResult, NULL); &driveInfo, sizeof (driveInfo), &dwResult, NULL);
if (!bResult) if (!bResult)
@ -253,8 +253,7 @@ int ChangePwd (const wchar_t *lpszVolume, Password *oldPassword, int old_pkcs5,
} }
else else
{ {
hostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector * hostSize = driveInfo.DiskSize.QuadPart;
driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
} }
if (hostSize == 0) if (hostSize == 0)

View File

@ -1155,21 +1155,21 @@ BOOL ReadEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header, DW
#endif #endif
byte sectorBuffer[TC_MAX_VOLUME_SECTOR_SIZE]; byte sectorBuffer[TC_MAX_VOLUME_SECTOR_SIZE];
DISK_GEOMETRY geometry; DISK_GEOMETRY_EX geometry;
if (!device) if (!device)
return ReadFile (fileHandle, header, TC_VOLUME_HEADER_EFFECTIVE_SIZE, bytesRead, NULL); return ReadFile (fileHandle, header, TC_VOLUME_HEADER_EFFECTIVE_SIZE, bytesRead, NULL);
if (!DeviceIoControl (fileHandle, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &geometry, sizeof (geometry), bytesRead, NULL)) if (!DeviceIoControl (fileHandle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &geometry, sizeof (geometry), bytesRead, NULL))
return FALSE; return FALSE;
if (geometry.BytesPerSector > sizeof (sectorBuffer) || geometry.BytesPerSector < TC_MIN_VOLUME_SECTOR_SIZE) if (geometry.Geometry.BytesPerSector > sizeof (sectorBuffer) || geometry.Geometry.BytesPerSector < TC_MIN_VOLUME_SECTOR_SIZE)
{ {
SetLastError (ERROR_INVALID_PARAMETER); SetLastError (ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
} }
if (!ReadFile (fileHandle, sectorBuffer, max (TC_VOLUME_HEADER_EFFECTIVE_SIZE, geometry.BytesPerSector), bytesRead, NULL)) if (!ReadFile (fileHandle, sectorBuffer, max (TC_VOLUME_HEADER_EFFECTIVE_SIZE, geometry.Geometry.BytesPerSector), bytesRead, NULL))
return FALSE; return FALSE;
memcpy (header, sectorBuffer, min (*bytesRead, TC_VOLUME_HEADER_EFFECTIVE_SIZE)); memcpy (header, sectorBuffer, min (*bytesRead, TC_VOLUME_HEADER_EFFECTIVE_SIZE));
@ -1189,7 +1189,7 @@ BOOL WriteEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header)
byte sectorBuffer[TC_MAX_VOLUME_SECTOR_SIZE]; byte sectorBuffer[TC_MAX_VOLUME_SECTOR_SIZE];
DWORD bytesDone; DWORD bytesDone;
DISK_GEOMETRY geometry; DISK_GEOMETRY_EX geometry;
if (!device) if (!device)
{ {
@ -1205,23 +1205,23 @@ BOOL WriteEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header)
return TRUE; return TRUE;
} }
if (!DeviceIoControl (fileHandle, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &geometry, sizeof (geometry), &bytesDone, NULL)) if (!DeviceIoControl (fileHandle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &geometry, sizeof (geometry), &bytesDone, NULL))
return FALSE; return FALSE;
if (geometry.BytesPerSector > sizeof (sectorBuffer) || geometry.BytesPerSector < TC_MIN_VOLUME_SECTOR_SIZE) if (geometry.Geometry.BytesPerSector > sizeof (sectorBuffer) || geometry.Geometry.BytesPerSector < TC_MIN_VOLUME_SECTOR_SIZE)
{ {
SetLastError (ERROR_INVALID_PARAMETER); SetLastError (ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
} }
if (geometry.BytesPerSector != TC_VOLUME_HEADER_EFFECTIVE_SIZE) if (geometry.Geometry.BytesPerSector != TC_VOLUME_HEADER_EFFECTIVE_SIZE)
{ {
LARGE_INTEGER seekOffset; LARGE_INTEGER seekOffset;
if (!ReadFile (fileHandle, sectorBuffer, geometry.BytesPerSector, &bytesDone, NULL)) if (!ReadFile (fileHandle, sectorBuffer, geometry.Geometry.BytesPerSector, &bytesDone, NULL))
return FALSE; return FALSE;
if (bytesDone != geometry.BytesPerSector) if (bytesDone != geometry.Geometry.BytesPerSector)
{ {
SetLastError (ERROR_INVALID_PARAMETER); SetLastError (ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
@ -1234,10 +1234,10 @@ BOOL WriteEffectiveVolumeHeader (BOOL device, HANDLE fileHandle, byte *header)
memcpy (sectorBuffer, header, TC_VOLUME_HEADER_EFFECTIVE_SIZE); memcpy (sectorBuffer, header, TC_VOLUME_HEADER_EFFECTIVE_SIZE);
if (!WriteFile (fileHandle, sectorBuffer, geometry.BytesPerSector, &bytesDone, NULL)) if (!WriteFile (fileHandle, sectorBuffer, geometry.Geometry.BytesPerSector, &bytesDone, NULL))
return FALSE; return FALSE;
if (bytesDone != geometry.BytesPerSector) if (bytesDone != geometry.Geometry.BytesPerSector)
{ {
SetLastError (ERROR_INVALID_PARAMETER); SetLastError (ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;

View File

@ -1483,6 +1483,34 @@ NTSTATUS ProcessMainDeviceControlIrp (PDEVICE_OBJECT DeviceObject, PEXTENSION Ex
} }
break; break;
case VC_IOCTL_GET_DRIVE_GEOMETRY_EX:
if (ValidateIOBufferSize (Irp, sizeof (DISK_GEOMETRY_EX_STRUCT), ValidateInputOutput))
{
DISK_GEOMETRY_EX_STRUCT *g = (DISK_GEOMETRY_EX_STRUCT *) Irp->AssociatedIrp.SystemBuffer;
{
NTSTATUS ntStatus;
DISK_GEOMETRY_EX geo = {0};
memset (g, 0, sizeof (DISK_GEOMETRY_EX_STRUCT));
EnsureNullTerminatedString (g->deviceName, sizeof (g->deviceName));
ntStatus = TCDeviceIoControl (g->deviceName,
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL, 0, &geo, sizeof (geo));
if (NT_SUCCESS(ntStatus))
{
memcpy (&g->diskGeometry, &geo.Geometry, sizeof (DISK_GEOMETRY));
g->DiskSize.QuadPart = geo.DiskSize.QuadPart;
}
Irp->IoStatus.Information = sizeof (DISK_GEOMETRY_EX_STRUCT);
Irp->IoStatus.Status = ntStatus;
}
}
break;
case TC_IOCTL_PROBE_REAL_DRIVE_SIZE: case TC_IOCTL_PROBE_REAL_DRIVE_SIZE:
if (ValidateIOBufferSize (Irp, sizeof (ProbeRealDriveSizeRequest), ValidateInputOutput)) if (ValidateIOBufferSize (Irp, sizeof (ProbeRealDriveSizeRequest), ValidateInputOutput))
{ {
@ -2125,6 +2153,7 @@ LPWSTR TCTranslateCode (ULONG ulCode)
TC_CASE_RET_NAME (TC_IOCTL_START_DECOY_SYSTEM_WIPE); TC_CASE_RET_NAME (TC_IOCTL_START_DECOY_SYSTEM_WIPE);
TC_CASE_RET_NAME (TC_IOCTL_WIPE_PASSWORD_CACHE); TC_CASE_RET_NAME (TC_IOCTL_WIPE_PASSWORD_CACHE);
TC_CASE_RET_NAME (TC_IOCTL_WRITE_BOOT_DRIVE_SECTOR); TC_CASE_RET_NAME (TC_IOCTL_WRITE_BOOT_DRIVE_SECTOR);
TC_CASE_RET_NAME (VC_IOCTL_GET_DRIVE_GEOMETRY_EX);
TC_CASE_RET_NAME (IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS); TC_CASE_RET_NAME (IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS);
@ -3421,14 +3450,14 @@ NTSTATUS WriteRegistryConfigFlags (uint32 flags)
NTSTATUS GetDeviceSectorSize (PDEVICE_OBJECT deviceObject, ULONG *bytesPerSector) NTSTATUS GetDeviceSectorSize (PDEVICE_OBJECT deviceObject, ULONG *bytesPerSector)
{ {
NTSTATUS status; NTSTATUS status;
DISK_GEOMETRY geometry; DISK_GEOMETRY_EX geometry;
status = SendDeviceIoControlRequest (deviceObject, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &geometry, sizeof (geometry)); status = SendDeviceIoControlRequest (deviceObject, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &geometry, sizeof (geometry));
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (status))
return status; return status;
*bytesPerSector = geometry.BytesPerSector; *bytesPerSector = geometry.Geometry.BytesPerSector;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }

View File

@ -82,7 +82,7 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
PARTITION_INFORMATION pi; PARTITION_INFORMATION pi;
PARTITION_INFORMATION_EX pix; PARTITION_INFORMATION_EX pix;
LARGE_INTEGER diskLengthInfo; LARGE_INTEGER diskLengthInfo;
DISK_GEOMETRY dg; DISK_GEOMETRY_EX dg;
STORAGE_PROPERTY_QUERY storagePropertyQuery = {0}; STORAGE_PROPERTY_QUERY storagePropertyQuery = {0};
STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR storageDescriptor = {0}; STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR storageDescriptor = {0};
@ -94,12 +94,12 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
if (!NT_SUCCESS (ntStatus)) if (!NT_SUCCESS (ntStatus))
goto error; goto error;
ntStatus = TCSendHostDeviceIoControlRequest (DeviceObject, Extension, IOCTL_DISK_GET_DRIVE_GEOMETRY, (char *) &dg, sizeof (dg)); ntStatus = TCSendHostDeviceIoControlRequest (DeviceObject, Extension, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, (char *) &dg, sizeof (dg));
if (!NT_SUCCESS (ntStatus)) if (!NT_SUCCESS (ntStatus))
goto error; goto error;
lDiskLength.QuadPart = dg.Cylinders.QuadPart * dg.SectorsPerTrack * dg.TracksPerCylinder * dg.BytesPerSector; lDiskLength.QuadPart = dg.DiskSize.QuadPart;
Extension->HostBytesPerSector = dg.BytesPerSector; Extension->HostBytesPerSector = dg.Geometry.BytesPerSector;
storagePropertyQuery.PropertyId = StorageAccessAlignmentProperty; storagePropertyQuery.PropertyId = StorageAccessAlignmentProperty;
storagePropertyQuery.QueryType = PropertyStandardQuery; storagePropertyQuery.QueryType = PropertyStandardQuery;
@ -113,7 +113,7 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
} }
else else
{ {
Extension->HostBytesPerPhysicalSector = dg.BytesPerSector; Extension->HostBytesPerPhysicalSector = dg.Geometry.BytesPerSector;
} }
// Drive geometry is used only when IOCTL_DISK_GET_PARTITION_INFO fails // Drive geometry is used only when IOCTL_DISK_GET_PARTITION_INFO fails

View File

@ -559,18 +559,17 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas
} }
else else
{ {
DISK_GEOMETRY driveInfo; DISK_GEOMETRY_EX driveInfo;
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0,
&driveInfo, sizeof (driveInfo), &dwResult, NULL); &driveInfo, sizeof (driveInfo), &dwResult, NULL);
if (!bResult) if (!bResult)
goto error; goto error;
hostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector * hostSize = driveInfo.DiskSize.QuadPart;
driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
HostSectorSize = driveInfo.BytesPerSector; HostSectorSize = driveInfo.Geometry.BytesPerSector;
} }
if (hostSize == 0) if (hostSize == 0)

View File

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

View File

@ -3416,7 +3416,7 @@ BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
} }
else else
{ {
DISK_GEOMETRY driveInfo; DISK_GEOMETRY_EX driveInfo;
PARTITION_INFORMATION diskInfo; PARTITION_INFORMATION diskInfo;
BOOL piValid = FALSE; BOOL piValid = FALSE;
BOOL gValid = FALSE; BOOL gValid = FALSE;
@ -3465,8 +3465,7 @@ BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
LARGE_INTEGER lDiskFree; LARGE_INTEGER lDiskFree;
// Drive geometry info is used only when GetPartitionInfo() fails // Drive geometry info is used only when GetPartitionInfo() fails
lDiskFree.QuadPart = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector * lDiskFree.QuadPart = driveInfo.DiskSize.QuadPart;
driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
nVolumeSize = lDiskFree.QuadPart; nVolumeSize = lDiskFree.QuadPart;
@ -10320,7 +10319,7 @@ static DWORD GetFormatSectorSize ()
if (!bDevice) if (!bDevice)
return TC_SECTOR_SIZE_FILE_HOSTED_VOLUME; return TC_SECTOR_SIZE_FILE_HOSTED_VOLUME;
DISK_GEOMETRY geometry; DISK_GEOMETRY_EX geometry;
if (!GetDriveGeometry (szDiskFile, &geometry)) if (!GetDriveGeometry (szDiskFile, &geometry))
{ {
@ -10328,5 +10327,5 @@ static DWORD GetFormatSectorSize ()
AbortProcessSilent(); AbortProcessSilent();
} }
return geometry.BytesPerSector; return geometry.Geometry.BytesPerSector;
} }

View File

@ -10243,16 +10243,15 @@ int RestoreVolumeHeader (HWND hwndDlg, const wchar_t *lpszVolume)
} }
else else
{ {
DISK_GEOMETRY driveInfo; DISK_GEOMETRY_EX driveInfo;
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0,
&driveInfo, sizeof (driveInfo), &dwResult, NULL); &driveInfo, sizeof (driveInfo), &dwResult, NULL);
if (!bResult) if (!bResult)
goto error; goto error;
hostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector * hostSize = driveInfo.DiskSize.QuadPart;
driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
} }
if (hostSize == 0) if (hostSize == 0)