File System Driver Creation
File System Driver Creation
A file system driver (FSD) is a dynamic-link library (DLL) that exports file system entry points that map to standard Microsoft® Windows® 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, the FSD Manager maps the call to the FSD. The FSD Manager manages all system interactions with installable FSDs.
The operating system (OS) provides a template for functions that you need to develop for a file system. 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 if you do not want that function to be available. For example, to prevent applications from creating or destroying directories inside volumes belonging to your FSD, do not include CreateDirectory and RemoveDirectory in your FSD. The FSD Manager automatically supplies stub functions for any functions that you choose not to supply for your file system. These stub functions return ERROR_NOT_SUPPORTED. As a result, if an application tries to create or remove a directory on a volume that belongs to your FSD, the call fails.
In addition to exporting entry points for the file system functions, an FSD must export entry points for the FSD_MountDisk and FSD_UnmountDisk functions. The Device Manager calls FSD_MountDisk when a target 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 the FSD Manager services that query, read, and write to that disk.
To create an FSD for a hypothetical file system named MyFSD, you must create a DLL named MyFSD.dll. This DLL contains the data type definitions, header files, and functions for MyFSD.
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 that you need. For example, you can redefine them as pointers to customized structures. You must redefine these types before including Fsdmgr.h or the default definitions will be used.
The code that compiles into MyFSD.dll must include Fsdmgr.h. This header file generates the prototypes for all of the 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 MyFSD.dll.
Copy
// This defines a type that is a pointer to a structure containing
// two DWORDs.
typedef struct {
DWORD first_field;
DWORD second_field;
} TWODWORDS, *PTWODWORDS;
// In this example, only PSEARCH is redefined.
// 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
// Now define the name of the file system.
#define FSDAPI MyFSD
#include
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. MyFSD.dll must generate prototypes for all FSD Manager services that your FSD needs.
MyFSD.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, which is MyFSD_ in this example. 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.
Copy
LIBRARY MyFSD
DESCRIPTION 'My File System for Windows 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 hypothetical 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 not provide a function in your FSD. For any missing functions, FSD Manager automatically provides stub functions that return ERROR_NOT_SUPPORTED.