Trait FileOperations

Source
pub trait FileOperations: Send + Sync {
    // Required methods
    fn open(&self, path: &str, flags: u32) -> Result<Arc<dyn FileHandle>>;
    fn read_dir(&self, path: &str) -> Result<Vec<DirectoryEntry>>;
    fn create_file(&self, path: &str, file_type: FileType) -> Result<()>;
    fn create_dir(&self, path: &str) -> Result<()>;
    fn remove(&self, path: &str) -> Result<()>;
    fn metadata(&self, path: &str) -> Result<FileMetadata>;
    fn root_dir(&self) -> Result<Directory<'_>>;
}
Expand description

Trait defining file operations

Required Methods§

Source

fn open(&self, path: &str, flags: u32) -> Result<Arc<dyn FileHandle>>

Open a file

Source

fn read_dir(&self, path: &str) -> Result<Vec<DirectoryEntry>>

Read directory entries

Source

fn create_file(&self, path: &str, file_type: FileType) -> Result<()>

Create a file with the specified type.

§Arguments
  • path - The path to the file to create.
  • file_type - The type of file to create. This can be a regular file, a device file, or other supported types.
§Behavior
  • Regular Files: These are standard files used for storing data. They are created in the filesystem and can be read from or written to using standard file operations.
  • Device Files: These represent hardware devices and are typically used for interacting with device drivers. Creating a device file may involve additional steps, such as associating the file with a specific device driver or hardware resource.
§Side Effects
  • Creating a device file may require elevated permissions or specific system configurations.
  • If a file already exists at the specified path, the function will return an error of type FileSystemErrorKind::AlreadyExists.
§Returns
  • Result<()> - Ok if the file was created successfully, or an error if the operation failed. Errors may include PermissionDenied, InvalidPath, or DeviceError for device files.
Source

fn create_dir(&self, path: &str) -> Result<()>

Create a directory

Source

fn remove(&self, path: &str) -> Result<()>

Remove a file/directory

Source

fn metadata(&self, path: &str) -> Result<FileMetadata>

Get the metadata

Source

fn root_dir(&self) -> Result<Directory<'_>>

Get the root directory of the file system

Implementors§