No IRP_MN_REMOVE_DEVICE (NTFS only)

All:

We have a PCMCIA driver for CF cards that has run under Windows 2000 (yeah, ancient indeed). We never had an issue before, but we have always just used FAT. Now we need to support NTFS as cards are now getting larger than 32 GB.

The issue that we run into with NTFS formatted cards and our driver is that we only receive an IRP_MN_SURPRISE_REMOVAL. We never receive an IRP_MN_REMOVE_DEVICE. In fact, after we pass the IRP_MN_SURPRISE_REMOVAL, we never receive any other notifications whatsoever. With FAT formatted cards, we receive IRP_MN_SURPRISE_REMOVAL followed by IRP_MN_REMOVE_DEVICE.

Is there additional handling that we should be doing in our IRP_MN_SURPRISE_REMOVAL handler? (Code snippet below)

Thanks in advance for any suggestions that can be offered.

// #
// # The procedure to respond to IRP_MN_SURPRISE_REMOVAL
// #
#pragma PAGEDCODE
NTSTATUS OnPnp_SurpriseRemoval(PDEVICE_OBJECT pdo, PIRP pIrp)
{
PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION)pdo->DeviceExtension; NTSTATUS status = STATUS_SUCCESS;

// DEBUG
DebugOutput((DRIVERNAME " - OnPnp (IRP_MN_SURPRISE_REMOVAL)\n"));

// Set flag
pIrp->IoStatus.Status = STATUS_SUCCESS;

// Skip handling
IoSkipCurrentIrpStackLocation(pIrp);

// Pass down
status = IoCallDriver(pdx->pdoChild, pIrp);
if (!NT_SUCCESS(status))
{
// Error - Output if error is other than STATUS_NOT_SUPPORTED
if (status != STATUS_NOT_SUPPORTED)
{
DebugOutput((DRIVERNAME " - ERROR: IoCallDriver failed [0x%08X]\n", status));
}
}

// Return
return status;
}

Is your driver an FDO? Do you enumerate any PDO? How do you handle DEVICE_RELATIONS/TargetReLations? Are you a storage port?

Alex:

Thanks for the follow up. The device is not a FDO and it does not create any PDOs. It simply issues IoRegisterDeviceInterface(…MOUNTDEV_MOUNTED_DEVICE_GUID…) and handles support directly. All device relations are default Pnp handler per Oney.

In the time since posting, I have tried EJECT in various forms and IoSetDeviceInterface(…FALSE), in IRP_MN_SURPRISE_REMOVAL handler, but whatever is holding access to the NTFS formatted drive is not letting go after the handler exit.

Any additional guidance would be most appreciated.

What O/S are you having the problem on? Do you have outstanding threads that
look similar to the ones posted in this thread:

http://ww.osronline.com/showthread.cfm?link=208667

There was/is an issue related to the KTM keeping a dangling reference on
particular NTFS volumes, which potentially sounds related. It might be worth
seeing if you can reproduce this issue on Win8.

-scott
OSR

wrote in message news:xxxxx@ntdev…

Alex:

Thanks for the follow up. The device is not a FDO and it does not create any
PDOs. It simply issues
IoRegisterDeviceInterface(…MOUNTDEV_MOUNTED_DEVICE_GUID…) and handles
support directly. All device relations are default Pnp handler per Oney.

In the time since posting, I have tried EJECT in various forms and
IoSetDeviceInterface(…FALSE), in IRP_MN_SURPRISE_REMOVAL handler, but
whatever is holding access to the NTFS formatted drive is not letting go
after the handler exit.

Any additional guidance would be most appreciated.

Scott:

This is a Windows 2000 (SP4) system. The issue has similar behavior to the attached thread, but other storage drivers on this same platform don’t have the issue (or they know the work around).

I will try XP to see if the issue reproduces, but PCMCIA and Win8 aren’t likely to overlap…

Thanks

Where your driver is in the device stack? Do you hold any pending IO requests, like media notifications?

Alex:

We are a monolithic driver supporting a PCMCIA drive (CF card). We don’t seem to be holding any requests at all.

Following up on the above, this issue does reproduce on XP for NTFS formatted drives only. FAT formatted drives continue to receive both IRP_MN_SURPRISE_REMOVAL and IRP_MN_SURPRISE_REMOVAL events.

What DeviceType do you set in the device object?

Hmmmm…

So… when you try to do an orderly removal (using the little tool tray applet) you don’t get Query Remove and you don’t get Remove. Just Surprise Remove?

THAT’s strange. There’s something about NTFS not supporting removable media, but supporting removable devices. Which one are you?

Peter
OSR