Skip to content

Commit

Permalink
Rework FileSystemContext
Browse files Browse the repository at this point in the history
- Rename `FileSystemContext` to `FileSystemInterface` (better shows it is the high level equivalent of `FSP_FILE_SYSTEM_INTERFACE`)
- Expose associated const boolean in the trait to explicitly indicate which function pointer in `FSP_FILE_SYSTEM_INTERFACE` should be set
- Remove default implementations of trait methods that was somewhat usable as-is (i.e. could be passed to WinFSP as function pointer,
  but created unexpected behavior given NULL function pointer != function pointer returning `Err(STATUS_NOT_IMPLEMENTED)`)
  • Loading branch information
touilleMan committed Aug 7, 2024
1 parent 12eeff0 commit fe3294e
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 127 deletions.
30 changes: 24 additions & 6 deletions examples/memfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::{
};
use winfsp_wrs::{
filetime_now, u16cstr, u16str, CleanupFlags, CreateFileInfo, CreateOptions, DirInfo,
FileAccessRights, FileAttributes, FileInfo, FileSystem, FileSystemContext, PSecurityDescriptor,
Params, SecurityDescriptor, U16CStr, U16CString, U16Str, VolumeInfo, VolumeParams, WriteMode,
NTSTATUS, STATUS_ACCESS_DENIED, STATUS_DIRECTORY_NOT_EMPTY, STATUS_END_OF_FILE,
STATUS_MEDIA_WRITE_PROTECTED, STATUS_NOT_A_DIRECTORY, STATUS_OBJECT_NAME_COLLISION,
STATUS_OBJECT_NAME_NOT_FOUND,
FileAccessRights, FileAttributes, FileInfo, FileSystem, FileSystemInterface,
PSecurityDescriptor, Params, SecurityDescriptor, U16CStr, U16CString, U16Str, VolumeInfo,
VolumeParams, WriteMode, NTSTATUS, STATUS_ACCESS_DENIED, STATUS_DIRECTORY_NOT_EMPTY,
STATUS_END_OF_FILE, STATUS_MEDIA_WRITE_PROTECTED, STATUS_NOT_A_DIRECTORY,
STATUS_OBJECT_NAME_COLLISION, STATUS_OBJECT_NAME_NOT_FOUND,
};

macro_rules! debug {
Expand Down Expand Up @@ -246,17 +246,19 @@ impl MemFs {
}
}

