FileSystemInterface

Trait FileSystemInterface 

Source
pub trait FileSystemInterface {
    type FileContext: FileContextKind;
Show 32 associated constants and 32 methods const GET_VOLUME_INFO_DEFINED: bool = false; const SET_VOLUME_LABEL_DEFINED: bool = false; const GET_SECURITY_BY_NAME_DEFINED: bool = false; const CREATE_DEFINED: bool = false; const CREATE_EX_DEFINED: bool = false; const OPEN_DEFINED: bool = false; const OVERWRITE_DEFINED: bool = false; const OVERWRITE_EX_DEFINED: bool = false; const CLEANUP_DEFINED: bool = false; const CLOSE_DEFINED: bool = false; const READ_DEFINED: bool = false; const WRITE_DEFINED: bool = false; const FLUSH_DEFINED: bool = false; const GET_FILE_INFO_DEFINED: bool = false; const SET_BASIC_INFO_DEFINED: bool = false; const SET_FILE_SIZE_DEFINED: bool = false; const CAN_DELETE_DEFINED: bool = false; const RENAME_DEFINED: bool = false; const GET_SECURITY_DEFINED: bool = false; const SET_SECURITY_DEFINED: bool = false; const READ_DIRECTORY_DEFINED: bool = false; const GET_REPARSE_POINT_DEFINED: bool = false; const SET_REPARSE_POINT_DEFINED: bool = false; const DELETE_REPARSE_POINT_DEFINED: bool = false; const GET_STREAM_INFO_DEFINED: bool = false; const GET_DIR_INFO_BY_NAME_DEFINED: bool = false; const CONTROL_DEFINED: bool = false; const SET_DELETE_DEFINED: bool = false; const GET_EA_DEFINED: bool = false; const SET_EA_DEFINED: bool = false; const DISPATCHER_STOPPED_DEFINED: bool = false; const RESOLVE_REPARSE_POINTS_DEFINED: bool = false; // Provided methods fn get_volume_info(&self) -> Result<VolumeInfo, NTSTATUS> { ... } fn set_volume_label( &self, _volume_label: &U16CStr, ) -> Result<VolumeInfo, NTSTATUS> { ... } fn get_security_by_name( &self, _file_name: &U16CStr, _find_reparse_point: impl Fn() -> Option<FileAttributes>, ) -> Result<(FileAttributes, PSecurityDescriptor, bool), NTSTATUS> { ... } fn create( &self, _file_name: &U16CStr, _create_file_info: CreateFileInfo, _security_descriptor: SecurityDescriptor, ) -> Result<(Self::FileContext, FileInfo), NTSTATUS> { ... } fn create_ex( &self, _file_name: &U16CStr, _create_file_info: CreateFileInfo, _security_descriptor: SecurityDescriptor, _buffer: &[u8], _extra_buffer_is_reparse_point: bool, ) -> Result<(Self::FileContext, FileInfo), NTSTATUS> { ... } fn open( &self, _file_name: &U16CStr, _create_options: CreateOptions, _granted_access: FileAccessRights, ) -> Result<(Self::FileContext, FileInfo), NTSTATUS> { ... } fn overwrite( &self, _file_context: Self::FileContext, _file_attributes: FileAttributes, _replace_file_attributes: bool, _allocation_size: u64, ) -> Result<FileInfo, NTSTATUS> { ... } fn overwrite_ex( &self, _file_context: Self::FileContext, _file_attributes: FileAttributes, _replace_file_attributes: bool, _allocation_size: u64, _buffer: &[u8], ) -> Result<FileInfo, NTSTATUS> { ... } fn cleanup( &self, _file_context: Self::FileContext, _file_name: Option<&U16CStr>, _flags: CleanupFlags, ) { ... } fn close(&self, _file_context: Self::FileContext) { ... } fn read( &self, _file_context: Self::FileContext, _buffer: &mut [u8], _offset: u64, ) -> Result<usize, NTSTATUS> { ... } fn write( &self, _file_context: Self::FileContext, _buffer: &[u8], _mode: WriteMode, ) -> Result<(usize, FileInfo), NTSTATUS> { ... } fn flush( &self, _file_context: Self::FileContext, ) -> Result<FileInfo, NTSTATUS> { ... } fn get_file_info( &self, _file_context: Self::FileContext, ) -> Result<FileInfo, NTSTATUS> { ... } fn set_basic_info( &self, _file_context: Self::FileContext, _file_attributes: FileAttributes, _creation_time: u64, _last_access_time: u64, _last_write_time: u64, _change_time: u64, ) -> Result<FileInfo, NTSTATUS> { ... } fn set_file_size( &self, _file_context: Self::FileContext, _new_size: u64, _set_allocation_size: bool, ) -> Result<FileInfo, NTSTATUS> { ... } fn can_delete( &self, _file_context: Self::FileContext, _file_name: &U16CStr, ) -> Result<(), NTSTATUS> { ... } fn rename( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _new_file_name: &U16CStr, _replace_if_exists: bool, ) -> Result<(), NTSTATUS> { ... } fn get_security( &self, _file_context: Self::FileContext, ) -> Result<PSecurityDescriptor, NTSTATUS> { ... } fn set_security( &self, _file_context: Self::FileContext, _security_information: u32, _modification_descriptor: PSecurityDescriptor, ) -> Result<(), NTSTATUS> { ... } fn read_directory( &self, _file_context: Self::FileContext, _marker: Option<&U16CStr>, _add_dir_info: impl FnMut(DirInfo) -> bool, ) -> Result<(), NTSTATUS> { ... } fn get_reparse_point( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _buffer: &mut [u8], ) -> Result<usize, NTSTATUS> { ... } fn set_reparse_point( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _buffer: &mut [u8], ) -> Result<(), NTSTATUS> { ... } fn delete_reparse_point( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _buffer: &mut [u8], ) -> Result<(), NTSTATUS> { ... } fn get_stream_info( &self, _file_context: Self::FileContext, _buffer: &mut [u8], ) -> Result<usize, NTSTATUS> { ... } fn get_dir_info_by_name( &self, _file_context: Self::FileContext, _file_name: &U16CStr, ) -> Result<FileInfo, NTSTATUS> { ... } fn control( &self, _file_context: Self::FileContext, _control_code: u32, _input_buffer: &[u8], _output_buffer: &mut [u8], ) -> Result<usize, NTSTATUS> { ... } fn set_delete( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _delete_file: bool, ) -> Result<(), NTSTATUS> { ... } fn get_ea( &self, _file_context: Self::FileContext, _buffer: &[u8], ) -> Result<usize, NTSTATUS> { ... } fn set_ea( &self, _file_context: Self::FileContext, _buffer: &[u8], ) -> Result<FileInfo, NTSTATUS> { ... } fn dispatcher_stopped(&self, _normally: bool) { ... } fn get_reparse_point_by_name( &self, _file_name: &U16CStr, _is_directory: bool, _buffer: Option<&mut [u8]>, ) -> Result<usize, NTSTATUS> { ... }
}
Expand description

