FsInode

Trait FsInode 

Source
pub trait FsInode: Send + Sync {
    // Required methods
    fn path_to_inode(&self, path: &Path) -> Result<u64, FsError>;
    fn inode_to_path(&self, inode: u64) -> Result<PathBuf, FsError>;
    fn lookup(&self, parent_inode: u64, name: &OsStr) -> Result<u64, FsError>;
    fn metadata_by_inode(&self, inode: u64) -> Result<Metadata, FsError>;
}
Expand description

Inode-based filesystem operations for FUSE mounting.

This trait provides the bridge between path-based and inode-based operations. FUSE implementations require efficient inode lookups and path-to-inode mappings.

§Root Inode

The root inode is conventionally 1 (see crate::ROOT_INODE). Implementations should ensure that path “/” maps to inode 1.

§Example

use anyfs_backend::{FsInode, FsError, Metadata, ROOT_INODE};
use std::path::{Path, PathBuf};
use std::ffi::OsStr;

struct MyInodeFs { /* ... */ }

impl FsInode for MyInodeFs {
    fn path_to_inode(&self, path: &Path) -> Result<u64, FsError> {
        // Map path to inode
        if path == Path::new("/") {
            Ok(ROOT_INODE)
        } else {
            // ... lookup in inode table
            Ok(2)
        }
    }

    fn inode_to_path(&self, inode: u64) -> Result<PathBuf, FsError> {
        // Map inode back to path
        if inode == ROOT_INODE {
            Ok(PathBuf::from("/"))
        } else {
            // ... lookup in path table
            Ok(PathBuf::from("/file.txt"))
        }
    }

    fn lookup(&self, _parent_inode: u64, _name: &OsStr) -> Result<u64, FsError> {
        // Find child inode by name within parent directory
        Ok(2)
    }

    fn metadata_by_inode(&self, _inode: u64) -> Result<Metadata, FsError> {
        // Get metadata directly by inode
        Ok(Metadata::default())
    }
}

Required Methods§

Source

fn path_to_inode(&self, path: &Path) -> Result<u64, FsError>

Convert a path to its inode number.

§Arguments
  • path - The filesystem path to look up
§Returns

The inode number for the path.

§Errors
Source

fn inode_to_path(&self, inode: u64) -> Result<PathBuf, FsError>

Convert an inode number back to its path.

§Arguments
  • inode - The inode number to look up
§Returns

The filesystem path for the inode.

§Errors
§Note

For filesystems with hard links, an inode may have multiple paths. This method returns one valid path (typically the canonical one).

Source

fn lookup(&self, parent_inode: u64, name: &OsStr) -> Result<u64, FsError>

Look up a child entry within a parent directory by name.

This is the core FUSE lookup operation. Given a parent directory’s inode and a child name, return the child’s inode.

§Arguments
  • parent_inode - The inode of the parent directory
  • name - The name of the child entry to find
§Returns

The inode number of the child entry.

§Errors
Source

fn metadata_by_inode(&self, inode: u64) -> Result<Metadata, FsError>

Get metadata for an inode directly.

This is more efficient than inode_to_path + metadata for FUSE operations, as it avoids path string manipulation.

§Arguments
  • inode - The inode number to get metadata for
§Returns

The metadata for the inode.

§Errors

Implementors§