Handling IRPs 4: Completing an IRP

来源:互联网 发布:nodejs高级编程 中文 编辑:程序博客网 时间:2024/05/18 02:33

Completing an IRP

When I/O is complete, the driver that completed the I/O calls theIoCompleteRequest routine. This routine moves the IRP stack pointer to point to the next higher location in the IRP stack, as Figure 3 shows.

 

 

Figure 3. IRP completion and stack pointer

Figure 3 shows the current I/O stack location after driver C has calledIoCompleteRequest. The solid arrow on the left indicates that the stack pointer now points to the parameters and callback for driver B. The dotted arrow indicates the previous stack location. The hollow arrow on the right indicates the order in which the IoCompletion routines are called.

Note: For ease of explanation, this paper shows the I/O stack locations in the IRP “upside-down,” that is, in inverted order from A to C instead of from C to A. Using an inverted diagram enables calls that proceed “down” the device stack to point downwards.

If a driver set an IoCompletion routine as it passed the IRP down the device stack, the I/O Manager calls that routine when the IRP stack pointer once again points to the I/O stack location for the driver. In this way, IoCompletion routines act as return addresses for the drivers that handled the IRP as it traversed the device stack.

An IoCompletion routine can return either of two status values:

·         STATUS_CONTINUE_COMPLETION—continues the upward completion of the IRP. The I/O Manager advances the IRP stack pointer and calls the next-higher driver’sIoCompletion routine.

·         STATUS_MORE_PROCESSING_REQUIRED—stops the upward completion of the IRP and leaves the IRP stack pointer at its current location. Drivers that return this status usually restart the upward completion of the IRP later by calling theIoCompleteRequest routine.

 

When every driver has completed its corresponding sub-request, the I/O request is complete. The I/O Manager retrieves the status of the request from theIrp‑>IoStatus.Status field and retrieves the number of bytes transferred from theIrp‑>IoStatus.Information field.