A create request can originate either in a user-mode subsystem’s attempt to get a handle for the file object representing the device (possibly on behalf of an application or subsystem-level driver) or in a higher-level driver’s call to IoGetDeviceObjectPointer or IoAttachDevice.
The reciprocal close request can originate in a user-mode subsystem’s close of the file object handle associated with the driver’s device object or in a higher-level driver’s call to IoDetachDevice.
Each of these requests is inherently synchronous.
An NT driver’s Dispatch routine(s) for IRP_MJ_CREATE and IRP_MJ_CLOSE requests might do nothing more than complete the input IRP with STATUS_SUCCESS, as already mentioned in Chapter 4.
Another NT driver’s Dispatch routine(s) 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:
For more information about discardable, pageable, and pageable-image driver code, see the Programmer’s Guide. For more information about the preceding support routines, see the Kernel-mode Driver Reference.
Although many NT drivers have a single Dispatch routine for create and close requests, any NT driver writer can implement separate DispatchCreate and DispatchClose routines. Some NT drivers handle IRP_MJ_CLOSE requests only for symmetry because, after their device objects have been opened by a protected subsystem or higher-level NT driver, the lower-level drivers’ device objects are not closed until the system itself is shut down.
In general, a DispatchClose routine is not called if it is implemented in any lower-level NT driver for an underlying physical device that must be available for the system to continue running.
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 minimalist DispatchClose routines for symmetry or combined DispatchCreateClose routines.
As another example, some of the the system disk drivers have no DispatchClose routine, but these drivers usually have DispatchFlush and DispatchShutdown routines to complete any outstanding file I/O operations before the system is shut down.