doc/WinFsp-API-winfsp.h.md
WinFsp User Mode API.
In order to use the WinFsp API the user mode file system must include <winfsp/winfsp.h> and link with the winfsp_x64.dll (or winfsp_x86.dll) library.
A user mode file system is a program that uses the WinFsp API to expose a file system to Windows. The user mode file system must implement the operations in FSP_FILE_SYSTEM_INTERFACE, create a file system object using FspFileSystemCreate and start its dispatcher using FspFileSystemStartDispatcher. At that point it will start receiving file system requests on the FSP_FILE_SYSTEM_INTERFACE operations.
Discussion
The operations in this interface must be implemented by the user mode file system. Not all operations need be implemented. For example, a user mode file system that does not wish to support reparse points, need not implement the reparse point operations.
Most of the operations accept a FileContext parameter. This parameter has different meanings depending on the value of the FSP_FSCTL_VOLUME_PARAMS flags UmFileContextIsUserContext2 and UmFileContextIsFullContext.
There are three cases to consider:
When both of these flags are unset (default), the FileContext parameter represents the file node. The file node is a void pointer (or an integer that can fit in a pointer) that is used to uniquely identify an open file. Opening the same file name should always yield the same file node value for as long as the file with that name remains open anywhere in the system.
When the UmFileContextIsUserContext2 is set, the FileContext parameter represents the file descriptor. The file descriptor is a void pointer (or an integer that can fit in a pointer) that is used to identify an open instance of a file. Opening the same file name may yield a different file descriptor.
When the UmFileContextIsFullContext is set, the FileContext parameter is a pointer to a FSP_FSCTL_TRANSACT_FULL_CONTEXT. This allows a user mode file system to access the low-level UserContext and UserContext2 values. The UserContext is used to store the file node and the UserContext2 is used to store the file descriptor for an open file.
NTSTATUS ( *CanDelete)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PWSTR FileName);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This function tests whether a file or directory can be safely deleted. This function does not need to perform access checks, but may performs tasks such as check for empty directories, etc.
This function should NEVER delete the file or directory in question. Deletion should happen during Cleanup with the FspCleanupDelete flag set.
This function gets called when Win32 API's such as DeleteFile or RemoveDirectory are used. It does not get called when a file or directory is opened with FILE_DELETE_ON_CLOSE.
NOTE: If both CanDelete and SetDelete are defined, SetDelete takes precedence. However most file systems need only implement the CanDelete operation.
See Also
VOID ( *Cleanup)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PWSTR FileName,
ULONG Flags);
Parameters
Discussion
When CreateFile is used to open or create a file the kernel creates a kernel mode file object (type FILE_OBJECT) and a handle for it, which it returns to user-mode. The handle may be duplicated (using DuplicateHandle), but all duplicate handles always refer to the same file object. When all handles for a particular file object get closed (using CloseHandle) the system sends a Cleanup request to the file system.
There will be a Cleanup operation for every Create or Open operation posted to the user mode file system. However the Cleanup operation is not the final close operation on a file. The file system must be ready to receive additional operations until close time. This is true even when the file is being deleted!
The Flags parameter contains information about the cleanup operation:
If the file system supports POSIX unlink (FSP_FSCTL_VOLUME_PARAMS :: SupportsPosixUnlinkRename), then a Cleanup / FspCleanupDelete operation may arrive while there are other open file handles for this particular file node. If the file system does not support POSIX unlink, then a Cleanup / FspCleanupDelete operation will always be the last outstanding cleanup for this particular file node.
FspCleanupSetAllocationSize - The NTFS and FAT file systems reset a file's allocation size when they receive the last outstanding cleanup for a particular file node. User mode file systems that implement allocation size and wish to duplicate the NTFS and FAT behavior can use this flag.
FspCleanupSetArchiveBit - File systems that support the archive bit should set the file node's archive bit when this flag is set.
FspCleanupSetLastAccessTime, FspCleanupSetLastWriteTime, FspCleanupSetChangeTime - File systems should set the corresponding file time when each one of these flags is set. Note that updating the last access time is expensive and a file system may choose to not implement it.
There is no way to report failure of this operation. This is a Windows limitation.
As an optimization a file system may specify the FSP_FSCTL_VOLUME_PARAMS :: PostCleanupWhenModifiedOnly flag. In this case the FSD will only post Cleanup requests when the file was modified/deleted.
See Also
VOID ( *Close)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext);
Parameters
NTSTATUS ( *Control)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
UINT32 ControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength,
PULONG PBytesTransferred);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This function is called when a program uses the DeviceIoControl API.
</blockquote> </details> <details> <summary> <b>Create</b> - Create new file or directory. </summary> <blockquote>NTSTATUS ( *Create)(
FSP_FILE_SYSTEM *FileSystem,
PWSTR FileName,
UINT32 CreateOptions,
UINT32 GrantedAccess,
UINT32 FileAttributes,
PSECURITY_DESCRIPTOR SecurityDescriptor,
UINT64 AllocationSize,
PVOID *PFileContext,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>CreateEx</b> - Create new file or directory. </summary> <blockquote>NTSTATUS ( *CreateEx)(
FSP_FILE_SYSTEM *FileSystem,
PWSTR FileName,
UINT32 CreateOptions,
UINT32 GrantedAccess,
UINT32 FileAttributes,
PSECURITY_DESCRIPTOR SecurityDescriptor,
UINT64 AllocationSize,
PVOID ExtraBuffer,
ULONG ExtraLength,
BOOLEAN ExtraBufferIsReparsePoint,
PVOID *PFileContext,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This function works like Create, except that it also accepts an extra buffer that may contain extended attributes or a reparse point.
NOTE: If both Create and CreateEx are defined, CreateEx takes precedence.
</blockquote> </details> <details> <summary> <b>DeleteReparsePoint</b> - Delete reparse point. </summary> <blockquote>NTSTATUS ( *DeleteReparsePoint)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PWSTR FileName,
PVOID Buffer,
SIZE_T Size);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>DispatcherStopped</b> - Inform the file system that its dispatcher has been stopped. </summary> <blockquote>VOID ( *DispatcherStopped)(
FSP_FILE_SYSTEM *FileSystem,
BOOLEAN Normally);
Parameters
Discussion
Prior to WinFsp v2.0 the FSD would never unmount a file system volume unless the user mode file system requested the unmount. Since WinFsp v2.0 it is possible for the FSD to unmount a file system volume without an explicit user mode file system request. For example, this happens when the FSD is being uninstalled.
A user mode file system can use this operation to determine when its dispatcher has been stopped. The Normally parameter can be used to determine why the dispatcher was stopped: it is TRUE when the file system is being stopped via FspFileSystemStopDispatcher and FALSE otherwise.
When the file system receives a request with Normally == TRUE it need not take any extra steps. This case is the same as for pre-v2.0 versions: since the file system stopped the dispatcher via FspFileSystemStopDispatcher, it will likely exit its process soon.
When the file system receives a request with Normally == FALSE it may need to take extra steps to exit its process as this is not done by default.
A file system that uses the FspService infrastructure may use the FspFileSystemStopServiceIfNecessary API to correctly handle all cases.
This operation is the last one that a file system will receive.
See Also
NTSTATUS ( *Flush)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
Note that the FSD will also flush all file/volume caches prior to invoking this operation.
</blockquote> </details> <details> <summary> <b>GetDirInfoByName</b> - Get directory information for a single file or directory within a parent directory. </summary> <blockquote>NTSTATUS ( *GetDirInfoByName)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PWSTR FileName,
FSP_FSCTL_DIR_INFO *DirInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>GetEa</b> - Get extended attributes. </summary> <blockquote>NTSTATUS ( *GetEa)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PFILE_FULL_EA_INFORMATION Ea,
ULONG EaLength,
PULONG PBytesTransferred);
Parameters
Return Value
STATUS_SUCCESS or error code.
See Also
NTSTATUS ( *GetFileInfo)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>GetReparsePoint</b> - Get reparse point. </summary> <blockquote>NTSTATUS ( *GetReparsePoint)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PWSTR FileName,
PVOID Buffer,
PSIZE_T PSize);
Parameters
Return Value
STATUS_SUCCESS or error code.
See Also
NTSTATUS ( *GetSecurity)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PSECURITY_DESCRIPTOR SecurityDescriptor,
SIZE_T *PSecurityDescriptorSize);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>GetSecurityByName</b> - Get file or directory attributes and security descriptor given a file name. </summary> <blockquote>NTSTATUS ( *GetSecurityByName)(
FSP_FILE_SYSTEM *FileSystem,
PWSTR FileName,
PUINT32 PFileAttributes/* or ReparsePointIndex */,
PSECURITY_DESCRIPTOR SecurityDescriptor,
SIZE_T *PSecurityDescriptorSize);
Parameters
If this call returns STATUS_REPARSE, the file system MAY place here the index of the first reparse point within FileName. The file system MAY also leave this at its default value of 0.
Return Value
STATUS_SUCCESS, STATUS_REPARSE or error code.
STATUS_REPARSE should be returned by file systems that support reparse points when they encounter a FileName that contains reparse points anywhere but the final path component.
</blockquote> </details> <details> <summary> <b>GetStreamInfo</b> - Get named streams information. </summary> <blockquote>NTSTATUS ( *GetStreamInfo)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PVOID Buffer,
ULONG Length,
PULONG PBytesTransferred);
Parameters
Return Value
STATUS_SUCCESS or error code.
See Also
NTSTATUS ( *GetVolumeInfo)(
FSP_FILE_SYSTEM *FileSystem,
FSP_FSCTL_VOLUME_INFO *VolumeInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>Open</b> - Open a file or directory. </summary> <blockquote>NTSTATUS ( *Open)(
FSP_FILE_SYSTEM *FileSystem,
PWSTR FileName,
UINT32 CreateOptions,
UINT32 GrantedAccess,
PVOID *PFileContext,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>Overwrite</b> - Overwrite a file. </summary> <blockquote>NTSTATUS ( *Overwrite)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
UINT32 FileAttributes,
BOOLEAN ReplaceFileAttributes,
UINT64 AllocationSize,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>OverwriteEx</b> - Overwrite a file. </summary> <blockquote>NTSTATUS ( *OverwriteEx)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
UINT32 FileAttributes,
BOOLEAN ReplaceFileAttributes,
UINT64 AllocationSize,
PFILE_FULL_EA_INFORMATION Ea,
ULONG EaLength,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This function works like Overwrite, except that it also accepts EA (extended attributes).
NOTE: If both Overwrite and OverwriteEx are defined, OverwriteEx takes precedence.
</blockquote> </details> <details> <summary> <b>Read</b> - Read a file. </summary> <blockquote>NTSTATUS ( *Read)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PVOID Buffer,
UINT64 Offset,
ULONG Length,
PULONG PBytesTransferred);
Parameters
Return Value
STATUS_SUCCESS or error code. STATUS_PENDING is supported allowing for asynchronous operation.
</blockquote> </details> <details> <summary> <b>ReadDirectory</b> - Read a directory. </summary> <blockquote>NTSTATUS ( *ReadDirectory)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PWSTR Pattern,
PWSTR Marker,
PVOID Buffer,
ULONG Length,
PULONG PBytesTransferred);
Parameters
Return Value
STATUS_SUCCESS or error code. STATUS_PENDING is supported allowing for asynchronous operation.
See Also
NTSTATUS ( *Rename)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PWSTR FileName,
PWSTR NewFileName,
BOOLEAN ReplaceIfExists);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
The kernel mode FSD provides certain guarantees prior to posting a rename operation:
A file cannot be renamed if a file with the same name exists and has open handles.
A directory cannot be renamed if it or any of its subdirectories contains a file that has open handles.
NTSTATUS ( *ResolveReparsePoints)(
FSP_FILE_SYSTEM *FileSystem,
PWSTR FileName,
UINT32 ReparsePointIndex,
BOOLEAN ResolveLastPathComponent,
PIO_STATUS_BLOCK PIoStatus,
PVOID Buffer,
PSIZE_T PSize);
Parameters
Return Value
STATUS_REPARSE or error code.
Discussion
Reparse points are a general mechanism for attaching special behavior to files. A file or directory can contain a reparse point. A reparse point is data that has special meaning to the file system, Windows or user applications. For example, NTFS and Windows use reparse points to implement symbolic links. As another example, a particular file system may use reparse points to emulate UNIX FIFO's.
This function is expected to resolve as many reparse points as possible. If a reparse point is encountered that is not understood by the file system further reparse point resolution should stop; the reparse point data should be returned to the FSD with status STATUS_REPARSE/reparse-tag. If a reparse point (symbolic link) is encountered that is understood by the file system but points outside it, the reparse point should be resolved, but further reparse point resolution should stop; the resolved file name should be returned to the FSD with status STATUS_REPARSE/IO_REPARSE.
</blockquote> </details> <details> <summary> <b>SetBasicInfo</b> - Set file or directory basic information. </summary> <blockquote>NTSTATUS ( *SetBasicInfo)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
UINT32 FileAttributes,
UINT64 CreationTime,
UINT64 LastAccessTime,
UINT64 LastWriteTime,
UINT64 ChangeTime,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>SetDelete</b> - Set the file delete flag. </summary> <blockquote>NTSTATUS ( *SetDelete)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PWSTR FileName,
BOOLEAN DeleteFile);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This function sets a flag to indicates whether the FSD file should delete a file when it is closed. This function does not need to perform access checks, but may performs tasks such as check for empty directories, etc.
This function should NEVER delete the file or directory in question. Deletion should happen during Cleanup with the FspCleanupDelete flag set.
This function gets called when Win32 API's such as DeleteFile or RemoveDirectory are used. It does not get called when a file or directory is opened with FILE_DELETE_ON_CLOSE.
NOTE: If both CanDelete and SetDelete are defined, SetDelete takes precedence. However most file systems need only implement the CanDelete operation.
See Also
NTSTATUS ( *SetEa)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PFILE_FULL_EA_INFORMATION Ea,
ULONG EaLength,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
See Also
NTSTATUS ( *SetFileSize)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
UINT64 NewSize,
BOOLEAN SetAllocationSize,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This function is used to change a file's sizes. Windows file systems maintain two kinds of sizes: the file size is where the End Of File (EOF) is, and the allocation size is the actual size that a file takes up on the "disk".
The rules regarding file/allocation size are:
Allocation size must always be aligned to the allocation unit boundary. The allocation
unit is the product (UINT64)SectorSize \* (UINT64)SectorsPerAllocationUnit from
the FSP_FSCTL_VOLUME_PARAMS structure. The FSD will always send properly aligned allocation
sizes when setting the allocation size.
Allocation size is always greater or equal to the file size.
A file size of more than the current allocation size will also extend the allocation size to the next allocation unit boundary.
An allocation size of less than the current file size should also truncate the current file size.
NTSTATUS ( *SetReparsePoint)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PWSTR FileName,
PVOID Buffer,
SIZE_T Size);
Parameters
Return Value
STATUS_SUCCESS or error code.
See Also
NTSTATUS ( *SetSecurity)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR ModificationDescriptor);
Parameters
Return Value
STATUS_SUCCESS or error code.
See Also
NTSTATUS ( *SetVolumeLabel)(
FSP_FILE_SYSTEM *FileSystem,
PWSTR VolumeLabel,
FSP_FSCTL_VOLUME_INFO *VolumeInfo);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>Write</b> - Write a file. </summary> <blockquote>NTSTATUS ( *Write)(
FSP_FILE_SYSTEM *FileSystem,
PVOID FileContext,
PVOID Buffer,
UINT64 Offset,
ULONG Length,
BOOLEAN WriteToEndOfFile,
BOOLEAN ConstrainedIo,
PULONG PBytesTransferred,
FSP_FSCTL_FILE_INFO *FileInfo);
Parameters
Return Value
STATUS_SUCCESS or error code. STATUS_PENDING is supported allowing for asynchronous operation.
</blockquote> </details> </blockquote> </details>FSP_API VOID FspDeleteSecurityDescriptor(
PSECURITY_DESCRIPTOR SecurityDescriptor,
NTSTATUS (*CreateFunc)());
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This is a helper for implementing the SetSecurity operation.
See Also
FSP_API BOOLEAN FspFileSystemAddDirInfo(
FSP_FSCTL_DIR_INFO *DirInfo,
PVOID Buffer,
ULONG Length,
PULONG PBytesTransferred);
Parameters
Return Value
TRUE if the directory information was added, FALSE if there was not enough space to add it.
Discussion
This is a helper for implementing the ReadDirectory operation.
See Also
FSP_API BOOLEAN FspFileSystemAddEa(
PFILE_FULL_EA_INFORMATION SingleEa,
PFILE_FULL_EA_INFORMATION Ea,
ULONG EaLength,
PULONG PBytesTransferred);
Parameters
Return Value
TRUE if the extended attribute was added, FALSE if there was not enough space to add it.
Discussion
This is a helper for implementing the GetEa operation.
See Also
FSP_API BOOLEAN FspFileSystemAddNotifyInfo(
FSP_FSCTL_NOTIFY_INFO *NotifyInfo,
PVOID Buffer,
ULONG Length,
PULONG PBytesTransferred);
Parameters
Return Value
TRUE if the notify information was added, FALSE if there was not enough space to add it.
Discussion
This is a helper for filling a buffer to use with FspFileSystemNotify.
See Also
FSP_API BOOLEAN FspFileSystemAddStreamInfo(
FSP_FSCTL_STREAM_INFO *StreamInfo,
PVOID Buffer,
ULONG Length,
PULONG PBytesTransferred);
Parameters
Return Value
TRUE if the stream information was added, FALSE if there was not enough space to add it.
Discussion
This is a helper for implementing the GetStreamInfo operation.
See Also
FSP_API NTSTATUS FspFileSystemCanReplaceReparsePoint(
PVOID CurrentReparseData,
SIZE_T CurrentReparseDataSize,
PVOID ReplaceReparseData,
SIZE_T ReplaceReparseDataSize);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This is a helper for implementing the SetReparsePoint/DeleteReparsePoint operation in file systems that support reparse points.
See Also
FSP_API NTSTATUS FspFileSystemCreate(
PWSTR DevicePath,
const FSP_FSCTL_VOLUME_PARAMS *VolumeParams,
const FSP_FILE_SYSTEM_INTERFACE *Interface,
FSP_FILE_SYSTEM **PFileSystem);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>FspFileSystemDelete</b> - Delete a file system object. </summary> <blockquote>FSP_API VOID FspFileSystemDelete(
FSP_FILE_SYSTEM *FileSystem);
Parameters
FSP_API NTSTATUS FspFileSystemEnumerateEa(
FSP_FILE_SYSTEM *FileSystem,
NTSTATUS (*EnumerateEa)(
FSP_FILE_SYSTEM *FileSystem,
PVOID Context,
PFILE_FULL_EA_INFORMATION SingleEa),
PVOID Context,
PFILE_FULL_EA_INFORMATION Ea,
ULONG EaLength);
Parameters
Return Value
STATUS_SUCCESS or error code from EnumerateEa.
Discussion
This is a helper for implementing the CreateEx and SetEa operations in file systems that support extended attributes.
</blockquote> </details> <details> <summary> <b>FspFileSystemFindReparsePoint</b> - Find reparse point in file name. </summary> <blockquote>FSP_API BOOLEAN FspFileSystemFindReparsePoint(
FSP_FILE_SYSTEM *FileSystem,
NTSTATUS (*GetReparsePointByName)(
FSP_FILE_SYSTEM *FileSystem,
PVOID Context,
PWSTR FileName,
BOOLEAN IsDirectory,
PVOID Buffer,
PSIZE_T PSize),
PVOID Context,
PWSTR FileName,
PUINT32 PReparsePointIndex);
Parameters
Return Value
TRUE if a reparse point was found, FALSE otherwise.
Discussion
Given a file name this function returns an index to the first path component that is a reparse point. The function will call the supplied GetReparsePointByName function for every path component until it finds a reparse point or the whole path is processed.
This is a helper for implementing the GetSecurityByName operation in file systems that support reparse points.
See Also
static inline UINT32 FspFileSystemGetEaPackedSize(
PFILE_FULL_EA_INFORMATION SingleEa)
Parameters
Return Value
The packed size of the extended attribute.
</blockquote> </details> <details> <summary> <b>FspFileSystemGetOpenFileInfo</b> - Get open information buffer. </summary> <blockquote>static inline FSP_FSCTL_OPEN_FILE_INFO *FspFileSystemGetOpenFileInfo(
FSP_FSCTL_FILE_INFO *FileInfo)
Parameters
Return Value
A pointer to the open information buffer for this Create or Open operation.
Discussion
This is a helper for implementing the Create and Open operations. It cannot be used with any other operations.
The FileInfo parameter to Create and Open is typed as pointer to FSP_FSCTL_FILE_INFO. The true type of this parameter is pointer to FSP_FSCTL_OPEN_FILE_INFO. This simple function converts from one type to the other.
The FSP_FSCTL_OPEN_FILE_INFO type contains a FSP_FSCTL_FILE_INFO as well as the fields NormalizedName and NormalizedNameSize. These fields can be used for file name normalization. File name normalization is used to ensure that the FSD and the OS know the correct case of a newly opened file name.
For case-sensitive file systems this functionality should be ignored. The FSD will always assume that the normalized file name is the same as the file name used to open the file.
For case-insensitive file systems this functionality may be ignored. In this case the FSD will assume that the normalized file name is the upper case version of the file name used to open the file. The file system will work correctly and the only way an application will be able to tell that the file system does not preserve case in normalized file names is by issuing a GetFinalPathNameByHandle API call (or NtQueryInformationFile with FileNameInformation/FileNormalizedNameInformation).
For case-insensitive file systems this functionality may also be used. In this case the user mode file system may use the NormalizedName and NormalizedNameSize parameters to report to the FSD the normalized file name. It should be noted that the normalized file name may only differ in case from the file name used to open the file. The NormalizedName field will point to a buffer that can receive the normalized file name. The NormalizedNameSize field will contain the size of the normalized file name buffer. On completion of the Create or Open operation it should contain the actual size of the normalized file name copied into the normalized file name buffer. The normalized file name should not contain a terminating zero.
See Also
FSP_API FSP_FILE_SYSTEM_OPERATION_CONTEXT *FspFileSystemGetOperationContext(
VOID);
Return Value
The current operation context.
Discussion
This function may be used only when servicing one of the FSP_FILE_SYSTEM_INTERFACE operations. The current operation context is stored in thread local storage. It allows access to the Request and Response associated with this operation.
</blockquote> </details> <details> <summary> <b>FspFileSystemNotify</b> - Notify Windows that the file system has file changes. </summary> <blockquote>FSP_API NTSTATUS FspFileSystemNotify(
FSP_FILE_SYSTEM *FileSystem,
FSP_FSCTL_NOTIFY_INFO *NotifyInfo,
SIZE_T Size);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
A file system that wishes to notify Windows about file changes must first issue an FspFileSystemBegin call, followed by 0 or more FspFileSystemNotify calls, followed by an FspFileSystemNotifyEnd call.
Note that FspFileSystemNotify requires file names to be normalized. A normalized file name is one that contains the correct case of all characters in the file name.
For case-sensitive file systems all file names are normalized by definition. For case-insensitive file systems that implement file name normalization, a normalized file name is the one that the file system specifies in the response to Create or Open (see also FspFileSystemGetOpenFileInfo). For case-insensitive file systems that do not implement file name normalization a normalized file name is the upper case version of the file name used to open the file.
</blockquote> </details> <details> <summary> <b>FspFileSystemNotifyBegin</b> - Begin notifying Windows that the file system has file changes. </summary> <blockquote>FSP_API NTSTATUS FspFileSystemNotifyBegin(
FSP_FILE_SYSTEM *FileSystem,
ULONG Timeout);
Parameters
Return Value
STATUS_SUCCESS or error code. The error code STATUS_CANT_WAIT means that a file rename operation is currently in progress and the operation must be retried at a later time.
Discussion
A file system that wishes to notify Windows about file changes must first issue an FspFileSystemBegin call, followed by 0 or more FspFileSystemNotify calls, followed by an FspFileSystemNotifyEnd call.
This operation blocks concurrent file rename operations. File rename operations may interfere with file notification, because a file being notified may also be concurrently renamed. After all file change notifications have been issued, you must make sure to call FspFileSystemNotifyEnd to allow file rename operations to proceed.
</blockquote> </details> <details> <summary> <b>FspFileSystemNotifyEnd</b> - End notifying Windows that the file system has file changes. </summary> <blockquote>FSP_API NTSTATUS FspFileSystemNotifyEnd(
FSP_FILE_SYSTEM *FileSystem);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
A file system that wishes to notify Windows about file changes must first issue an FspFileSystemBegin call, followed by 0 or more FspFileSystemNotify calls, followed by an FspFileSystemNotifyEnd call.
This operation allows any blocked file rename operations to proceed.
</blockquote> </details> <details> <summary> <b>FspFileSystemOperationProcessId</b> - Gets the originating process ID. </summary> <blockquote>static inline UINT32 FspFileSystemOperationProcessId(
VOID)
Discussion
Valid only during Create, Open and Rename requests when the target exists.
</blockquote> </details> <details> <summary> <b>FspFileSystemPreflight</b> - Check whether creating a file system object is possible. </summary> <blockquote>FSP_API NTSTATUS FspFileSystemPreflight(
PWSTR DevicePath,
PWSTR MountPoint);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>FspFileSystemRemoveMountPoint</b> - Remove the mount point for a file system. </summary> <blockquote>FSP_API VOID FspFileSystemRemoveMountPoint(
FSP_FILE_SYSTEM *FileSystem);
Parameters
FSP_API NTSTATUS FspFileSystemResolveReparsePoints(
FSP_FILE_SYSTEM *FileSystem,
NTSTATUS (*GetReparsePointByName)(
FSP_FILE_SYSTEM *FileSystem,
PVOID Context,
PWSTR FileName,
BOOLEAN IsDirectory,
PVOID Buffer,
PSIZE_T PSize),
PVOID Context,
PWSTR FileName,
UINT32 ReparsePointIndex,
BOOLEAN ResolveLastPathComponent,
PIO_STATUS_BLOCK PIoStatus,
PVOID Buffer,
PSIZE_T PSize);
Parameters
Return Value
STATUS_REPARSE or error code.
Discussion
Given a file name (and an index where to start resolving) this function will attempt to resolve as many reparse points as possible. The function will call the supplied GetReparsePointByName function for every path component until it resolves the reparse points or the whole path is processed.
This is a helper for implementing the ResolveReparsePoints operation in file systems that support reparse points.
See Also
FSP_API VOID FspFileSystemSendResponse(
FSP_FILE_SYSTEM *FileSystem,
FSP_FSCTL_TRANSACT_RSP *Response);
Parameters
Discussion
This call is not required when the user mode file system performs synchronous processing of requests. It is possible however for the following FSP_FILE_SYSTEM_INTERFACE operations to be processed asynchronously:
Read
Write
ReadDirectory
These operations are allowed to return STATUS_PENDING to postpone sending a response to the FSD. At a later time the file system can use FspFileSystemSendResponse to send the response.
</blockquote> </details> <details> <summary> <b>FspFileSystemSetMountPoint</b> - Set the mount point for a file system. </summary> <blockquote>FSP_API NTSTATUS FspFileSystemSetMountPoint(
FSP_FILE_SYSTEM *FileSystem,
PWSTR MountPoint);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This function supports drive letters (X:) or directories as mount points:
Drive letters: Refer to the documentation of the DefineDosDevice Windows API to better understand how they are created.
Directories: They can be used as mount points for disk based file systems. They cannot be used for network file systems. This is a limitation that Windows imposes on junctions.
static inline VOID FspFileSystemSetOperationGuardStrategy(
FSP_FILE_SYSTEM *FileSystem,
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY GuardStrategy)
Parameters
See Also
FSP_API NTSTATUS FspFileSystemStartDispatcher(
FSP_FILE_SYSTEM *FileSystem,
ULONG ThreadCount);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
The file system dispatcher is used to dispatch operations posted by the FSD to the user mode file system. Once this call starts executing the user mode file system will start receiving file system requests from the kernel.
</blockquote> </details> <details> <summary> <b>FspFileSystemStopDispatcher</b> - Stop the file system dispatcher. </summary> <blockquote>FSP_API VOID FspFileSystemStopDispatcher(
FSP_FILE_SYSTEM *FileSystem);
Parameters
FSP_API VOID FspFileSystemStopServiceIfNecessary(
FSP_FILE_SYSTEM *FileSystem,
BOOLEAN Normally);
Parameters
Discussion
This is a helper for implementing the DispatcherStopped operation, but only for file systems that use the FspService infrastructure.
See Also
FSP_API NTSTATUS FspSetSecurityDescriptor(
PSECURITY_DESCRIPTOR InputDescriptor,
SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR ModificationDescriptor,
PSECURITY_DESCRIPTOR *PSecurityDescriptor);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This is a helper for implementing the SetSecurity operation.
See Also
typedef enum {
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE = 0,
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE,
} FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY;
Discussion
Two concurrency models are provided:
EXCL: SetVolumeLabel, Flush(Volume), Create, Cleanup(Delete), SetInformation(Rename)
SHRD: GetVolumeInfo, Open, SetInformation(Disposition), ReadDirectory
NONE: all other operations
See Also
User mode file systems typically are run as Windows services. WinFsp provides an API to make the creation of Windows services easier. This API is provided for convenience and is not necessary to expose a user mode file system to Windows.
FSP_API VOID FspServiceAcceptControl(
FSP_SERVICE *Service,
ULONG Control);
Parameters
Discussion
This API should be used prior to Start operations.
</blockquote> </details> <details> <summary> <b>FspServiceAllowConsoleMode</b> - Allow a service to run in console mode. </summary> <blockquote>FSP_API VOID FspServiceAllowConsoleMode(
FSP_SERVICE *Service);
Parameters
Discussion
A service that is run in console mode runs with a console attached and outside the control of the Service Control Manager. This is useful for debugging and testing a service during development.
User mode file systems that wish to use the WinFsp Launcher functionality must also use this call. The WinFsp Launcher is a Windows service that can be configured to launch and manage multiple instances of a user mode file system.
</blockquote> </details> <details> <summary> <b>FspServiceContextCheck</b> - Check if the supplied token is from the service context. </summary> <blockquote>FSP_API NTSTATUS FspServiceContextCheck(
HANDLE Token,
PBOOLEAN PIsLocalSystem);
Parameters
Return Value
STATUS_SUCCESS if the token is from the service context. STATUS_ACCESS_DENIED if it is not. Other error codes are possible.
</blockquote> </details> <details> <summary> <b>FspServiceCreate</b> - Create a service object. </summary> <blockquote>FSP_API NTSTATUS FspServiceCreate(
PWSTR ServiceName,
FSP_SERVICE_START *OnStart,
FSP_SERVICE_STOP *OnStop,
FSP_SERVICE_CONTROL *OnControl,
FSP_SERVICE **PService);
Parameters
Return Value
STATUS_SUCCESS or error code.
</blockquote> </details> <details> <summary> <b>FspServiceDelete</b> - Delete a service object. </summary> <blockquote>FSP_API VOID FspServiceDelete(
FSP_SERVICE *Service);
Parameters
FSP_API ULONG FspServiceGetExitCode(
FSP_SERVICE *Service);
Parameters
Return Value
Service process exit code.
</blockquote> </details> <details> <summary> <b>FspServiceIsInteractive</b> - Determine if the current process is running in user interactive mode. </summary> <blockquote>FSP_API BOOLEAN FspServiceIsInteractive(
VOID);
Return Value
TRUE if the process is running in running user interactive mode.
</blockquote> </details> <details> <summary> <b>FspServiceLog</b> - Log a service message. </summary> <blockquote>FSP_API VOID FspServiceLog(
ULONG Type,
PWSTR Format,
...);
Parameters
Discussion
This function can be used to log an arbitrary message to the Windows Event Log or to the current console if running in user interactive mode.
</blockquote> </details> <details> <summary> <b>FspServiceLoop</b> - Run a service main loop. </summary> <blockquote>FSP_API NTSTATUS FspServiceLoop(
FSP_SERVICE *Service);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
This function starts and runs a service. It executes the Windows StartServiceCtrlDispatcher API to connect the service process to the Service Control Manager. If the Service Control Manager is not available (and console mode is allowed) it will enter console mode.
This function should be called once per process.
</blockquote> </details> <details> <summary> <b>FspServiceRequestTime</b> - Request additional time from the Service Control Manager. </summary> <blockquote>FSP_API VOID FspServiceRequestTime(
FSP_SERVICE *Service,
ULONG Time);
Parameters
Discussion
This API should be used during Start and Stop operations only.
</blockquote> </details> <details> <summary> <b>FspServiceRunEx</b> - Run a service. </summary> <blockquote>FSP_API ULONG FspServiceRunEx(
PWSTR ServiceName,
FSP_SERVICE_START *OnStart,
FSP_SERVICE_STOP *OnStop,
FSP_SERVICE_CONTROL *OnControl,
PVOID UserContext);
Parameters
Return Value
Service process exit code.
Discussion
This function wraps calls to FspServiceCreate, FspServiceLoop and FspServiceDelete to create, run and delete a service. It is intended to be used from a service's main/wmain function.
This function runs a service with console mode allowed.
</blockquote> </details> <details> <summary> <b>FspServiceSetExitCode</b> - Set the service process exit code. </summary> <blockquote>FSP_API VOID FspServiceSetExitCode(
FSP_SERVICE *Service,
ULONG ExitCode);
Parameters
FSP_API VOID FspServiceStop(
FSP_SERVICE *Service);
Parameters
Return Value
STATUS_SUCCESS or error code.
Discussion
Stopping a service usually happens when the Service Control Manager instructs the service to stop. In some situations (e.g. fatal errors) the service may wish to stop itself. It can do so in a clean manner by calling this function.
</blockquote> </details> <p align="center"> <sub> Copyright © 2015-2026 Bill ZissimopoulosGenerated with <a href="https://github.com/billziss-gh/prettydoc">prettydoc</a> </sub>
</p>