2.3 NT Driver Objects and Standard Driver Routines

Figure 2.4 illustrates a driver object, representing an NT driver, with the set of system-defined (or standard) routines that lowest-level and higher-level drivers can or must have.

Figure 2.4 also shows which of these standard routines are passed an IRP when they are called. On entry, every standard routine that is passed an IRP is also given a pointer to the target device object for the I/O request.

Figure 2.4 NT Driver Object

The I/O Manager defines the driver object type and uses driver objects to register and track information about the loaded images of NT drivers. Note the one-to-one correspondence between the Dispatch entry points in the driver object and the major function codes (IRP_MJ_XXX) that are passed in the I/O stack locations of IRPs.

As shown previously in Figure 2.3, the I/O Manager routes each IRP first to a driver-supplied Dispatch routine, and a device driver's Dispatch routine usually calls an I/O support routine (IoStartPacket) to queue (or pass on) each IRP with valid arguments to the driver's StartIo routine, which starts the requested I/O operation on a particular device. Higher-level NT drivers usually do not have StartIo routines, but they can.

When an NT driver is loaded, its DriverEntry routine is called with a pointer to the driver object. The DriverEntry routine sets one or more Dispatch entry points in the input driver object so that the I/O Manager can route IRPs to the appropriate driver-supplied Dispatch routine. The DriverEntry routine also sets the driver's StartIo and Unload entry points, if any, in the driver object.

A DriverEntry or optional Reinitialize routine also can use a field in the driver object (not shown in Figure 2.4) to get information from and/or set information in the NT Configuration Manager's registry database. For more information about how NT drivers use the registry, see Chapter 16.