SCSI Filter driver - getting eject notification

Hi guys,

Anyone know of a way in a SCSI filter driver (which monitors all SCSI
requests to CD-ROM’s) to get notification when a disk has been inserted?

Any help would be much appreciated.

Lee Griff


This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com


On Thu, 10 Apr 2003 10:28:06 +0100, “Lee Griffiths”
wrote:

>Hi guys,
>
>Anyone know of a way in a SCSI filter driver (which monitors all SCSI
>requests to CD-ROM’s) to get notification when a disk has been inserted?
>
>Any help would be much appreciated.
>
>Lee Griff

The only reliable way I’ve found to do this is to use a lower class
filter driver that polls the device with a SCSIOP_TEST_UNIT_READY
every couple of seconds.

You will also need to handle any similar SCSI requests that are sent
down by drivers above yours. If you fail to do this you will find that
the upper drivers will be eating the sense data that you need and you
will be eating the sense data that they need.

An example of polling a CDROM device with an IoTimer routine is
available in the CDROM class driver DDK sample. Look at the code that
supports media change notification.

…John

Why not just register for the media change PNP notification that cdrom
signals when it detects a media change?

-p

-----Original Message-----
From: John Hensley [mailto:xxxxx@msn.com]
Sent: Thursday, April 10, 2003 7:12 AM
To: NT Developers Interest List

On Thu, 10 Apr 2003 10:28:06 +0100, “Lee Griffiths”
wrote:

>Hi guys,
>
>Anyone know of a way in a SCSI filter driver (which monitors all SCSI
>requests to CD-ROM’s) to get notification when a disk has been
inserted?
>
>Any help would be much appreciated.
>
>Lee Griff

The only reliable way I’ve found to do this is to use a lower class
filter driver that polls the device with a SCSIOP_TEST_UNIT_READY every
couple of seconds.

You will also need to handle any similar SCSI requests that are sent
down by drivers above yours. If you fail to do this you will find that
the upper drivers will be eating the sense data that you need and you
will be eating the sense data that they need.

An example of polling a CDROM device with an IoTimer routine is
available in the CDROM class driver DDK sample. Look at the code that
supports media change notification.

…John


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

The PnP media change notification was not always reliable when I tried
this route. The MCN timer routine in the CD-ROM class driver appeared
to be turned off on some machines and I’d miss the disk insertions.

…John

wrote:

>
>Why not just register for the media change PNP notification that cdrom
>signals when it detects a media change?
>
>-p
>
>
>-----Original Message-----
>From: John Hensley [mailto:xxxxx@msn.com]
>Sent: Thursday, April 10, 2003 7:12 AM
>To: NT Developers Interest List
>
>On Thu, 10 Apr 2003 10:28:06 +0100, “Lee Griffiths”
> wrote:
>
>>Hi guys,
>>
>>Anyone know of a way in a SCSI filter driver (which monitors all SCSI
>>requests to CD-ROM’s) to get notification when a disk has been
>inserted?
>>
>>Any help would be much appreciated.
>>
>>Lee Griff
>
>The only reliable way I’ve found to do this is to use a lower class
>filter driver that polls the device with a SCSIOP_TEST_UNIT_READY every
>couple of seconds.
>
>You will also need to handle any similar SCSI requests that are sent
>down by drivers above yours. If you fail to do this you will find that
>the upper drivers will be eating the sense data that you need and you
>will be eating the sense data that they need.
>
>An example of polling a CDROM device with an IoTimer routine is
>available in the CDROM class driver DDK sample. Look at the code that
>supports media change notification.
>
>…John
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@microsoft.com To
>unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>

Applicable to W2K(? I didn’t verify ?), WXP, and WS03:

The storage class drivers report media change to the entire system through
the use of:

IoReportTargetDeviceChangeAsynchronous(), with a GUID of
GUID_IO_MEDIA_EJECT_REQUEST.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/kmarch/hh/kmarch/k104_2f5e.asp

You can register for these notifications with
IoRegisterPlugPlayNotification().
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/kmarch/hh/kmarch/k104_7diq.asp

This is how the MediaChangeNotification functionality occurs, how the
shell listens for MCN to create Autorun functionality, and how other
services (such as Removable Media Storage) find out about media
arrival/removal.

If you want to keep your own internal state based on the SCSI commands
directly, it’s more complex. Here’s the starting point: listen for a
SenseKey of Unit Attention, AdditionSenseCode/AdditionalSenseCodeQualifier
(ASC/ASCQ) of 29/00 (Medium may have changed). You actually have to do a
lot more, and I don’t have the resources to describe all the edge cases or
unusual paths that can occur, so I recommend just listening for the event.

