The Cancel routine cancels an I/O operation.
VOID
Cancel(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
);
None
When a driver or other system component calls IoCancelIrp, the I/O Manager calls the IRP's Cancel routine, if one has been registered for the IRP.
To register a Cancel routine for an IRP, a driver can use either of the following two methods:
Only one Cancel routine can be registered for an IRP at one time.
The I/O Manager calls IoAcquireCancelSpinLock before calling a driver's Cancel routine, so the Cancel routine must call IoReleaseCancelSpinLock at some point. The routine should not hold the spin lock longer than necessary.
The Cancel routine executes in an arbitrary thread context at IRQL = DISPATCH_LEVEL until it calls IoReleaseCancelSpinLock, which changes the IRQL to a caller-supplied value. The driver should specify Irp->CancelIrql for this value.
The Cancel routine must set the I/O status block's Status member to STATUS_CANCELLED, and set its Information member to zero. The routine must then complete the specified IRP by calling IoCompleteRequest.
For detailed information about implementing a driver's Cancel routine, see Canceling IRPs.