Avoiding 'Unsafe Removal of Device' Dialog on Win2K

Hi,
I’ve solved my previous problem by modifying the inf files. And now my customer asks me to avoid the dialog of ‘Unsafe Removal of Device’ on Win2K when the user disconnects the USB device from the computer. I’ve searched some website and MSDN, but cannot get any ideas.
Does here anyone know how to do this?
Thanks

-Ray Yang
xxxxx@yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi:
just handle the IRP_MN_SURPRISE_REMOVAL of IRP_MJ_PNP, go to reference the docs in ddk for the details.

----- Original Message -----
From: “Ray Yang”
To: “NT Developers Interest List”
Sent: Thursday, April 19, 2001 8:19 AM
Subject: [ntdev] Avoiding ‘Unsafe Removal of Device’ Dialog on Win2K

> Hi,
> I’ve solved my previous problem by modifying the inf files. And now my customer asks me to avoid the dialog of ‘Unsafe Removal of Device’ on Win2K when the user disconnects the USB device from the computer. I’ve searched some website and MSDN, but cannot get any ideas.
> Does here anyone know how to do this?
> Thanks
>
>
> -Ray Yang
> xxxxx@yahoo.com
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@bhnec.nec.co.jp
> To unsubscribe send a blank email to xxxxx@lists.osr.com
???y˫???+.n?+???u?ڲ˛??^r*D???kN???r??zǧu??jy???^j???ׯ??? 0?j?b??(??(

Ray,

I think when your respond to IRP_MN_QUERY_CAPABILITIES you return the
DEVICE_CAPABILITIES structure. These settings should do what you want.

SurpriseRemovalOK

Specifies whether the system should display a pop-up window if a user
removes the device from the machine without first going through the Unplug
or Eject Hardware applet (a “surprise-style” removal).

Removable

Specifies whether the device can be dynamically removed from the system. If
TRUE, the device is displayed in the Unplug or Eject Hardware applet, unless
SurpriseRemovalOK is also set to TRUE.

Marc Reinig
System Solutions

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Ray Yang
Sent: Wednesday, April 18, 2001 5:20 PM
To: NT Developers Interest List
Subject: [ntdev] Avoiding ‘Unsafe Removal of Device’ Dialog on Win2K

Hi,
I’ve solved my previous problem by modifying the inf files. And now my
customer asks me to avoid the dialog of ‘Unsafe Removal of Device’ on Win2K
when the user disconnects the USB device from the computer. I’ve searched
some website and MSDN, but cannot get any ideas.
Does here anyone know how to do this?
Thanks

-Ray Yang
xxxxx@yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

you can do this by handling the PDEVICE_CAPABILITIES structure flags in the
QueryCapabilities Function then modify the following
DevCap->SurpriseRemovalOK=TRUE;
DevCap->Removable=TRUE;
DevCap->EjectSupported=TRUE;
DevCap->WarmEjectSupported=TRUE;
I tried and it works fine
Hesham
----- Original Message -----
From: “Ray Yang”
To: “NT Developers Interest List”
Sent: Thursday, April 19, 2001 2:19 AM
Subject: [ntdev] Avoiding ‘Unsafe Removal of Device’ Dialog on Win2K

> Hi,
> I’ve solved my previous problem by modifying the inf files. And now my
customer asks me to avoid the dialog of ‘Unsafe Removal of Device’ on Win2K
when the user disconnects the USB device from the computer. I’ve searched
some website and MSDN, but cannot get any ideas.
> Does here anyone know how to do this?
> Thanks
>
>
> -Ray Yang
> xxxxx@yahoo.com
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@yahoo.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

_________________________________________________________

Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

There was an article in the last month’s hardware newsletter on
“Creating a Better End-User Experience: Avoiding the Unsafe Removal
Dialog”. Here are the excerpts from the article:

In Windows 2000 if a device driver does not explicitly tell the
operating system that it can tolerate surprise removal, the operating
system displays the following notifications:
* Unplug/Eject icon in the taskbar tray
* Unsafe Removal dialog when a bus driver reports surprise removal
of a device

In Windows Whistler if a device driver does not explicitly tell the
operating system that it can tolerate surprise removal the operating
system:
* Displays the Unplug/Eject icon in the taskbar tray
* Does not display the Unsafe Removal dialog when a bus driver
reports the surprise removal of a device

The Unsafe Removal dialog is not displayed in Windows Whistler because
testing has shown that this popup does not impact user behavior. That
is, it does not prevent end users from surprise removing hardware. End
user input has suggested that the Unsafe Removal dialog detracts from
the user experience. However, Windows Whistler preserves the
Unplug/Eject icon in the task tray so users can still access the applet
to stop devices before removal.

In Windows 2000, end users can avoid the Unsafe Removal dialog by first
stopping the device by selecting the Unplug/Eject icon in the taskbar
tray, and then unplugging the hardware. However, when the user has a
device that can be safely surprised removed, making the user go through
this process is an unnecessary burden. Instead, drivers for USB or IEEE
1394 devices that don’t maintain a persistent state should inform the
operating systems that they are able to safely tolerate a surprise
removal.
In Windows Whistler, although the Unsafe Removal dialog is not presented
upon surprise removal of hardware, it is still important to inform the
operating system that a device is able to safely tolerate a surprise
remove in appropriate cases. Conveying this information prevents the
operating system from unnecessarily displaying the Unplug/Eject icon in
the taskbar. Any reduction in the number of icons in the taskbar
improves the end user experience.

Device drivers indicate their ability to tolerate surprise removal by
setting the SurpriseRemovalOK field in the DeviceCapabilities structure
to TRUE in response to the IRP_MN_QUERY_CAPABILITIES Plug and Play IRP.
According to the Plug and Play rule, drivers should set the
SurpriseRemovalOK field in the IRP_MN_QURERY_CAPABILITIES IRP before
passing the IRP to the lower drivers in the devnode. Because the Windows
2000 USB hub driver erroneously resets this field to FALSE, Windows 2000
drivers for USB devices must set the SurpriseRemovalOK field on the way
up, as demonstrated in the sample code in this paper. Drivers for
non-USB devices or drivers that will only run under Windows Whistler
should set the SurpriseRemovalOK field on the way down.
//
// Sample code taken from PnP Dispatch Routine
//
case IRP_MN_QUERY_CAPABILITIES:
{
PIO_STACK_LOCATION IrpSp;

//
// Set the SurpiseremovalOK capability to true becase this device
// can safely tolerate suprise remove, and we want to avoid the unsafe
device
// removal UI
//

IrpSp = IoGetCurrentIrpStackLocation(Irp);
IrpSp->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK =
TRUE;

if (!IoIsWdmVersionAvailable(1, 0x20) /* & this is a for USB device
*/) {
//
// Reset the SurpriseRemovalOK capabilty back to TRUE when the IRP
is on
// the way back up to work around a bug in Windows 2000 USB hub
driver that
// incorrectly sets this capabilty to FALSE
//
// NOTE: IoIsWdmVersionAvailable(1, 0x20) returns TRUE on o/s after
// Windows 2000 & Windows Millennium Edition
//

KEVENT QueryCapabilitiesEvent;
KeInitializeEvent(&QueryCapabilitiesEvent,
SynchronizationEvent,
FALSE);

IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp,
SIdriverDispatchPnpComplete,
&QueryCapabilitiesEvent,
TRUE,
TRUE,
TRUE);

status = IoCallDriver(fdoData->NextLowerDriver, Irp);

if (status == STATUS_PENDING) {
KeWaitForSingleObject(&QueryCapabilitiesEvent,
Executive,
KernelMode,
FALSE,
NULL);
status = Irp->IoStatus.Status;
}
IrpSp = IoGetCurrentIrpStackLocation(Irp);

IrpSp->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK=TRU
E;
Irp->IoStatus.Status = status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);

} else {
//
// WDM version is 2.0 or newer (or this is not a USB driver)
// so assume the bus driver will not erronously reset the
SurpiseRemovalOK
// capapbility and just pass the IRP down
//
IoSkipCurrentIrpStackLocation (Irp);
status = IoCallDriver (fdoData->NextLowerDriver, Irp);
}

SIdriverIoDecrement(fdoData);
return status;
break;
}
//
// PnP Dipatch Routine continues…
//

