It could be you ARE successfully responding to cause an eject request. And the storage stacks says “sorry, files are open, so can’t eject right now”. LOTS of apps can’t respond to PnP eject requests on an open file, because they have not even registered to receive notification. When the file system is unable to convince apps to close their files on the mounted volume, the eject request is essentially canceled.
Also just look at the scenario of a memory mapped file, what as the graceful way to eject that. You can’t just make some range of addresses vanish or suddenly become read-only.
The media we most commonly think of with an eject button is a DVD drive, and the consequences of ejecting read-only media are different that the consequences of ejecting read-write media.
Keep in mind ejecting the media is different that the device going away. When you press the eject button on a DVD drive, the DVD drive does not go away.
You might trace the SCSI commands and see if you get a command to lock the media, which would mean an eject button does not work until an unlock is received.
Perhaps the correct question to ask is: how do people implement hot plug disks on Windows. Generally I think there is a user command initiated from the top before the disk is removed. Some hot plug disks have a physical lock controlled by the OS, so you can’t pull the disk unless it’s been properly unmounted. Removing a hot plug disk is the device going away, not just it’s media.
You might write/find a little test app that opens a file on a volume, registers for PnP notification on that file, and then you can see of you get notification when you issue eject requests from the driver. I’d bet there is a ETW trace you could enable to show what’s happening.
As I remember, a few years ago when I tried to get storage devices to gracefully eject from the driver, I gave up and concluded ungraceful removal was the only thing that worked reliably. Having something that sometimes maybe would gracefully eject was not very useful.
Jan
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Dan Greenfield
Sent: Sunday, January 27, 2013 11:43 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Virtual Storport: ejecting media? (safely)
Thanks Mark, as I just replied to Maxim now, I’m trying to simulate a fake eject button being pressed by the user on the device. SCSI does support ejectable media buttons in this manner (see point 2 for the Sense parameters that should be set). What I’m having trouble with is getting Windows to issue a SCSIOP REQUEST_SENSE despite setting the SCSISTAT_CHECK_CONDITION. Do you have any ideas on how to get one triggered?
On 27/01/2013, at 6:50 PM, Mark Roddy wrote:
Ah, so yes you cannot ‘eject’ from the driver as eject starts from user mode. What you can do is initiate surprise removal. If you have correctly marked the media as removable then the FS above you will make sure that the volume is kept consistent even if the media disappears underneath it.
Just convince pnp to reenumerate the bus and don’t provide inquiry data for this lun.
Mark Roddy
On Fri, Jan 25, 2013 at 3:34 PM, Dan Greenfield > wrote:
Thank you Mark. That is indeed what I do, I set the per LUN removable media flags as such - and eject works fine when ejecting directly from the Windows GUI. It’s just that I can’t seem to initiate an eject from the driver itself.
On 25/01/2013, at 8:09 PM, Mark Roddy wrote:
I think you have to declare the media as removable from the moment it arrives, rather than deciding that it needs to become removable after it has been made visible to the system.
Mark Roddy
On Fri, Jan 25, 2013 at 2:36 PM, > wrote:
I’ve been writing a Virtual Storport miniport driver and I want to ensure that any mounted volumes have been properly flushed before disconnecting the virtual disk. I figured that mimicing an ‘eject button’ for removable media would be the way to go - telling Windows to flush it out and then handling the correponding SCSIOP_MEDIUM_REMOVAL and SCSIOP_START_STOP_UNIT operations. Indeed when I eject using the Windows GUI - this works fine.
However, I am trying to get the miniport driver itself to tell Windows that an ‘eject’ button was pressed, and for that I get the following behaviour:
1. Despite setting the ScsiStatus to SCSISTAT_CHECK_CONDITION in SRB responses, there are no SCSIOP_REQUEST_SENSE queries received by the driver - in fact I never see these queries occur at any time throughout driver usage… this seems really strange to me as I thought these are ordinarily triggered…
( Does anyone know how I can trigger a SCSIOP REQUEST_SENSE? )
2. Regardless, I’ve also tried setting the SrbStatus to have SRB_STATUS_AUTOSENSE_VALID and set the sense as:
SenseKey = SCSI_SENSE_UNIT_ATTENTION
AdditionalSenseCode = SCSI_ADSENSE_OPERATOR_REQUEST
AdditionalSenseCodeQualifier = SCSI_SENSEQ_MEDIUM_REMOVAL
AdditionalSenseLength = 14; // no additional length beyond main fields
I figure this might not be working because it is not a response to a SCSIOP_REQUEST_SENSE - but to other operations instead?
Am I missing something? What could I be doing wrong? Or is there another way to safely flush data from the driver before disconnecting it?
Any help would be appreciated.
Thanks,
Dan
—
NTDEV is sponsored by OSR
OSR is HIRING!! See http://www.osr.com/careers
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
— NTDEV is sponsored by OSR OSR is HIRING!! See http://www.osr.com/careers For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
—
NTDEV is sponsored by OSR
OSR is HIRING!! See http://www.osr.com/careers
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
— NTDEV is sponsored by OSR OSR is HIRING!! See http://www.osr.com/careers For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
—
NTDEV is sponsored by OSR
OSR is HIRING!! See http://www.osr.com/careers
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer