Redigera

Dela via


Separate DispatchCreate and DispatchClose Routines

A driver's Dispatch routines for IRP_MJ_CREATE and IRP_MJ_CLOSE requests might do nothing more than complete the input IRP with STATUS_SUCCESS. For more information, see Completing IRPs.

Another driver's Dispatch routines for IRP_MJ_CREATE and IRP_MJ_CLOSE requests might do more work, depending on the underlying device driver or on the underlying device. Consider the following scenarios:

  • On receipt of a create request, a class driver might initialize an internal queue and send an IRP_MJ_INTERNAL_DEVICE_CONTROL request down to the corresponding port driver requesting device configuration information or exclusive access to a controller port.

  • Receipt of IRP_MJ_CLOSE indicates that the last reference to the file object that is associated with the target device object has been removed. This implies that all handles to the file object has been closed and all outstanding I/O requests have been completed or canceled.

  • On receipt of a create request, a driver of an infrequently used device might call MmLockPagableCodeSection to make resident some of the driver routines that process other IRP_MJ_XXX requests. On receipt of a reciprocal close request, the driver might call MmUnlockPagableImageSection to conserve system memory by having its pageable-image section paged out when all file object handles for such a driver's device object(s) are closed.

Some drivers handle IRP_MJ_CLOSE requests only for symmetry because, after their device objects have been opened by a protected subsystem or higher-level driver, the lower-level drivers' device objects are not closed until the system itself is shut down. For example, keyboard and mouse drivers set up device objects representing physical devices that must be functional while the system is running, so these drivers might have minimal DispatchClose routines for symmetry, or they might have combined DispatchCreateClose routines.

If the device controlled by a lower-level driver must be available for the system to continue running, the driver's DispatchClose routine generally will not be called. For example, some of the system disk drivers have no DispatchClose routine, but these drivers usually have DispatchFlushBuffers and DispatchShutdown routines to complete any outstanding file I/O operations before the system is shut down.

While you can implement separate DRIVER_DISPATCH and DispatchClose routines, drivers sometimes have a single DispatchCreateClose routine for handling both create and close requests.