NTSTATUS
SIdriverDispatchPnpComplete (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)
/*++

Routine Description:
The lower-level drivers completed the pnp IRP.
Signal this to whoever registered us.

Arguments:
DeviceObject - pointer to a device object.
Irp - pointer to an I/O Request Packet.
Context - pointer to the event to be signaled.
Return Value:
NT status code
–*/
{
PKEVENT event = (PKEVENT)Context;
UNREFERENCED_PARAMETER (DeviceObject);

//
// Wait for lower drivers to be done with the IRP.
// Important thing to note here is when you allocate
// the memory for an event in the stack you must do a
// KernelMode wait instead of UserMode to prevent
// the stack from getting paged out.
//

KeSetEvent (event, IO_NO_INCREMENT, FALSE);

//
// Take the IRP back so that we can continue using it during
// the dispatch routine.
// NB: The dispatch routine will have to call IoCompleteRequest
//
return STATUS_MORE_PROCESSING_REQUIRED;
}

Additionally, there are cases where devices that don’t use persistent
storage are not as safe to surprise remove. An example of this would be
surprise removing a PCMCIA card; in rare cases hardware limitations
could cause this removal to crash the PCI bus. For this reason, the
PCMCIA bus driver sets the SurpiseRemovalOK field to FALSE for all
PCMCIA cards.
Recall that all Plug and Play drivers need to support the
IRP_MN_SURPISE_REMOVAL Plug and Play IRP, regardless of the
SupriseRemovalOK setting. Even PCI devices can tolerate surprise removal
if they are included in a docking station. Drivers for all PCI devices
included in a docking station will receive an IRP_MN_SURPRISE_REMOVAL
IRP if the mobile PC is undocked while the operating system is running.

