Windows driver: queue volume flushes as ordered barriers

Route IRP_MJ_FLUSH_BUFFERS through EncryptedIoQueue for mounted writable non-system volumes. Flushes are represented as zero-length queue items handled by the I/O thread, so ZwFlushBuffersFile runs after earlier encrypted write fragments before completing to the caller.

Also perform a best-effort ZwFlushBuffersFile before closing writable mounted-volume host handles, after the encrypted I/O queue has drained, so clean dismount/shutdown paths push the host file or raw device before close.

This keeps the change focused on ordinary mounted-volume flush ordering and avoids system-encryption, boot-drive, and header-update paths.
This commit is contained in:
Mounir IDRASSI
2026-05-22 18:29:14 +09:00
parent 79bee911be
commit d1f73ce429
4 changed files with 83 additions and 3 deletions
+12 -1
View File
@@ -621,7 +621,18 @@ NTSTATUS TCDispatchQueueIRP (PDEVICE_OBJECT DeviceObject, PIRP Irp)
return STATUS_PENDING;
case IRP_MJ_FLUSH_BUFFERS:
return TCCompleteDiskIrp (Irp, STATUS_SUCCESS, 0);
if (Extension->hDeviceFile == NULL || Extension->bReadOnly)
return TCCompleteDiskIrp (Irp, STATUS_SUCCESS, 0);
if (!EncryptedIoQueueIsRunning (&Extension->Queue))
return TCCompleteDiskIrp (Irp, STATUS_SUCCESS, 0);
ntStatus = EncryptedIoQueueAddIrp (&Extension->Queue, Irp);
if (ntStatus != STATUS_PENDING)
TCCompleteDiskIrp (Irp, ntStatus, 0);
return ntStatus;
}
break;