Why do many device drivers have an IoCompleteRequest(irp,IO_NO_INCREMENT);
at the end of the dispatch routines? I read the corresponding Microsoft docs for the IoCompleteRequest
function, but I didn't understand very well those concepts.
CodePudding user response:
First, you need to understand the lifecycle of an IRP. How the IRP is created (IoAllocateIrp), delivered (IoCallDriver), and released (IoFreeIrp) after work is done. Second, if necessary, when post-processing is required at the end of the operation, the processing of the I/O completion routine is also handled in the driver hierarchical manner. IoCompleteRequest does the job of ensuring these two things.
- Application performs an I/O request.
- I/O Manager (create IRP, pass to driver)
- Driver (IRP complete after processing the job (IoCompleteRequest))
- I/O Manager (Release IRP, transfer result to upper application)
- The application receives the I/O result.