VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2017-05-23 12:17:40 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2017-05-25 01:15:16 +0200
commita117f040687e307c948bba04a9f98fd713f6de82 (patch)
treea2ab7e30f7ac4c307baaf7beb5421bcaf80a9fc5
parentfeef2fee91d25def1f213cd5156b641abeec8229 (diff)
downloadVeraCrypt-a117f040687e307c948bba04a9f98fd713f6de82.tar.gz
VeraCrypt-a117f040687e307c948bba04a9f98fd713f6de82.zip
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.
-rw-r--r--src/Driver/Ntvol.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/Driver/Ntvol.c b/src/Driver/Ntvol.c
index b3e08747..8fda0bd9 100644
--- a/src/Driver/Ntvol.c
+++ b/src/Driver/Ntvol.c
@@ -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;
-
- storagePropertyQuery.PropertyId = StorageAccessAlignmentProperty;
- storagePropertyQuery.QueryType = PropertyStandardQuery;
+ Extension->HostBytesPerPhysicalSector = dg.Geometry.BytesPerSector;
/* 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))))
- {
- Extension->HostBytesPerPhysicalSector = storageDescriptor.BytesPerPhysicalSector;
- }
- else
+ if (OsMajorVersion >= 6)
{
- Extension->HostBytesPerPhysicalSector = dg.Geometry.BytesPerSector;
+ storagePropertyQuery.PropertyId = StorageAccessAlignmentProperty;
+ storagePropertyQuery.QueryType = PropertyStandardQuery;
+
+ if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
+ (char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
+ (char *) &storageHeader, sizeof (storageHeader))))
+ {
+ byte* outputBuffer = TCalloc (storageHeader.Size);
+ if (!outputBuffer)
+ {
+ ntStatus = STATUS_INSUFFICIENT_RESOURCES;
+ goto error;
+ }
+
+ if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
+ (char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
+ outputBuffer, storageHeader.Size)))
+ {
+ 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