.

-----Original Message-----
From: Lee Griffiths [mailto:xxxxx@first4internet.co.uk]
Sent: Thursday, April 10, 2003 2:28 AM

Hi guys,

Anyone know of a way in a SCSI filter driver (which monitors all SCSI
requests to CD-ROM’s) to get notification when a disk has been inserted?

Any help would be much appreciated.

Lee Griff


This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com


They’re often turned off for good reasons - like the administrator
wanted them turned off, or the drive gets testy if you poll it a lot,
etc…

Another option is to watch requests which come back from the class
driver and catch ones completing with STATUS_VERIFY_REQUIRED. This is
how the class driver notifies the file system that the media MAY have
changed. The FS then sends a bunch of IO marked with
SL_OVERRIDE_VERFIY_VOLUME and once it’s done clears the DO_VERIFY_VOLUME
in the class driver’s device object (and yes, I do find the idea of one
driver poking the flags of another disgusting)

Of course this only happens when media is mounted. Whether this is
sufficient depends entirely on what is it you want to do with the MCN
notifications.

If you’re going to poll, do it from an upper filter so the class driver
can see the media change status as the request comes through. When you
poll from a lower filter you tend to swallow such events which makes
everything above you a bit irate.

-p

-----Original Message-----
From: John Hensley [mailto:xxxxx@msn.com]
Sent: Friday, April 11, 2003 7:29 AM
To: NT Developers Interest List

The PnP media change notification was not always reliable when I tried
this route. The MCN timer routine in the CD-ROM class driver appeared to
be turned off on some machines and I’d miss the disk insertions.

…John

wrote:

>
>Why not just register for the media change PNP notification that cdrom
>signals when it detects a media change?
>
>-p
>
>
>-----Original Message-----
>From: John Hensley [mailto:xxxxx@msn.com]
>Sent: Thursday, April 10, 2003 7:12 AM
>To: NT Developers Interest List
>
>On Thu, 10 Apr 2003 10:28:06 +0100, “Lee Griffiths”
> wrote:
>
>>Hi guys,
>>
>>Anyone know of a way in a SCSI filter driver (which monitors all SCSI
>>requests to CD-ROM’s) to get notification when a disk has been
>inserted?
>>
>>Any help would be much appreciated.
>>
>>Lee Griff
>
>The only reliable way I’ve found to do this is to use a lower class
>filter driver that polls the device with a SCSIOP_TEST_UNIT_READY every

>couple of seconds.
>
>You will also need to handle any similar SCSI requests that are sent
>down by drivers above yours. If you fail to do this you will find that
>the upper drivers will be eating the sense data that you need and you
>will be eating the sense data that they need.
>
>An example of polling a CDROM device with an IoTimer routine is
>available in the CDROM class driver DDK sample. Look at the code that
>supports media change notification.
>
>…John
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@microsoft.com To
>unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

On Fri, 11 Apr 2003 11:14:44 -0700, “Peter Wieland”
wrote:

>
>They’re often turned off for good reasons - like the administrator
>wanted them turned off, or the drive gets testy if you poll it a lot,
>etc…

Unfortunately most administrators expect formatted CDRWs to mount
automatically even after they’ve turned off MCN. Drivers for CD
burning software or things like Iomega’s Activity Disk really need to
be controlled independently of the normal autorun features and have
there own method of enabling and disabling such functionality.

When I wrote the filter drivers to support Activity Disk and Hotburn I
really scratched my head about this problem for a long time and really
wanted to leverage off of MCN but could never come up with an
acceptible solution other than having my drive do polling.

I also needed to poll the nonsense data to detect whether the eject
button has been pressed while the media is locked in the drive so that
they can signal an application to do cleanup work and then unlock the
media and eject it. It would be great if there was better way to
handle both of these issues.

>Another option is to watch requests which come back from the class
>driver and catch ones completing with STATUS_VERIFY_REQUIRED. This is
>how the class driver notifies the file system that the media MAY have
>changed. The FS then sends a bunch of IO marked with
>SL_OVERRIDE_VERFIY_VOLUME and once it’s done clears the DO_VERIFY_VOLUME
>in the class driver’s device object (and yes, I do find the idea of one
>driver poking the flags of another disgusting)
>
>Of course this only happens when media is mounted. Whether this is
>sufficient depends entirely on what is it you want to do with the MCN
>notifications.

