How to avoid the "Unsafe Removal" dialog box

Article translations Article translations
Article ID: 298504 - View products that this article applies to.
This article was previously published under Q298504
Expand all | Collapse all

SUMMARY

This article describes how a function or a filter driver for a device can report if the device can tolerate surprise removal. Even if the bus driver indicates that the device can tolerate surprise removal, NDIS always clears the SurpriseRemoval field.

MORE INFORMATION

In Microsoft Windows 2000, you can avoid the Unsafe Removal dialog box. To do this, stop the device by selecting clicking Unplug/Eject icon in the task bar notification area. Then, unplug the hardware. However, if you have a device that can be surprise-removed, this process is unnecessary. Instead, drivers for hot plug-in/unplug devices that do not maintain a persistent state should inform the operating systems that they can tolerate a 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_QUERY_CAPABILITIES IRP before the drivers pass the IRP to the lower drivers in the device stack. Because the Windows 2000 USB hub driver incorrectly resets this field to FALSE, Windows 2000 drivers for USB devices must set the SurpriseRemovalOK field on the way up. This behavior is demonstrated in the following code example. This code example is adapted for the toaster function driver sample in the DDK (Src\General\Toaster\Func\Toaster.c).
    case IRP_MN_QUERY_CAPABILITIES: {
        // 
        // Set the SurpiseremovalOK capability to true because this device
        // can safely tolerate surprise remove, and we want to avoid the unsafe device
        // removal UI
        // 

        stack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK = TRUE;

        if (!IoIsWdmVersionAvailable(1, 0x20) /* & this is a for USB device */) {		
            // 
            // Reset the SurpriseRemovalOK capability 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 capability to FALSE
            // 
            // NOTE: IoIsWdmVersionAvailable(1, 0x20) returns TRUE on o/s after 
            // Windows 2000 & Windows Millennium Edition
            // 
 
            // 
            // This function defined in toaster.c basically sends the Irp to the lower 
            // driver and waits for it complete.
            // 
            status = ToasterSendIrpSynchronously(fdoData->NextLowerDriver, Irp);
            if (NT_SUCCESS (status)) {

                stack->Parameters.DeviceCapabilities.Capabilities->SurpriseRemovalOK=TRUE;
            }
        } else {

            // 
            // WDM version is 2.0 or newer (or this is not a USB driver)
            // so assume the bus driver will not erroneously reset the SurpiseRemovalOK
            // capability and just pass the IRP down
            // 

            IoSkipCurrentIrpStackLocation (Irp);
            status = IoCallDriver (fdoData->NextLowerDriver, Irp);
            ToasterIoDecrement(fdoData); //this function is defined in toaster.c
            return status;
        }
    }
    break;
				
Additionally, some devices that do not use persistent storage are not as safe to surprise remove. For example, you may surprise remove a PCMCIA card. Sometimes, hardware limitations may cause this removal to cause the PCI bus to fail. Therefore, the PCMCIA bus driver sets the SurpiseRemovalOK field to FALSE for all PCMCIA cards.

NDIS miniport drivers cannot avoid the surprise removal dialog box by using the code example in this section because the following conditions are true:
  • All the PnP IRPs are handled by the NDIS driver.
  • Even if the bus driver shows that the device can tolerate surprise removal, NDIS always clears the SurpriseRemoval field.
Currently, there is no other documented interface to work around this problem.

Properties

Article ID: 298504 - Last Review: August 22, 2005 - Revision: 4.1
APPLIES TO
  • Microsoft Win32 Device Driver Kit for Windows 2000
  • Microsoft Windows XP Driver Development Kit
  • Microsoft Windows Server 2003 Driver Development Kit
  • Microsoft Windows 2000 Professional Edition
  • Microsoft Windows XP Professional
  • Microsoft Windows Server 2003 Service Pack 1
Keywords: 
kbhowto kbkmode kbndis kbusb kbwdm KB298504

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com