impl FileSystemContext for MemFs {
impl FileSystemInterface for MemFs {
type FileContext = Arc<Mutex<Obj>>;

const SET_DELETE_DEFINED: bool = true;

const GET_VOLUME_INFO_DEFINED: bool = true;
fn get_volume_info(&self) -> Result<VolumeInfo, NTSTATUS> {
debug!("get_volume_info()");

Ok(self.volume_info.lock().unwrap().clone())
}

const SET_VOLUME_LABEL_DEFINED: bool = true;
fn set_volume_label(&self, volume_label: &U16CStr) -> Result<VolumeInfo, NTSTATUS> {
debug!("set_volume_label(volume_label: {:?})", volume_label);

Expand All @@ -269,6 +271,7 @@ impl FileSystemContext for MemFs {
Ok(guard.clone())
}

const GET_SECURITY_BY_NAME_DEFINED: bool = true;
fn get_security_by_name(
&self,
file_name: &U16CStr,
Expand Down Expand Up @@ -298,6 +301,7 @@ impl FileSystemContext for MemFs {
}
}

const CREATE_EX_DEFINED: bool = true;
fn create_ex(
&self,
file_name: &U16CStr,
Expand Down Expand Up @@ -349,6 +353,7 @@ impl FileSystemContext for MemFs {
Ok((file_context, file_info))
}

const OPEN_DEFINED: bool = true;
fn open(
&self,
file_name: &U16CStr,
Expand All @@ -372,6 +377,7 @@ impl FileSystemContext for MemFs {
}
}

const OVERWRITE_EX_DEFINED: bool = true;
fn overwrite_ex(
&self,
file_context: Self::FileContext,
Expand Down Expand Up @@ -416,6 +422,7 @@ impl FileSystemContext for MemFs {
self.get_file_info_from_obj(&fc)
}

const CLEANUP_DEFINED: bool = true;
fn cleanup(
&self,
file_context: Self::FileContext,
Expand Down Expand Up @@ -479,6 +486,7 @@ impl FileSystemContext for MemFs {
}
}

const READ_DEFINED: bool = true;
fn read(
&self,
file_context: Self::FileContext,
Expand All @@ -505,6 +513,7 @@ impl FileSystemContext for MemFs {
}
}

const WRITE_DEFINED: bool = true;
fn write(
&self,
file_context: Self::FileContext,
Expand Down Expand Up @@ -539,13 +548,15 @@ impl FileSystemContext for MemFs {
Ok((written, self.get_file_info_from_obj(&fc)?))
}

const FLUSH_DEFINED: bool = true;
fn flush(&self, file_context: Self::FileContext) -> Result<FileInfo, NTSTATUS> {
let fc = file_context.lock().unwrap();
debug!("[WinFSP] flush(file_context: {:?})", fc);

self.get_file_info_from_obj(&fc)
}

const GET_FILE_INFO_DEFINED: bool = true;
fn get_file_info(&self, file_context: Self::FileContext) -> Result<FileInfo, NTSTATUS> {
let fc = file_context.lock().unwrap();
debug!("[WinFSP] get_file_info(file_context: {:?})", fc);
Expand All @@ -556,6 +567,7 @@ impl FileSystemContext for MemFs {
}
}

const SET_BASIC_INFO_DEFINED: bool = true;
fn set_basic_info(
&self,
file_context: Self::FileContext,
Expand Down Expand Up @@ -615,6 +627,7 @@ impl FileSystemContext for MemFs {
self.get_file_info_from_obj(&fc)
}

const SET_FILE_SIZE_DEFINED: bool = true;
fn set_file_size(
&self,
file_context: Self::FileContext,
Expand Down Expand Up @@ -647,6 +660,7 @@ impl FileSystemContext for MemFs {
self.get_file_info_from_obj(&fc)
}

const RENAME_DEFINED: bool = true;
fn rename(
&self,
file_context: Self::FileContext,
Expand Down Expand Up @@ -699,6 +713,7 @@ impl FileSystemContext for MemFs {
Ok(())
}

const GET_SECURITY_DEFINED: bool = true;
fn get_security(
&self,
file_context: Self::FileContext,
Expand All @@ -712,6 +727,7 @@ impl FileSystemContext for MemFs {
}
}

const SET_SECURITY_DEFINED: bool = true;
fn set_security(
&self,
file_context: Self::FileContext,
Expand Down Expand Up @@ -743,6 +759,7 @@ impl FileSystemContext for MemFs {
Ok(())
}

const READ_DIRECTORY_DEFINED: bool = true;
fn read_directory(
&self,
file_context: Self::FileContext,
Expand Down Expand Up @@ -808,6 +825,7 @@ impl FileSystemContext for MemFs {
}
}

const SET_DELETE_DEFINED: bool = true;
fn set_delete(
&self,
file_context: Self::FileContext,
Expand Down
9 changes: 7 additions & 2 deletions examples/minimal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use winfsp_wrs::{
filetime_now, u16cstr, u16str, CreateOptions, DirInfo, FileAccessRights, FileAttributes,
FileInfo, FileSystem, FileSystemContext, PSecurityDescriptor, Params, SecurityDescriptor,
FileInfo, FileSystem, FileSystemInterface, PSecurityDescriptor, Params, SecurityDescriptor,
U16CStr, U16Str, VolumeInfo, VolumeParams, NTSTATUS,
};

Expand Down Expand Up @@ -48,9 +48,10 @@ impl MemFs {
}
}

impl FileSystemContext for MemFs {
impl FileSystemInterface for MemFs {
type FileContext = Arc<Context>;

const GET_SECURITY_BY_NAME_DEFINED: bool = true;
fn get_security_by_name(
&self,
_file_name: &U16CStr,
Expand All @@ -63,6 +64,7 @@ impl FileSystemContext for MemFs {
))
}

const OPEN_DEFINED: bool = true;
fn open(
&self,
_file_name: &U16CStr,
Expand All @@ -74,14 +76,17 @@ impl FileSystemContext for MemFs {
Ok((file_context, file_info))
}

const GET_FILE_INFO_DEFINED: bool = true;
fn get_file_info(&self, _file_context: Self::FileContext) -> Result<FileInfo, NTSTATUS> {
Ok(self.file_context.info)
}

const GET_VOLUME_INFO_DEFINED: bool = true;
fn get_volume_info(&self) -> Result<VolumeInfo, NTSTATUS> {
Ok(self.volume_info.clone())
}

const READ_DIRECTORY_DEFINED: bool = true;
fn read_directory(
&self,
_file_context: Self::FileContext,
Expand Down
Loading

0 comments on commit fe3294e

Please sign in to comment.