Loading and Unloading a File System

Block device drivers need to perform certain tasks to work correctly with Windows CE file systems. When the driver receives DISK_IOCTL_INITIALIZED in its DSK_IOControl function, it also receives a pointer to a POST_INIT_BUF structure. This structure lists the driver’s registry key, which the driver can use to retrieve the name of a file system driver. The driver must pass that name and a device-specific handle also present in the structure to the LoadFSD function. The Device Manager then loads the correct file system driver. The file system driver name should never be hard-coded into a block device driver; it should always be retrieved from the registry. Hard coding the file system driver name means that your block device driver could stop working if later versions of Windows CE use different names for their file system drivers.

The block device driver should be prepared to accept I/O control requests as soon as it calls LoadFSD, even if LoadFSD has not yet returned. Because of the way the Device Manager implements LoadFSD, it is possible for the file system driver to be loaded and to issue a request to your block device driver before LoadFSD actually returns. It is also possible for LoadFSD to return successfully, even if there are subsequent errors initializing the file system driver. Presently, there are no mechanisms that the block device driver can use to detect such errors.

Windows CE versions 2.12 and earlier do not support multiple file system drivers acting on the same block device. If a Windows CE–based system has multiple file system drivers installed, the block device driver must determine which one to load during its processing of DISK_IOCTL_INITIALIZED. A block device driver can make only one successful call to LoadFSD; calling LoadFSD more than once causes unpredictable behavior.

The Device Manager unloads file system drivers at the time that a block device’s driver is deregistered by the DeregisterDevice function. Once the file system driver is loaded, the block device driver cannot force it to unload or unmount the block device from the system’s directory structure.

Because file systems are frequently unloaded just prior to system shutdown, block device drivers must ensure that all write operations to the block device are fully complete before the driver’s DSK_IOControl function returns. Failure to do so can cause corruption of files or directories.