Trait FileSystemTraits

Source
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§

Source

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 ownership
  • Path - Path to the file to open
  • Flags - Open flags (read, write, create, etc.)
  • Time - Current time for metadata updates
  • User - User identifier for permission checking
  • Group - Group identifier for permission checking
§Returns
  • Ok(Local_file_identifier_type) - File descriptor for the opened file
  • Err(Error) - Error if file cannot be opened
§Errors
Source

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 closed
  • Err(Error) - Error closing file
§Errors
Source

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 closed
  • Err(Error) - Error during cleanup
Source

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 file
  • Err(Error) - Error creating duplicate
§Errors
Source

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 to
  • File - File identifier to transfer
  • New_file - Optional specific identifier to use in the new task
§Returns
  • Ok(Local_file_identifier_type) - File identifier in the new task
  • Err(Error) - Error during transfer
§Errors
Source

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 removed
  • Err(Error) - Error during removal
§Errors
Source

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 from
  • Buffer - Buffer to read data into
  • Time_type - Current time for access time updates
§Returns
  • Ok(Size) - Number of bytes actually read
  • Err(Error) - Error during read operation
§Errors
Source

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 to
  • Buffer - Buffer containing data to write
  • Time_type - Current time for modification time updates
§Returns
  • Ok(Size) - Number of bytes actually written
  • Err(Error) - Error during write operation
§Errors
Source

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 directory
  • destination - New path for the file or directory
§Returns
  • Ok(()) - File or directory successfully renamed/moved
  • Err(Error) - Error during rename operation
§Errors
Source

fn set_position( &self, file: LocalFileIdentifier, position: &Position, ) -> Result<Size>

Set the position of the file.

§Errors
  • If the file is not opened (invalid file identifier).
Source

fn flush(&self, file: LocalFileIdentifier) -> Result<()>

Source

fn create_directory( &self, path: &Path, time: Time, user: UserIdentifier, group: GroupIdentifier, ) -> Result<()>

Source

fn open_directory( &self, path: &Path, task: TaskIdentifier, ) -> Result<LocalFileIdentifier>

Source

fn read_directory(&self, file: LocalFileIdentifier) -> Result<Option<Entry>>

Source

fn set_position_directory( &self, file: LocalFileIdentifier, position: Size, ) -> Result<()>

Source

fn get_position_directory(&self, file: LocalFileIdentifier) -> Result<Size>

Source

fn rewind_directory(&self, file: LocalFileIdentifier) -> Result<()>

Source

fn close_directory(&self, file: LocalFileIdentifier) -> Result<()>

Source

fn get_metadata(&self, file: LocalFileIdentifier) -> Result<Metadata>

Source

fn set_metadata_from_path(&self, path: &Path, metadata: &Metadata) -> Result<()>

Source

fn get_metadata_from_path(&self, path: &Path) -> Result<Metadata>

Source

fn get_statistics(&self, file: LocalFileIdentifier) -> Result<Statistics_type>

Source

fn get_mode(&self, file: LocalFileIdentifier) -> Result<Mode>

Implementors§