File System Driver Creation (Windows Embedded CE 6.0)

1/6/2010

A file system driver (FSD) is a DLL that exports file system entry points that map to standard Windows Embedded CE file system functions, such as CreateFile and CreateDirectory. When an application calls a file system function, and the function references a file on a volume registered by the FSD, FSD Manager maps the call to the FSD. FSD Manager manages all system interactions with installable FSDs.

Typically, an FSD exports a full range of functions, but you can also choose to not export an entry point for a particular file system function. For example, to prevent applications from creating or destroying directories in volumes belonging to your FSD, you might not include CreateDirectory and RemoveDirectory. The file system returns ERROR_NOT_SUPPORTED for any functions that you choose not to implement for your file system.

In addition to exporting entry points for file system functions, an FSD must export entry points for the FSD_MountDisk and FSD_UnmountDisk functions. Device Manager calls FSD_MountDisk when a device for which that FSD has been registered is inserted or removed. The FSD_MountDisk and FSD_UnmountDisk entry points are each passed a DWORD that uniquely identifies the disk being mounted. These DWORD types are passed back to FSD Manager services that query, read, and write to that disk.

To create an FSD for a file system, create a DLL with the name of the FSD. This DLL must contain the data type definitions, header files, and functions for the FSD. For example, to create an FSD for the file system MyFSD, create a DLL named MyFSD.dll.

You can define the PVOLUME, PFILE, and PSEARCH data types in MyFSD.dll. Use these types to declare variables and function parameters that hold information about the mounted volume, the file, and the search handle, respectively. These data types are used throughout the FSD functions and by default, are all DWORD types. You can redefine these data types to contain any information. For example, you can redefine them as pointers to customized structures. You must redefine these types before including Fsdmgr.h, or the default definitions is used.

The code that compiles into the DLL for the FSD must include Fsdmgr.h. This header file generates the prototypes for all functions that you write for your file system. If you want to define the PVOLUME, PFILE, and PSEARCH data types, do so before including Fsdmgr.h. You must also define a constant, FSDAPI, which is the name of your file system.

The following code example shows how to include the header file Fsdmgr.h in a DLL that defines an FSD:

//Defines a type that is a pointer to a structure named TWOWORDS that contains two DWORDs.
typedef struct
{
   DWORD first_field;
   DWORD second_field;
}
TWODWORDS, *PTWODWORDS;
//Re-defines the PSEARCH datatype. PFILE and PVOLUME will default to being defined as DWORDs. You can define these types to be different types or the same type, based on your FSD needs.
#define PSEARCH PTWODWORDS
//Defines the name of the file system as MyFSD.
#define FSDAPI   MyFSD
#include <fsdmgr.h>

The file system name, the prefix for all functions, and the name of the resulting DLL are all defined by the name that you specify for FSDAPI. The FSD DLL must also generate prototypes for all FSD Manager services that your FSD needs.

The FSD DLL must export entry points for all file system functions that you want to export. For each of these file system functions, the function name must be preceded by the name of your FSD. For example, if the name of your FSD is MyFSD, function names must be preceded by MyFSD_, such as MyFSD_CreateFile.

You must also implement the MyFSD_MountDisk and MyFSD_UnmountDisk functions in MyFSD.dll. These functions are exported using the generic names FSD_MountDisk and FSD_UnmountDisk. FSD Manager uses these functions to identify MyFSD.dll as a legitimate FSD.

The following code example shows how to export functions for MyFSD.dll in a module definition (.def) file:

LIBRARY MyFSD
DESCRIPTION 'My File System for Windows Embedded CE'
EXPORTS
   MyFSD_MountDisk
   MyFSD_UnmountDisk
   FSD_MountDisk=MyFSD_MountDisk
   FSD_UnmountDisk=MyFSD_UnmountDisk
   MyFSD_CreateDirectoryW
   MyFSD_RemoveDirectoryW
   MyFSD_GetFileAttributesW
   MyFSD_SetFileAttributesW
   MyFSD_DeleteFileW
   MyFSD_MoveFileW
   MyFSD_DeleteAndRenameFileW
   MyFSD_GetDiskFreeSpaceW
   MyFSD_Notify
   MyFSD_RegisterFileSystemFunction
   MyFSD_FindFirstFileW
   MyFSD_FindNextFileW
   MyFSD_FindClose
   MyFSD_CreateFileW
   MyFSD_ReadFile
   MyFSD_ReadFileWithSeek
   MyFSD_WriteFile
   MyFSD_WriteFileWithSeek
   MyFSD_SetFilePointer
   MyFSD_GetFileSize
   MyFSD_GetFileInformationByHandle
   MyFSD_FlushFileBuffers
   MyFSD_GetFileTime
   MyFSD_SetFileTime
   MyFSD_SetEndOfFile
   MyFSD_DeviceIOControl
   MyFSD_CloseFile
   MyFSD_CloseVolume

The MyFSD file system implements the full set of functions for working with a file system. You must supply the functions necessary for your file system. However, as previously mentioned, you can choose to omit a function in your FSD. For any missing functions, FSD Manager automatically provides stub functions that return ERROR_NOT_SUPPORTED.

See Also

Reference

FSD Reference

Concepts

Installable File System Drivers

Other Resources

Device Manager