Writing Shutdown Routines

< BACK  NEXT >
[oR]

If a driver has special processing to do before the operating system disappears, a driver should supply a Shutdown routine.

Execution Context

The I/O Manager calls a Shutdown routine during a system shutdown. As described in Table 6.5, the Shutdown routine runs at PASSIVE_LEVEL IRQL, which means it has access to paged system resources.

Table 6.5. Function Prototype for Shutdown Routine
NTSTATUS Shutdown IRQL == PASSIVE_LEVEL
Parameter Description
IN PRDRIVE_OBJECT pDriverObject Pointer to driver object for this driver
IN PIRP pIrp Pointer to shutdown IRP
Return value STATUS_SUCCESS -or-
STATUS_XXX - some error code

What a Shutdown Routine Does

The main purpose of the Shutdown routine is to put the device into a quiescent state and perhaps store some device information into the system Registry. Again, saving the current volume settings from a sound card is a good example of something a Shutdown routine might do.

Unlike the driver's Unload routine, Shutdown routines don't have to worry about releasing driver resources because the operating system is about to disappear anyway.

Enabling Shutdown Notification

There is no direct field in the Driver object for announcing the Shutdown routine. Instead, the event of system shutdown is sent as a separate I/O request to a driver. It is handled with an entry inside of the driver's MajorFunction code array.

Additionally, the I/O Manager must be notified that a driver is interested in receiving shutdown notifications. This is done by making a call to IoRegisterShutdownNotification. The following code fragment shows how to enable shutdown notifications in a driver.

 NTSTATUS DriverEntry (      IN PDRIVER_OBJECT pDriverObject,      IN PUNICODE_STRING pRegistryPath ) {      :      pDriverObject->MajorFunction[ IRP_MJ_SHUTDOWN ] =                Shutdown;      IoRegisterShutdownNotification( pDriverObject );      : } 
< BACK  NEXT >


The Windows 2000 Device Driver Book(c) A Guide for Programmers
The Windows 2000 Device Driver Book: A Guide for Programmers (2nd Edition)
ISBN: 0130204315
EAN: 2147483647
Year: 2000
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net