Writing Windows WDM Device Drivers

This chapter looks at how to write driver dispatch routines that process I/O Request Packets (IRPs). Dispatch routines are used to handle requests from Win32 applications. It is crucial that you understand everything in this chapter clearly. If necessary, refer to Chapter 3 where IRPs are first introduced.
The dispatch routines for the Wdm1 driver are explained in full. These handle open, close, read, write, and IOCTL requests. The Wdm1 driver implements a global memory buffer that is shared by all Wdm1 devices.
This chapter takes a good hard look at I/O Request Packets (IRPs). It is worth reading this chapter carefully, as a good understanding of IRPs will ease your passage through the rest of the book.
Table 7.1 lists the most common Win32 functions that are used to access devices. A CreateFile call to your device ends up as a Create IRP, an I/O Request Packet with a major function code of IRP_MJ_CREATE. The driver routine to handle this IRP can have any name. However, I use a generic name for the Create IRP handler of Create. In your driver, you would usually put a short name or acronym in front of this base name. The Wdm1 device driver's Create IRP handler is called Wdm1Create .
| Win32 Function | IRP Major Code | Base Driver routine name |
|---|---|---|
| CreateFile | IRP_MJ_CREATE | Create |
| CloseHandle | IRP_MJ_CLOSE | Close |
| ReadFile | IRP_MJ_READ | Read |
| WriteFile | IRP_MJ_WRITE | Write |
| DeviceIoControl | IRP_MJ_DEVICE_CONTROL | DeviceControl |
Table...