Trait FileSystem

Source
pub trait FileSystem: Send + Sync {
    // Required methods
    fn open_root(&self) -> Result<DirectoryNode, FileSystemError>;
    fn read_dir(
        &self,
        inode: &DirectoryNode,
        handler: &mut dyn FnMut(Node) -> DirTraverse,
    ) -> Result<(), FileSystemError>;

    // Provided methods
    fn traverse_dir(
        &self,
        inode: &DirectoryNode,
        matcher: &str,
    ) -> Result<Node, FileSystemError> { ... }
    fn create_node(
        &self,
        _parent: &DirectoryNode,
        _name: &str,
        _attributes: FileAttributes,
    ) -> Result<Node, FileSystemError> { ... }
    fn read_file(
        &self,
        inode: &FileNode,
        position: u64,
        buf: &mut [u8],
        _access_helper: &mut AccessHelper,
    ) -> Result<u64, FileSystemError> { ... }
    fn write_file(
        &self,
        inode: &mut FileNode,
        position: u64,
        buf: &[u8],
        _access_helper: &mut AccessHelper,
    ) -> Result<u64, FileSystemError> { ... }
    fn flush_file(
        &self,
        _inode: &mut FileNode,
        _access_helper: &mut AccessHelper,
    ) -> Result<(), FileSystemError> { ... }
    fn close_file(
        &self,
        _inode: &FileNode,
        _access_helper: AccessHelper,
    ) -> Result<(), FileSystemError> { ... }
    fn set_file_size(
        &self,
        inode: &mut FileNode,
        size: u64,
    ) -> Result<(), FileSystemError> { ... }
    fn unmount(self: Arc<Self>) { ... }
}
Expand description

A filesystem trait, this is the main interface to interact with the filesystem it is used to open files, directories, read and write files, etc.

Required Methods§

Source

fn open_root(&self) -> Result<DirectoryNode, FileSystemError>

Open the root directory of the filesystem

Source

fn read_dir( &self, inode: &DirectoryNode, handler: &mut dyn FnMut(Node) -> DirTraverse, ) -> Result<(), FileSystemError>

Read the directory entries in the inode, and call the handler for each entry The handler should return DirTraverse::Stop to stop the traversal

Provided Methods§

Source

fn traverse_dir( &self, inode: &DirectoryNode, matcher: &str, ) -> Result<Node, FileSystemError>

Traverse the directory in the inode and return the entry with the name matcher Most of the time, no need to implement this, as it is already implemented in the default using FileSystem::read_dir

Source

fn create_node( &self, _parent: &DirectoryNode, _name: &str, _attributes: FileAttributes, ) -> Result<Node, FileSystemError>

Create a new entry in the parent directory with the name and attributes This could be a file or a directory, the attributes should specify the type

Source

fn read_file( &self, inode: &FileNode, position: u64, buf: &mut [u8], _access_helper: &mut AccessHelper, ) -> Result<u64, FileSystemError>

Read the file in the inode at the position and put the data in buf The access_helper is used to store some extra metadata to help the filesystem manage the caches or any extra data it needs.

Source

fn write_file( &self, inode: &mut FileNode, position: u64, buf: &[u8], _access_helper: &mut AccessHelper, ) -> Result<u64, FileSystemError>

Write the file in the inode at the position with the data in buf The access_helper is used to store some extra metadata to help the filesystem manage the caches or any extra data it needs.

Source

fn flush_file( &self, _inode: &mut FileNode, _access_helper: &mut AccessHelper, ) -> Result<(), FileSystemError>

Tells the filesystem to flush the content of this file to disk or to the backing store if it needs to

Source

fn close_file( &self, _inode: &FileNode, _access_helper: AccessHelper, ) -> Result<(), FileSystemError>

Close the file in the inode, this is called when the file is dropped The access_helper is used to store some extra metadata to help the filesystem manage the caches or any extra data it needs.

Source

fn set_file_size( &self, inode: &mut FileNode, size: u64, ) -> Result<(), FileSystemError>

Set the size of the file in the inode to size, this is used to truncate the file or to extend it

Source

fn unmount(self: Arc<Self>)

Unmount the filesystem, this is called before the filesystem is dropped The reason we use this is that we can’t force Drop to be implemented for Arc<dyn FileSystem>, so we have this instead

Implementors§