pub trait FileSystemTraits: Send + Sync {
Show 23 methods
// Required methods
fn open(
&self,
task: TaskIdentifier,
path: &Path,
flags: Flags,
time: Time,
user: UserIdentifier,
group: GroupIdentifier,
) -> Result<LocalFileIdentifier>;
fn close(&self, file: LocalFileIdentifier) -> Result<()>;
fn close_all(&self, task: TaskIdentifier) -> Result<()>;
fn duplicate(
&self,
file: LocalFileIdentifier,
) -> Result<LocalFileIdentifier>;
fn transfert(
&self,
new_task: TaskIdentifier,
file: LocalFileIdentifier,
new_file: Option<FileIdentifier>,
) -> Result<LocalFileIdentifier>;
fn remove(&self, path: &Path) -> Result<()>;
fn read(
&self,
file: LocalFileIdentifier,
buffer: &mut [u8],
time_type: Time,
) -> Result<Size>;
fn write(
&self,
file: LocalFileIdentifier,
buffer: &[u8],
time_type: Time,
) -> Result<Size>;
fn rename(&self, source: &Path, destination: &Path) -> Result<()>;
fn set_position(
&self,
file: LocalFileIdentifier,
position: &Position,
) -> Result<Size>;
fn flush(&self, file: LocalFileIdentifier) -> Result<()>;
fn create_directory(
&self,
path: &Path,
time: Time,
user: UserIdentifier,
group: GroupIdentifier,
) -> Result<()>;
fn open_directory(
&self,
path: &Path,
task: TaskIdentifier,
) -> Result<LocalFileIdentifier>;
fn read_directory(&self, file: LocalFileIdentifier) -> Result<Option<Entry>>;
fn set_position_directory(
&self,
file: LocalFileIdentifier,
position: Size,
) -> Result<()>;
fn get_position_directory(&self, file: LocalFileIdentifier) -> Result<Size>;
fn rewind_directory(&self, file: LocalFileIdentifier) -> Result<()>;
fn close_directory(&self, file: LocalFileIdentifier) -> Result<()>;
fn get_metadata(&self, file: LocalFileIdentifier) -> Result<Metadata>;
fn set_metadata_from_path(
&self,
path: &Path,
metadata: &Metadata,
) -> Result<()>;
fn get_metadata_from_path(&self, path: &Path) -> Result<Metadata>;
fn get_statistics(
&self,
file: LocalFileIdentifier,
) -> Result<Statistics_type>;
fn get_mode(&self, file: LocalFileIdentifier) -> Result<Mode>;
}
Expand description
Core trait for all file system implementations.
This trait defines the complete interface that file systems must implement to integrate with the Xila operating system. It provides a POSIX-like API with additional features for multi-user environments, task isolation, and modern file system operations.
§Design Principles
§Task Isolation
All file operations are associated with a TaskIdentifier
to ensure proper
isolation between processes. File descriptors are local to each task.
§User Security
Operations include user and group identifiers for permission checking, ensuring secure multi-user operation.
§Concurrent Access
Implementations must handle concurrent access safely. The trait requires Send + Sync
and implementations should use appropriate synchronization primitives like RwLock
or Mutex
.
§Non-blocking Operations
All operations should avoid blocking indefinitely. If an operation would block,
implementations should return Error::RessourceBusy
.
§File Operations
The trait supports standard file operations including:
- Opening and closing files with various flags
- Reading and writing data
- Seeking to specific positions
- File and directory creation/deletion
- Metadata operations
§Directory Operations
Directory operations include:
- Creating and removing directories
- Opening directories for iteration
- Reading directory entries
- Position management for directory iteration
§Example Implementation Pattern
struct MyFileSystem {
// Use RwLock for thread safety
files: RwLock<CriticalSectionRawMutex, BTreeMap<Local_file_identifier_type, u32>>,
// ... other fields
}
impl File_system_traits for MyFileSystem {
fn Open(&self, task: TaskIdentifier, path: &Path_type, flags: Flags_type,
time: Time_type, user: User_identifier_type, group: Group_identifier_type)
-> Result<Local_file_identifier_type> {
todo!()
}
// ... other methods would be implemented here
}
Required Methods§
Sourcefn open(
&self,
task: TaskIdentifier,
path: &Path,
flags: Flags,
time: Time,
user: UserIdentifier,
group: GroupIdentifier,
) -> Result<LocalFileIdentifier>
fn open( &self, task: TaskIdentifier, path: &Path, flags: Flags, time: Time, user: UserIdentifier, group: GroupIdentifier, ) -> Result<LocalFileIdentifier>
Open a file for I/O operations.
Opens a file at the specified path with the given flags and associates it with the specified task. The operation is subject to permission checking based on the provided user and group identifiers.
§Arguments
Task
- Task identifier for file descriptor ownershipPath
- Path to the file to openFlags
- Open flags (read, write, create, etc.)Time
- Current time for metadata updatesUser
- User identifier for permission checkingGroup
- Group identifier for permission checking
§Returns
Ok(Local_file_identifier_type)
- File descriptor for the opened fileErr(Error)
- Error if file cannot be opened
§Errors
Error::NotFound
- File doesn’t exist and create flag not setError::PermissionDenied
- Insufficient permissionsError::AlreadyExists
- File exists and exclusive create flag setError::TooManyOpenFiles
- File descriptor limit reached
Sourcefn close(&self, file: LocalFileIdentifier) -> Result<()>
fn close(&self, file: LocalFileIdentifier) -> Result<()>
Close a file and release its resources.
Closes the file associated with the given file identifier and releases any resources associated with it. After calling this method, the file identifier becomes invalid for the task.
§Arguments
file
- File identifier to close
§Returns
Ok(())
- File successfully closedErr(Error)
- Error closing file
§Errors
Error::InvalidIdentifier
- File identifier is invalidError::InputOutput
- I/O error during close operation
Sourcefn close_all(&self, task: TaskIdentifier) -> Result<()>
fn close_all(&self, task: TaskIdentifier) -> Result<()>
Close all files opened by a specific task.
This is typically called during task cleanup to ensure all file descriptors are properly released when a task terminates.
§Arguments
task
- Task identifier whose files should be closed
§Returns
Ok(())
- All files successfully closedErr(Error)
- Error during cleanup
Sourcefn duplicate(&self, file: LocalFileIdentifier) -> Result<LocalFileIdentifier>
fn duplicate(&self, file: LocalFileIdentifier) -> Result<LocalFileIdentifier>
Create a duplicate file identifier for the same file.
Creates a new file identifier that refers to the same open file. This is
similar to the dup()
system call in Unix systems. Both identifiers
can be used independently and must be closed separately.
§Arguments
File
- File identifier to duplicate
§Returns
Ok(Local_file_identifier_type)
- New file identifier for the same fileErr(Error)
- Error creating duplicate
§Errors
Error::InvalidIdentifier
- Original file identifier is invalidError::TooManyOpenFiles
- File descriptor limit reached
Sourcefn transfert(
&self,
new_task: TaskIdentifier,
file: LocalFileIdentifier,
new_file: Option<FileIdentifier>,
) -> Result<LocalFileIdentifier>
fn transfert( &self, new_task: TaskIdentifier, file: LocalFileIdentifier, new_file: Option<FileIdentifier>, ) -> Result<LocalFileIdentifier>
Transfer a file identifier from one task to another.
Moves ownership of a file identifier from the current task to another task. This is useful for inter-process communication and file descriptor passing.
§Arguments
New_task
- Task to transfer the file toFile
- File identifier to transferNew_file
- Optional specific identifier to use in the new task
§Returns
Ok(Local_file_identifier_type)
- File identifier in the new taskErr(Error)
- Error during transfer
§Errors
Error::InvalidIdentifier
- File identifier is invalidError::FailedToGetTaskInformations
- Target task is invalid
Sourcefn remove(&self, path: &Path) -> Result<()>
fn remove(&self, path: &Path) -> Result<()>
Remove a file or directory from the file system.
Permanently deletes the specified file or directory. For directories, they must be empty before they can be removed.
§Arguments
path
- Path to the file or directory to remove
§Returns
Ok(())
- File or directory successfully removedErr(Error)
- Error during removal
§Errors
Error::NotFound
- File or directory doesn’t existError::PermissionDenied
- Insufficient permissionsError::DirectoryNotEmpty
- Directory contains filesError::RessourceBusy
- File is currently in use
Sourcefn read(
&self,
file: LocalFileIdentifier,
buffer: &mut [u8],
time_type: Time,
) -> Result<Size>
fn read( &self, file: LocalFileIdentifier, buffer: &mut [u8], time_type: Time, ) -> Result<Size>
Read data from an open file.
Reads data from the file at its current position into the provided buffer. The file position is advanced by the number of bytes read.
§Arguments
File
- File identifier to read fromBuffer
- Buffer to read data intoTime_type
- Current time for access time updates
§Returns
Ok(Size)
- Number of bytes actually readErr(Error)
- Error during read operation
§Errors
Error::InvalidIdentifier
- File identifier is invalidError::PermissionDenied
- File not opened for readingError::InputOutput
- I/O error during read
Sourcefn write(
&self,
file: LocalFileIdentifier,
buffer: &[u8],
time_type: Time,
) -> Result<Size>
fn write( &self, file: LocalFileIdentifier, buffer: &[u8], time_type: Time, ) -> Result<Size>
Write data to an open file.
Writes data from the buffer to the file at its current position. The file position is advanced by the number of bytes written.
§Arguments
File
- File identifier to write toBuffer
- Buffer containing data to writeTime_type
- Current time for modification time updates
§Returns
Ok(Size)
- Number of bytes actually writtenErr(Error)
- Error during write operation
§Errors
Error::InvalidIdentifier
- File identifier is invalidError::PermissionDenied
- File not opened for writingError::NoSpaceLeft
- Insufficient storage spaceError::InputOutput
- I/O error during write
Sourcefn rename(&self, source: &Path, destination: &Path) -> Result<()>
fn rename(&self, source: &Path, destination: &Path) -> Result<()>
Rename or move a file or directory.
Changes the name or location of a file or directory. This can be used for both renaming within the same directory and moving between directories.
§Arguments
source
- Current path of the file or directorydestination
- New path for the file or directory
§Returns
Ok(())
- File or directory successfully renamed/movedErr(Error)
- Error during rename operation
§Errors
Error::NotFound
- Source file doesn’t existError::AlreadyExists
- Destination already existsError::PermissionDenied
- Insufficient permissions