1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::error::CNFSResult;
use crate::CNFSError::NotImplemented;
use alloc::sync::Arc;

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
/// The Inode type
pub enum InodeType {
    /// Directory
    Dir,
    /// Regular file
    File,
}

/// Trait for inode
pub trait Inode: Send + Sync {
    /// Read data from file to buffer at a given offset
    fn read(&self, _offset: u64, _buffer: &mut [u8]) -> CNFSResult<usize>
    {
        Err(NotImplemented)
    }

    /// Write data from buffer to file at a given offset
    fn write(&self, _offset: u64, _buffer: &[u8]) -> CNFSResult<usize>
    {
        Err(NotImplemented)
    }

    /// Synchronize the data to filesystem.
    fn sync(&self) -> CNFSResult
    {
        Err(NotImplemented)
    }

    /// Lookup a inode with a given name
    fn lookup(&self, _name: &str) -> CNFSResult<InodeRef>
    {
        Err(NotImplemented)
    }

    /// Create a new inode with a given name
    fn create(&self, _name: &str, _inode_type: InodeType) -> CNFSResult<InodeRef>
    {
        Err(NotImplemented)
    }

    /// Remove an inode with a given name
    fn remove(&self, _name: &str) -> CNFSResult
    {
        Err(NotImplemented)
    }
}

/// Inode reference
pub type InodeRef = Arc<dyn Inode>;

/// Trait for filesystem
pub trait FileSystem: Send + Sync {
    /// Returns the root directory of the filesystem
    fn root_inode(&self) -> InodeRef;
}