Path: news.mitre.org!blanket.mitre.org!philabs!newsjunkie.ans.net!newsfeeds.ans.net!news-was.dfn.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!howland.erols.net!usc!newshub.cts.com!newsfeed.cts.com!cmkrnl!jeh From: jeh@cmkrnl.com (Jamie Hanrahan) Newsgroups: comp.os.ms-windows.programmer.nt.kernel-mode Subject: Re: IoCanelIrp() question Message-ID: <1998Jan5.210112.8388@cmkrnl> Date: 5 Jan 98 21:01:12 PST References: <01bd1a13$76154c50$680010ac@mccoym> Organization: Kernel Mode Systems, San Diego, CA Lines: 40 In article <01bd1a13$76154c50$680010ac@mccoym>, "mark mccoy" writes: > I am a little confused about how to cancel an IRP that has already been > passed on to a lower level driver. My driver is a USB driver. It receives > an IOCTL from a user mode app and then allocates its own IRP to send on to > the USBD driver. I don't set a completion routine since I block on an > event until the IRP completes. Don't do this. This forces synchronous behavior onto the app. (Please don't say "the app expects this". Going against the NT I/O philosophy of asynchronous I/O is nearly always a terrible idea. Sometimes it is merely a bad idea.) Instead, you should rely on a completion callback routine to tell you that (a) the lower-level driver is done with the IRP you created and (b) you can then complete the app's IRP. Once you've done that, you can maintain some state information private to your driver that tells you whether the IRP you created has been completed by the lower layer or not. This is fairly simple if there can be only one of them at a time, more complex if there can be 'n'... but in any case, if you know it hasn't been completed, then and only then is it safe to call IoCancelIrp on it. > I would like to be able to timeout if the > IRP takes too long to complete and cancel the IRP. The DDK documentation > for IoCancelIrp() says "If a driver that does not own the IRP calls > IoCancelIrp, the results are unpredictable". Does my driver "own" the IRP? > Since I didn't register a completion routine, my assumption would be No. > Once I submit the IRP it no longer belongs to me. Correct. It might be gone by the time your call to IoCallDriver returns. --- Jamie Hanrahan, Kernel Mode Systems, San Diego CA Internet: jeh@cmkrnl.com (JH645) CompuServe: 74140,2055 drivers, internals, networks, applications, and training for VMS and Windows NT NT driver FAQ, links, and other information: http://www.cmkrnl.com/ If you post a reply in news, please don't e-mail it too.