VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Driver
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2017-05-23 12:23:07 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2017-05-25 01:15:16 +0200
commitcda40547fe35b28321f7a00b53cc18eb9cf77cba (patch)
treec6623de47b0912a0d4f1d95a60e937d85ea078f9 /src/Driver
parenta117f040687e307c948bba04a9f98fd713f6de82 (diff)
downloadVeraCrypt-cda40547fe35b28321f7a00b53cc18eb9cf77cba.tar.gz
VeraCrypt-cda40547fe35b28321f7a00b53cc18eb9cf77cba.zip
Windows: query extra host drive information using IOCTL_STORAGE_QUERY_PROPERTY (StorageAdapterProperty) in both driver and user mode applications.
Diffstat (limited to 'src/Driver')
-rw-r--r--src/Driver/Ntdriver.h3
-rw-r--r--src/Driver/Ntvol.c33
2 files changed, 36 insertions, 0 deletions
diff --git a/src/Driver/Ntdriver.h b/src/Driver/Ntdriver.h
index 5b52ab04..09a29542 100644
--- a/src/Driver/Ntdriver.h
+++ b/src/Driver/Ntdriver.h
@@ -63,6 +63,9 @@ typedef struct EXTENSION
uint32 HostBytesPerSector;
uint32 HostBytesPerPhysicalSector;
+ ULONG HostMaximumTransferLength;
+ ULONG HostMaximumPhysicalPages;
+ ULONG HostAlignmentMask;
KEVENT keVolumeEvent; /* Event structure used when setting up a device */
diff --git a/src/Driver/Ntvol.c b/src/Driver/Ntvol.c
index 8fda0bd9..8be0393a 100644
--- a/src/Driver/Ntvol.c
+++ b/src/Driver/Ntvol.c
@@ -63,6 +63,11 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
Extension->hDeviceFile = NULL;
Extension->bTimeStampValid = FALSE;
+ /* default value for storage alignment */
+ Extension->HostMaximumTransferLength = 65536;
+ Extension->HostMaximumPhysicalPages = 17;
+ Extension->HostAlignmentMask = 0;
+
RtlInitUnicodeString (&FullFileName, pwszMountVolume);
InitializeObjectAttributes (&oaFileAttributes, &FullFileName, OBJ_CASE_INSENSITIVE | (forceAccessCheck ? OBJ_FORCE_ACCESS_CHECK : 0) | OBJ_KERNEL_HANDLE, NULL, NULL);
KeInitializeEvent (&Extension->keVolumeEvent, NotificationEvent, FALSE);
@@ -129,6 +134,31 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
TCfree (outputBuffer);
}
+
+ storagePropertyQuery.PropertyId = StorageAdapterProperty;
+ 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_ADAPTER_DESCRIPTOR pStorageDescriptor = (PSTORAGE_ADAPTER_DESCRIPTOR) outputBuffer;
+ Extension->HostMaximumTransferLength = pStorageDescriptor->MaximumTransferLength;
+ Extension->HostMaximumPhysicalPages = pStorageDescriptor->MaximumPhysicalPages;
+ Extension->HostAlignmentMask = pStorageDescriptor->AlignmentMask;
+ }
+
+ TCfree (outputBuffer);
+ }
}
// Drive geometry is used only when IOCTL_DISK_GET_PARTITION_INFO fails
@@ -179,6 +209,9 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
Extension->HostBytesPerSector = mount->BytesPerSector;
Extension->HostBytesPerPhysicalSector = mount->BytesPerPhysicalSector;
+ Extension->HostMaximumTransferLength = mount->MaximumTransferLength;
+ Extension->HostMaximumPhysicalPages = mount->MaximumPhysicalPages;
+ Extension->HostAlignmentMask = mount->AlignmentMask;
if (Extension->HostBytesPerSector != TC_SECTOR_SIZE_FILE_HOSTED_VOLUME)
disableBuffering = FALSE;