High level interface over FSP_FILE_SYSTEM_INTERFACE.

This trait requires to overwrite all WinFSP callbacks you need and it corresponding xxx_DEFINED associated const boolean.

This is needed to properly build the FSP_FILE_SYSTEM_INTERFACE struct, as a callback pointer set to NULL (i.e. if xxx_DEFINED=false) leads to a different behavior that a callback pointer containing a mock implementation (e.g. returning Err(STATUS_NOT_IMPLEMENTED)).

So the way to work with this trait is to overwrite the method and xxx_DEFINED for each function pointer you will need in FSP_FILE_SYSTEM_INTERFACE:

struct MyFS;
impl FileSystemInterface for MyFS {
    type FileContext: usize;
    // `CREATE_DEFINED` not overwritten, hence `FSP_FILE_SYSTEM_INTERFACE.Create == NULL`
    const CREATE_EX_DEFINED: bool = true;  // i.e. `FSP_FILE_SYSTEM_INTERFACE.CreateEx != NULL`
    fn create_ex(
        &self,
        file_name: &U16CStr,
        create_file_info: CreateFileInfo,
        security_descriptor: SecurityDescriptor,
        buffer: &[u8],
        extra_buffer_is_reparse_point: bool,
    ) -> Result<(Self::FileContext, FileInfo), NTSTATUS> {
        ...
    }
}

