VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Driver/Ntvol.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Driver/Ntvol.c')
-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