Trait kernel::fs::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) -> DirTreverse
    ) -> Result<(), FileSystemError>;

    // Provided methods
    fn treverse_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 number_global_refs(&self) -> usize { ... }
    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) -> DirTreverse ) -> Result<(), FileSystemError>

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

Provided Methods§

source

fn treverse_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 number_global_refs(&self) -> usize

The expected number of strong refs in Arc by default This is used to check if the filesystem is still in use before unmounting This is here because for some filesystems, it could be stored globally in some Mutex like /devices this reference should not be counted to know if its still in use

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§