Skip to main content

FileSystemExt

Trait FileSystemExt 

Source
pub trait FileSystemExt: Send + Sync {
    // Provided methods
    fn usage(&self) -> FsUsage { ... }
    fn mkfifo<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _path: &'life1 Path,
        _mode: u32,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn limits(&self) -> FsLimits { ... }
    fn vfs_snapshot(&self) -> Option<VfsSnapshot> { ... }
    fn vfs_restore(&self, _snapshot: &VfsSnapshot) -> Result<()> { ... }
    fn backend_kind(&self) -> &'static str { ... }
}
Expand description

Optional filesystem extensions for resource tracking and special file types.

This trait provides methods that most custom filesystem implementations do not need to override. All methods have sensible defaults:

Built-in implementations (InMemoryFs, OverlayFs, MountableFs) override these to provide real statistics. Custom backends can opt in by implementing just the methods they need.

FileSystemExt is a supertrait of FileSystem, so its methods are available on any dyn FileSystem trait object.

Provided Methods§

Source

fn usage(&self) -> FsUsage

Get current filesystem usage statistics.

Returns total bytes used, file count, and directory count. Used by du and df builtins.

§Default Implementation

Returns zeros. Implementations should override for accurate stats.

Source

fn mkfifo<'life0, 'life1, 'async_trait>( &'life0 self, _path: &'life1 Path, _mode: u32, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a named pipe (FIFO) at the given path.

FIFOs are simulated as buffered files in the virtual filesystem. Reading from a FIFO returns its buffered content, writing appends to it.

§Default Implementation

Returns “not supported” error. Override in implementations that support FIFOs.

Source

fn limits(&self) -> FsLimits

Get filesystem limits.

Returns the configured limits for this filesystem. Used by df builtin to show available space.

§Default Implementation

Returns unlimited limits.

Source

fn vfs_snapshot(&self) -> Option<VfsSnapshot>

Take a snapshot of the filesystem contents for serialization.

Returns None if this filesystem implementation doesn’t support snapshots. The default implementation returns None. InMemoryFs and filesystems wrapping it (e.g. MountableFs, OverlayFs) return Some(snapshot).

Source

fn vfs_restore(&self, _snapshot: &VfsSnapshot) -> Result<()>

Restore filesystem contents from a snapshot.

Returns Err(...) if this filesystem doesn’t support restore, or if the snapshot fails validation (path, size, or count limits). On error the filesystem MUST be left untouched so callers can refuse the restore atomically (issue #1576).

The default implementation returns Err(Unsupported).

Source

fn backend_kind(&self) -> &'static str

Short, stable identifier for this backend kind.

Recorded in snapshot capability fingerprints so a checkout can tell that state captured against, say, an overlay is being restored into a plain in-memory filesystem. Wrappers delegate to what they wrap when the wrapper does not change restore semantics.

These strings are part of the snapshot format: changing one invalidates Strict checkouts of existing snapshots.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§