In a lower filter I found this alone did not work and I was forced to
save the SCSI sense data whenever I saw the media change and then
catch the next IRP_MJ_SCSIS reqest or IRP_MJ_DEVICE_CONTROL, whichever
shows up first, and then emulate what would have happened had I not
eaten the sense data.

>If you’re going to poll, do it from an upper filter so the class driver
>can see the media change status as the request comes through. When you
>poll from a lower filter you tend to swallow such events which makes
>everything above you a bit irate.

Unfortunately most filter drivers need to be under the class driver to
be able to catch all of the requests coming down from the class
driver.

Hopefully the functionality needed for applications to easily burn CDs
and DVDs will eventually available in Windows. I have to say that XP
is a good start with the IMAPI interface but it needs more flexiblity
to be usable by most applications.

It would be nice if a service pack could make similar functionality
available in Windows 2K as well but I guess I’m just being greedy:)

Regards,
…John

>-p
>
>
>-----Original Message-----
>From: John Hensley [mailto:xxxxx@msn.com]
>Sent: Friday, April 11, 2003 7:29 AM
>To: NT Developers Interest List
>
>
>
>The PnP media change notification was not always reliable when I tried
>this route. The MCN timer routine in the CD-ROM class driver appeared to
>be turned off on some machines and I’d miss the disk insertions.
>
>…John
>
> wrote:
>
>>
>>Why not just register for the media change PNP notification that cdrom
>>signals when it detects a media change?
>>
>>-p
>>
>>
>>-----Original Message-----
>>From: John Hensley [mailto:xxxxx@msn.com]
>>Sent: Thursday, April 10, 2003 7:12 AM
>>To: NT Developers Interest List
>>
>>On Thu, 10 Apr 2003 10:28:06 +0100, “Lee Griffiths”
>> wrote:
>>
>>>Hi guys,
>>>
>>>Anyone know of a way in a SCSI filter driver (which monitors all SCSI
>>>requests to CD-ROM’s) to get notification when a disk has been
>>inserted?
>>>
>>>Any help would be much appreciated.
>>>
>>>Lee Griff
>>
>>The only reliable way I’ve found to do this is to use a lower class
>>filter driver that polls the device with a SCSIOP_TEST_UNIT_READY every
>
>>couple of seconds.
>>
>>You will also need to handle any similar SCSI requests that are sent
>>down by drivers above yours. If you fail to do this you will find that
>>the upper drivers will be eating the sense data that you need and you
>>will be eating the sense data that they need.
>>
>>An example of polling a CDROM device with an IoTimer routine is
>>available in the CDROM class driver DDK sample. Look at the code that
>>supports media change notification.
>>
>>…John
>>
>>
>>
>>—
>>You are currently subscribed to ntdev as: xxxxx@microsoft.com To
>>unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@microsoft.com To
>unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>

This is by design. Clients can temporarily disable MCN via IOCTL_STORAGE_MCN_CONTROL.

Polling on your own will eat the sense data that the upper layers require. I strongly suggest against this path. Instead, if you interpret the sense data for all existing requests that are occurring, you should be able to find the media changes.

.

-----Original Message-----
From: John Hensley [mailto:xxxxx@msn.com]
Sent: Friday, April 11, 2003 7:29 AM

The PnP media change notification was not always reliable when I tried
this route. The MCN timer routine in the CD-ROM class driver appeared
to be turned off on some machines and I’d miss the disk insertions.

…John

wrote:

>
>Why not just register for the media change PNP notification that cdrom
>signals when it detects a media change?
>
>-p
>
>
>-----Original Message-----
>From: John Hensley [mailto:xxxxx@msn.com]
>Sent: Thursday, April 10, 2003 7:12 AM
>To: NT Developers Interest List
>
>On Thu, 10 Apr 2003 10:28:06 +0100, “Lee Griffiths”
> wrote:
>
>>Hi guys,
>>
>>Anyone know of a way in a SCSI filter driver (which monitors all SCSI
>>requests to CD-ROM’s) to get notification when a disk has been
>inserted?
>>
>>Any help would be much appreciated.
>>
>>Lee Griff
>
>The only reliable way I’ve found to do this is to use a lower class
>filter driver that polls the device with a SCSIOP_TEST_UNIT_READY every
>couple of seconds.
>
>You will also need to handle any similar SCSI requests that are sent
>down by drivers above yours. If you fail to do this you will find that
>the upper drivers will be eating the sense data that you need and you
>will be eating the sense data that they need.
>
>An example of polling a CDROM device with an IoTimer routine is
>available in the CDROM class driver DDK sample. Look at the code that
>supports media change notification.
>
>…John
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@microsoft.com To
>unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>