Handling IRPs: What Every Driver
Writer Needs to Know
July 31, 2006
Abstract
This paper presents an overview of the I/O request packet (IRP) mechanism that is
used in the Microsoft® Windows® family of operating systems. It is intended to
provide driver writers with a greater understanding of how I/O works in the operating
system and how their drivers should manage and respond to I/O requests.
This information applies for the following operating systems:
Microsoft Windows Vista™
Microsoft Windows Server® 2003
Microsoft Windows XP
Microsoft Windows 2000
The current version of this paper is maintained at:
http://www.microsoft.com/whdc/driver/kernel/IRPs.mspx
Contents
Introduction.................................................................................................................................................3
Definition 1: IRP as a Container for an I/O Request...................................................................................3
Contents of the IRP Header..................................................................................................................4
IRP Parameters ....................................................................................................................................4
Definition 2: IRP as a Thread-Independent Call Stack...............................................................................5
Passing an IRP to the Next Lower Driver...................................................................................................5
Completing an IRP .....................................................................................................................................6
Synchronous I/O Responses......................................................................................................................7
Asynchronous I/O Responses....................................................................................................................8
IoCompletion Routines and Asynchronous I/O Responses ..................................................................9
Summary of Guidelines for Pending IRPs ..........................................................................................12
Optimizations ......................................................................................................................................13
Life Cycle of a File Object ........................................................................................................................13
IRP_MJ_CREATE Requests ..............................................................................................................13
IRP_MJ_CLEANUP Requests ............................................................................................................14
IRP_MJ_CLOSE Requests.................................................................................................................14
Data Transfer Mechanisms ......................................................................................................................15
Buffered I/O.........................................................................................................................................15
Direct I/O.............................................................................................................................................15
Neither Buffered nor Direct I/O ...........................................................................................................15
I/O Control Codes (IOCTLs).....................................................................................................................16
METHOD_BUFFERED IOCTLs..........................................................................................................16
METHOD_OUT_DIRECT IOCTLs ......................................................................................................17
METHOD_IN_DIRECT IOCTLs ..........................................................................................................17
METHOD_NEITHER IOCTLs .............................................................................................................17
Success, Error, and Warning Status for IRP Completion.........................................................................18
Building IRPs............................................................................................................................................19
Threaded IRPs....................................................................................................................................19
Nonthreaded IRPs ..............................................................................................................................19
IRP Cancellation .................................................................................................................................20
Debugging I/O Problems ..........................................................................................................................20
Call to Action and Resources ...................................................................................................................20