Clearing the DO_DEVICE_INITIALIZING Flag

Note

For optimal reliability and performance, use file system minifilter drivers with Filter Manager support instead of legacy file system filter drivers. To port your legacy driver to a minifilter driver, see Guidelines for Porting Legacy Filter Drivers.

After attaching a legacy filter device object to a file system or volume, always be sure to clear the DO_DEVICE_INITIALIZING flag on the filter device object. (For more information about this flag, see DEVICE_OBJECT in the Kernel Reference.) The following example shows how to use the ClearFlag macro defined in ntifs.h to do so:

ClearFlag(NewDeviceObject->Flags, DO_DEVICE_INITIALIZING);

When the filter device object is created, IoCreateDevice sets the DO_DEVICE_INITIALIZING flag on the device object. After the filter is successfully attached, this flag must be cleared. If this flag isn't cleared, no more filter drivers can attach to the filter chain because the call to IoAttachDeviceToDeviceStackSafe will fail.

It isn't necessary to clear the DO_DEVICE_INITIALIZING flag on device objects that are created in DriverEntry, because the I/O Manager automatically clears it. However, your driver should clear this flag on all other device objects that it creates.