mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Windows Driver: call IOCTL_STORAGE_QUERY_PROPERTY in a more standard way by using STORAGE_DESCRIPTOR_HEADER in order to be compatible with any future structure changes.
This commit is contained in:
@@ -84,7 +84,7 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
|
||||
LARGE_INTEGER diskLengthInfo;
|
||||
DISK_GEOMETRY_EX dg;
|
||||
STORAGE_PROPERTY_QUERY storagePropertyQuery = {0};
|
||||
STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR storageDescriptor = {0};
|
||||
STORAGE_DESCRIPTOR_HEADER storageHeader = {0};
|
||||
|
||||
ntStatus = IoGetDeviceObjectPointer (&FullFileName,
|
||||
FILE_READ_DATA | FILE_READ_ATTRIBUTES,
|
||||
@@ -100,20 +100,35 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
|
||||
|
||||
lDiskLength.QuadPart = dg.DiskSize.QuadPart;
|
||||
Extension->HostBytesPerSector = dg.Geometry.BytesPerSector;
|
||||
Extension->HostBytesPerPhysicalSector = dg.Geometry.BytesPerSector;
|
||||
|
||||
/* IOCTL_STORAGE_QUERY_PROPERTY supported only on Vista and above */
|
||||
if (OsMajorVersion >= 6)
|
||||
{
|
||||
storagePropertyQuery.PropertyId = StorageAccessAlignmentProperty;
|
||||
storagePropertyQuery.QueryType = PropertyStandardQuery;
|
||||
|
||||
/* IOCTL_STORAGE_QUERY_PROPERTY supported only on Vista and above */
|
||||
if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
|
||||
(char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
|
||||
(char *) &storageDescriptor, sizeof (storageDescriptor))))
|
||||
(char *) &storageHeader, sizeof (storageHeader))))
|
||||
{
|
||||
Extension->HostBytesPerPhysicalSector = storageDescriptor.BytesPerPhysicalSector;
|
||||
byte* outputBuffer = TCalloc (storageHeader.Size);
|
||||
if (!outputBuffer)
|
||||
{
|
||||
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
|
||||
if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
|
||||
(char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
|
||||
outputBuffer, storageHeader.Size)))
|
||||
{
|
||||
Extension->HostBytesPerPhysicalSector = dg.Geometry.BytesPerSector;
|
||||
PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR pStorageDescriptor = (PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR) outputBuffer;
|
||||
Extension->HostBytesPerPhysicalSector = pStorageDescriptor->BytesPerPhysicalSector;
|
||||
}
|
||||
|
||||
TCfree (outputBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
// Drive geometry is used only when IOCTL_DISK_GET_PARTITION_INFO fails
|
||||
|
||||
Reference in New Issue
Block a user