Tech Support > Microsoft Windows > Drivers > question from sfilter
question from sfilter
Posted by Min Wang on February 24th, 2005


Hi all,

Suppose I have two file system filters(mostly copied from sfilter): A and B.
A calls IoRegisterFsRegistrationChange before B does. As a result, when a
file system driver C calls IoRegisterFileSystem, B will be notified before
A. Therefore, B will attach to C and A will attach to B.

C<-B<-A

When C calls IoUnregisterFileSystem, B will still be notified before A. B
will call SfDetachFromFileSystemDevice, the same as sfilter does:

VOID SfDetachFromFileSystemDevice(IN PDEVICE_OBJECT DeviceObject)
{
PDEVICE_OBJECT ourAttachedDevice = DeviceObject->AttachedDevice;

while (NULL != ourAttachedDevice) {

if (IS_MY_DEVICE_OBJECT( ourAttachedDevice ))
{
IoDetachDevice( DeviceObject );
IoDeleteDevice( ourAttachedDevice );
return;
}

DeviceObject = ourAttachedDevice;
ourAttachedDevice = ourAttachedDevice->AttachedDevice;
}
}

The problem is, when B calls IoDetachDevice and IoDeleteDevice, it's still
attached by A. So when A get the notification, DeviceObject->AttachedDevice
will be empty and A's filter device object will never have a chance to get
deleted.

Is there anything wrong in my understanding?

Thanks