Notes:

  • Associated method and xxx_DEFINED const must be overwritten together, as the method is simply ignored if xxx_DEFINED is not set, and setting xxx_DEFINED without overwritting the method means the function pointer relies on the method default implementation that panics whenever used (ah !).
  • If your are curious about the reason for using a trait here instead of a struct (or associated const fields with Option<fn()> type in the trait instead of methods), it all boils down to the fact some methods have an impl Fn function pointer as argument, which is only possible in trait method.

Provided Associated Constants§

Required Associated Types§

Provided Methods§

Source

fn get_volume_info(&self) -> Result<VolumeInfo, NTSTATUS>

Get volume information.

Source

fn set_volume_label( &self, _volume_label: &U16CStr, ) -> Result<VolumeInfo, NTSTATUS>

Set volume label.

Source

fn get_security_by_name( &self, _file_name: &U16CStr, _find_reparse_point: impl Fn() -> Option<FileAttributes>, ) -> Result<(FileAttributes, PSecurityDescriptor, bool), NTSTATUS>

Get file or directory attributes and security descriptor given a file name.

[out]:

  • file_attributes
  • security descriptor
  • reparse (false if reparse_point is not supported)

[help]:

  • find_reparse_point (optional, can be ignored): Helper to find reparse points (get_reparse_point_by_name should be implemented). If reparse point is found, return the FileAttributes and reparse should be set to true.
Source

fn create( &self, _file_name: &U16CStr, _create_file_info: CreateFileInfo, _security_descriptor: SecurityDescriptor, ) -> Result<(Self::FileContext, FileInfo), NTSTATUS>

Create new file or directory.

Note: FileSystemContext::create_ex takes precedence over FileSystemContext::create

Source

fn create_ex( &self, _file_name: &U16CStr, _create_file_info: CreateFileInfo, _security_descriptor: SecurityDescriptor, _buffer: &[u8], _extra_buffer_is_reparse_point: bool, ) -> Result<(Self::FileContext, FileInfo), NTSTATUS>

Create new file or directory.

This function works like create, except that it also accepts an extra buffer that may contain extended attributes or a reparse point.

Note: FileSystemContext::create_ex takes precedence over FileSystemContext::create

Source

fn open( &self, _file_name: &U16CStr, _create_options: CreateOptions, _granted_access: FileAccessRights, ) -> Result<(Self::FileContext, FileInfo), NTSTATUS>

Open a file or directory.

Source

fn overwrite( &self, _file_context: Self::FileContext, _file_attributes: FileAttributes, _replace_file_attributes: bool, _allocation_size: u64, ) -> Result<FileInfo, NTSTATUS>

Overwrite a file.

Note: FileSystemContext::overwrite_ex takes precedence over FileSystemContext::overwrite

Source

fn overwrite_ex( &self, _file_context: Self::FileContext, _file_attributes: FileAttributes, _replace_file_attributes: bool, _allocation_size: u64, _buffer: &[u8], ) -> Result<FileInfo, NTSTATUS>

Overwrite a file.

This function works like overwrite, except that it also accepts EA (extended attributes).

Note: FileSystemContext::overwrite_ex takes precedence over FileSystemContext::overwrite

Source

fn cleanup( &self, _file_context: Self::FileContext, _file_name: Option<&U16CStr>, _flags: CleanupFlags, )

Cleanup a file.

Source

fn close(&self, _file_context: Self::FileContext)

Close a file.

Source

fn read( &self, _file_context: Self::FileContext, _buffer: &mut [u8], _offset: u64, ) -> Result<usize, NTSTATUS>

Read a file.

Source

fn write( &self, _file_context: Self::FileContext, _buffer: &[u8], _mode: WriteMode, ) -> Result<(usize, FileInfo), NTSTATUS>

