Previous Next

Cancel

The Cancel routine cancels an I/O operation.

VOID
  Cancel(
    IN PDEVICE_OBJECT  DeviceObject,
    IN PIRP  Irp
    );

Parameters

DeviceObject
Caller-supplied pointer to a DEVICE_OBJECT structure. This is the device object for the target device, previously created by the driver's AddDevice routine.
Irp
Caller-supplied pointer to an IRP structure that describes the I/O operation to be canceled.

Return Value

None

Comments

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:

  1. A driver that provides a StartIo routine and uses the I/O Manager-supplied device queue can specify a Cancel routine when calling IoStartPacket.
  2. A driver that creates and manages supplemental device queues can register a Cancel routine by calling IoSetCancelRoutine.

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.