mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 19:08:26 -06:00
Windows: Implement TRIM support for non-system SSD partitions/drives and add driver option to enable it (TRIM is disabled by default for non-system SSD partitions/drives)
This commit is contained in:
@@ -68,6 +68,10 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
|
||||
Extension->HostMaximumPhysicalPages = 17;
|
||||
Extension->HostAlignmentMask = 0;
|
||||
|
||||
/* default values for non-SSD drives */
|
||||
Extension->IncursSeekPenalty = TRUE;
|
||||
Extension->TrimEnabled = FALSE;
|
||||
|
||||
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);
|
||||
@@ -152,6 +156,8 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
|
||||
{
|
||||
STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR alignmentDesc = {0};
|
||||
STORAGE_ADAPTER_DESCRIPTOR adapterDesc = {0};
|
||||
DEVICE_SEEK_PENALTY_DESCRIPTOR penaltyDesc = {0};
|
||||
DEVICE_TRIM_DESCRIPTOR trimDesc = {0};
|
||||
|
||||
storagePropertyQuery.PropertyId = StorageAccessAlignmentProperty;
|
||||
storagePropertyQuery.QueryType = PropertyStandardQuery;
|
||||
@@ -178,6 +184,28 @@ NTSTATUS TCOpenVolume (PDEVICE_OBJECT DeviceObject,
|
||||
Extension->HostMaximumPhysicalPages = adapterDesc.MaximumPhysicalPages;
|
||||
Extension->HostAlignmentMask = adapterDesc.AlignmentMask;
|
||||
}
|
||||
|
||||
storagePropertyQuery.PropertyId = StorageDeviceSeekPenaltyProperty;
|
||||
penaltyDesc.Version = sizeof (DEVICE_SEEK_PENALTY_DESCRIPTOR);
|
||||
penaltyDesc.Size = sizeof (DEVICE_SEEK_PENALTY_DESCRIPTOR);
|
||||
|
||||
if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
|
||||
(char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
|
||||
(char *) &penaltyDesc, sizeof (penaltyDesc))))
|
||||
{
|
||||
Extension->IncursSeekPenalty = penaltyDesc.IncursSeekPenalty;
|
||||
}
|
||||
|
||||
storagePropertyQuery.PropertyId = StorageDeviceTrimProperty;
|
||||
trimDesc.Version = sizeof (DEVICE_TRIM_DESCRIPTOR);
|
||||
trimDesc.Size = sizeof (DEVICE_TRIM_DESCRIPTOR);
|
||||
|
||||
if (NT_SUCCESS (TCSendHostDeviceIoControlRequestEx (DeviceObject, Extension, IOCTL_STORAGE_QUERY_PROPERTY,
|
||||
(char*) &storagePropertyQuery, sizeof(storagePropertyQuery),
|
||||
(char *) &trimDesc, sizeof (trimDesc))))
|
||||
{
|
||||
Extension->TrimEnabled = trimDesc.TrimEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
// Drive geometry is used only when IOCTL_DISK_GET_PARTITION_INFO fails
|
||||
|
||||
Reference in New Issue
Block a user