Write a file.

Source

fn flush(&self, _file_context: Self::FileContext) -> Result<FileInfo, NTSTATUS>

Flush a file or volume.

Source

fn get_file_info( &self, _file_context: Self::FileContext, ) -> Result<FileInfo, NTSTATUS>

Get file or directory information.

Source

fn set_basic_info( &self, _file_context: Self::FileContext, _file_attributes: FileAttributes, _creation_time: u64, _last_access_time: u64, _last_write_time: u64, _change_time: u64, ) -> Result<FileInfo, NTSTATUS>

Set file or directory basic information.

Source

fn set_file_size( &self, _file_context: Self::FileContext, _new_size: u64, _set_allocation_size: bool, ) -> Result<FileInfo, NTSTATUS>

Set file/allocation size.

Source

fn can_delete( &self, _file_context: Self::FileContext, _file_name: &U16CStr, ) -> Result<(), NTSTATUS>

Determine whether a file or directory can be deleted.

Note: FileSystemContext::set_delete takes precedence over FileSystemContext::can_delete

Source

fn rename( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _new_file_name: &U16CStr, _replace_if_exists: bool, ) -> Result<(), NTSTATUS>

Renames a file or directory.

Source

fn get_security( &self, _file_context: Self::FileContext, ) -> Result<PSecurityDescriptor, NTSTATUS>

Get file or directory security descriptor.

Source

fn set_security( &self, _file_context: Self::FileContext, _security_information: u32, _modification_descriptor: PSecurityDescriptor, ) -> Result<(), NTSTATUS>

Set file or directory security descriptor.

Source

fn read_directory( &self, _file_context: Self::FileContext, _marker: Option<&U16CStr>, _add_dir_info: impl FnMut(DirInfo) -> bool, ) -> Result<(), NTSTATUS>

Read a directory.

add_dir_info returns false if there is no more space left to add elements.

Source

fn get_reparse_point( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _buffer: &mut [u8], ) -> Result<usize, NTSTATUS>

Get reparse point.

Source

fn set_reparse_point( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _buffer: &mut [u8], ) -> Result<(), NTSTATUS>

Set reparse point.

Source

fn delete_reparse_point( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _buffer: &mut [u8], ) -> Result<(), NTSTATUS>

Delete reparse point.

Source

fn get_stream_info( &self, _file_context: Self::FileContext, _buffer: &mut [u8], ) -> Result<usize, NTSTATUS>

Get named streams information.

Source

fn get_dir_info_by_name( &self, _file_context: Self::FileContext, _file_name: &U16CStr, ) -> Result<FileInfo, NTSTATUS>

Get directory information for a single file or directory within a parent directory.

Source

fn control( &self, _file_context: Self::FileContext, _control_code: u32, _input_buffer: &[u8], _output_buffer: &mut [u8], ) -> Result<usize, NTSTATUS>

Process control code.

Source

fn set_delete( &self, _file_context: Self::FileContext, _file_name: &U16CStr, _delete_file: bool, ) -> Result<(), NTSTATUS>

Set the file delete flag.

Note: FileSystemContext::set_delete takes precedence over FileSystemContext::can_delete

Source

fn get_ea( &self, _file_context: Self::FileContext, _buffer: &[u8], ) -> Result<usize, NTSTATUS>

Get extended attributes.

Source

fn set_ea( &self, _file_context: Self::FileContext, _buffer: &[u8], ) -> Result<FileInfo, NTSTATUS>

Set extended attributes.

Source

fn dispatcher_stopped(&self, _normally: bool)

Source

fn get_reparse_point_by_name( &self, _file_name: &U16CStr, _is_directory: bool, _buffer: Option<&mut [u8]>, ) -> Result<usize, NTSTATUS>

Get reparse point given a file name.

This method is used as a callback parameter to FspFileSystemFindReparsePoint & FspFileSystemResolveReparsePoints helpers to respectively implement FSP_FILE_SYSTEM_INTERFACE’s GetSecurityByName & ResolveReparsePoints.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§