In a recent thread, there was an argument between Peter Viscarola and me about whether it is “kosher” to use some coding pattern.
The issue occurs when there is a need to first pend the IRP till some later event will occur, and then, when the event will occur, to pass this same IRP down to the lower driver.
The suggested pattern is:
dispatch routine:
IoMarkIrpPending
put the IRP to some list
return STATUS_PENDING;
when the event occurs:
take the IRP off the list
IoSkipCurrentIrpStackLocation
(VOID)IoCallDriver(LowerDO, Irp);
Peter says this is not OK, since IoSkip propagates the SL_PENDING_RETURNED flag to the next driver’s SL, and, if the next driver will return non-pending status, this is a rules violation.
The contra-argument is: even if this will go that way, the return value of the lower driver just plain does not care, since the IO manager never sees it and sees STATUS_PENDING instead.
Probably, Peter is correct nevertheless: even if the IO manager will never see the return value from the lower driver (the (VOID)IoCallDriver call), Verifier’s instrumented IoCallDriver can possibly see it and complain.
But, for me, the only solution to this problem (if Peter is correct and this is a really problem) is:
dispatch routine:
IoCopyCurrentIrpStackLocationToNext // set up NextLoc without the pending flag
IoMarkIrpPending // set the pending flag in CurrentLoc and NOT in NextLoc
put the IRP to some list
return STATUS_PENDING;
when the event occurs:
take the IRP off the list
(VOID)IoCallDriver(LowerDO, Irp)
which looks very ugly, since IoSkip/IoCopy are logical companions of IoCallDriver and not of the “put IRP to list” path.
What about MS’s code? what pattern is it using?
Surely there are some MS’s filters like VolSnap.sys which have exactly the same pattern: first pend the IRP (write) till some activity (disk block redirections) will be done, and then pass this IRP down unchanged. What approach - of the 2 above - is used by VolSnap.sys? by other MS’s drivers?
–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com