Please consult the Windows 2000 DDK documentation and the toaster
function driver in the toaster sample package in the Windows 2000 DDK
for details regarding the correct handling the IRP_MN_SURPRISE_REMOVAL
IRP.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I have a similar question, but my driver is a ndis driver that attach to wdm, so, my driver communite with the system via the ndis wrapper, and I can’t handle the IRP_MJ_PNP, so the question is ‘how to avoid it in a ndis driver?’
thx.
K.Y
----- Original Message -----
From: “Jan Bottorff”
To: “NT Developers Interest List”
Sent: Friday, April 20, 2001 4:50 AM
Subject: [ntdev] RE: Avoiding ‘Unsafe Removal of Device’ Dialog on Win2K

>
> >The Unsafe Removal dialog is not displayed in Windows Whistler because
> >testing has shown that this popup does not impact user behavior. That
> >is, it does not prevent end users from surprise removing hardware. End
> >user input has suggested that the Unsafe Removal dialog detracts from
> >the user experience.
>
> I’m not sure I totally agree with Microsoft’s thinking. Another way of
> wording this is “Because user’s find it annoying to be informed of data
> loss, we have stopped informing them”. From a behavioral economics
> viewpoint, perhaps you should cause a soft BSOD on unsafe device removal,
> my guess is user behavior would change very effectively.
>
> If there is no actual data loss when the device is removed, then the driver
> should inform the OS things are ok. In this case, perhaps the driver should
> also keep on responding to I/O requests, and return some sort of status
> saying the request was only simulated. For example, you unplug your USB
> camera. I could imagine the driver could keep returning the last frame
> captured, with a STATUS_SIMULATED result code.
>
> If there is real data loss, say somebody just unplugged a USB disk drive,
> while write activity was happening, a dialog that says “You better plug
> that device back in right now, and we’ll attempt to repair any damage that
> was done” might be best. It may not fit the marketing image of making “user
> friendly” computers, but it’s the reality of how things are. My experience
> is: delayed or squelched delivery of bad news is generally not such a good
> idea.
>
> To remove the surprise removal popup is like making your car soundproof, so
> you don’t have to listen to that annoying grinding sound when your brakes
> need replacing. It’s a more pleasant user experience, but it’s NOT in the
> user’s best interest to be shielded from information they should have.
>
> I suppose the meta question is: why does the idea of a BSOD on unsafe
> device removal get instantly discard by us developers. If our goal is to
> change the behavior of users, to protect them from themselves, this seems
> like a very effective strategy. The REAL engineering solution seems like:
> there should be a software controlled physical lock, so the device simple
> can’t be removed if it’s unsafe to do so. Cloths washing machines seemed to
> have us pretty well trained to not open the top when they are spinning,
> otherwise significant system shutdown occurs. Even cheap devices could have
> an indicator light that basically means unplug this device with the light
> on and expect your computer to BSOD. Users would learn real quick to
> logically shutdown the device before pulling it out.
>
> - Jan
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@bhnec.nec.co.jp
> To unsubscribe send a blank email to xxxxx@lists.osr.com
(???r??z{e?˛???m?m?{]z???&j)@u?Ӣ?칻?&ޱ??i?Z?G?j)m?W???u?칻-E?"?Ǧm??(Z?X???,??&

No MS recommended solution for your problem. There are other ways to
prevent it, but then WHQL doesn’t like it. So the best thing to do is do
nothing about this issue, IMHO.

-----Original Message-----
From: Kamasamikon [mailto:xxxxx@bhnec.nec.co.jp]
Sent: Thursday, April 19, 2001 6:05 PM
To: NT Developers Interest List
Subject: [ntdev] RE: Avoiding ‘Unsafe Removal of Device’ Dialog on Win2K

I have a similar question, but my driver is a ndis driver that attach to
wdm, so, my driver communite with the system via the ndis wrapper, and I
can’t handle the IRP_MJ_PNP, so the question is ‘how to avoid it in a
ndis driver?’
thx.
K.Y


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com