axfs_ng_vfs/
fs.rs

1use alloc::sync::Arc;
2
3use inherit_methods_macro::inherit_methods;
4
5use crate::{DirEntry, VfsResult};
6
7pub struct StatFs {
8    pub fs_type: u32,
9    pub block_size: u32,
10    pub blocks: u64,
11    pub blocks_free: u64,
12    pub blocks_available: u64,
13
14    pub file_count: u64,
15    pub free_file_count: u64,
16
17    pub name_length: u32,
18    pub fragment_size: u32,
19    pub mount_flags: u32,
20}
21
22/// Trait for filesystem operations
23pub trait FilesystemOps: Send + Sync {
24    /// Gets the name of the filesystem
25    fn name(&self) -> &str;
26
27    /// Gets the root directory entry of the filesystem
28    fn root_dir(&self) -> DirEntry;
29
30    /// Returns statistics about the filesystem
31    fn stat(&self) -> VfsResult<StatFs>;
32
33    /// Flushes the filesystem, ensuring all data is written to disk
34    fn flush(&self) -> VfsResult<()> {
35        Ok(())
36    }
37}
38
39#[derive(Clone)]
40pub struct Filesystem {
41    ops: Arc<dyn FilesystemOps>,
42}
43
44#[inherit_methods(from = "self.ops")]
45impl Filesystem {
46    pub fn name(&self) -> &str;
47
48    pub fn root_dir(&self) -> DirEntry;
49
50    pub fn stat(&self) -> VfsResult<StatFs>;
51}
52
53impl Filesystem {
54    pub fn new(ops: Arc<dyn FilesystemOps>) -> Self {
55        Self { ops }
56    }
57}