pub trait VfsNode: Send + Sync {
Show 16 methods
// Required methods
fn node_type(&self) -> NodeType;
fn read(
&self,
offset: usize,
buffer: &mut [u8],
) -> Result<usize, KernelError>;
fn write(&self, offset: usize, data: &[u8]) -> Result<usize, KernelError>;
fn metadata(&self) -> Result<Metadata, KernelError>;
fn readdir(&self) -> Result<Vec<DirEntry>, KernelError>;
fn lookup(&self, name: &str) -> Result<Arc<dyn VfsNode>, KernelError>;
fn create(
&self,
name: &str,
permissions: Permissions,
) -> Result<Arc<dyn VfsNode>, KernelError>;
fn mkdir(
&self,
name: &str,
permissions: Permissions,
) -> Result<Arc<dyn VfsNode>, KernelError>;
fn unlink(&self, name: &str) -> Result<(), KernelError>;
fn truncate(&self, size: usize) -> Result<(), KernelError>;
// Provided methods
fn link(
&self,
_name: &str,
_target: Arc<dyn VfsNode>,
) -> Result<(), KernelError> { ... }
fn symlink(
&self,
_name: &str,
_target: &str,
) -> Result<Arc<dyn VfsNode>, KernelError> { ... }
fn readlink(&self) -> Result<String, KernelError> { ... }
fn chmod(&self, _permissions: Permissions) -> Result<(), KernelError> { ... }
fn poll_readiness(&self) -> u16 { ... }
fn as_any(&self) -> Option<&dyn Any> { ... }
}Expand description
VFS node operations trait
Required Methods§
Sourcefn node_type(&self) -> NodeType
fn node_type(&self) -> NodeType
Node type query (also serves as vtable slot padding for AArch64)
Sourcefn read(&self, offset: usize, buffer: &mut [u8]) -> Result<usize, KernelError>
fn read(&self, offset: usize, buffer: &mut [u8]) -> Result<usize, KernelError>
Read data from the node
Sourcefn write(&self, offset: usize, data: &[u8]) -> Result<usize, KernelError>
fn write(&self, offset: usize, data: &[u8]) -> Result<usize, KernelError>
Write data to the node
Sourcefn metadata(&self) -> Result<Metadata, KernelError>
fn metadata(&self) -> Result<Metadata, KernelError>
Get metadata for the node
Sourcefn readdir(&self) -> Result<Vec<DirEntry>, KernelError>
fn readdir(&self) -> Result<Vec<DirEntry>, KernelError>
List directory entries (if this is a directory)
Sourcefn lookup(&self, name: &str) -> Result<Arc<dyn VfsNode>, KernelError>
fn lookup(&self, name: &str) -> Result<Arc<dyn VfsNode>, KernelError>
Look up a child node by name (if this is a directory)
Sourcefn create(
&self,
name: &str,
permissions: Permissions,
) -> Result<Arc<dyn VfsNode>, KernelError>
fn create( &self, name: &str, permissions: Permissions, ) -> Result<Arc<dyn VfsNode>, KernelError>
Create a new file in this directory
Sourcefn mkdir(
&self,
name: &str,
permissions: Permissions,
) -> Result<Arc<dyn VfsNode>, KernelError>
fn mkdir( &self, name: &str, permissions: Permissions, ) -> Result<Arc<dyn VfsNode>, KernelError>
Create a new directory in this directory
Sourcefn unlink(&self, name: &str) -> Result<(), KernelError>
fn unlink(&self, name: &str) -> Result<(), KernelError>
Remove a file or empty directory
Sourcefn truncate(&self, size: usize) -> Result<(), KernelError>
fn truncate(&self, size: usize) -> Result<(), KernelError>
Truncate the file to the specified size
Provided Methods§
Sourcefn link(
&self,
_name: &str,
_target: Arc<dyn VfsNode>,
) -> Result<(), KernelError>
fn link( &self, _name: &str, _target: Arc<dyn VfsNode>, ) -> Result<(), KernelError>
Create a hard link to this node
Sourcefn symlink(
&self,
_name: &str,
_target: &str,
) -> Result<Arc<dyn VfsNode>, KernelError>
fn symlink( &self, _name: &str, _target: &str, ) -> Result<Arc<dyn VfsNode>, KernelError>
Create a symbolic link in this directory.
Creates a new symlink entry named name in this directory node
that points to target. The target path is stored as the symlink’s
data content and is not validated (it may be relative or absolute,
and the target need not exist).
§Default Implementation
Returns NotImplemented for filesystems that do not support
symbolic links (e.g., DevFS, ProcFS). Filesystems that support
symlinks (e.g., RamFS, BlockFS) override this method.
§Arguments
name: The name of the symlink entry to create in this directory.target: The target path that the symlink points to.
§Returns
An Arc<dyn VfsNode> representing the newly created symlink node.
Sourcefn readlink(&self) -> Result<String, KernelError>
fn readlink(&self) -> Result<String, KernelError>
Read the target of a symbolic link.
If this node is a symbolic link, returns the target path as a
String. The target is the raw path stored when the symlink was
created and is not resolved or canonicalized.
§Default Implementation
Returns NotImplemented for filesystem nodes that are not symbolic
links or for filesystems that do not support symlinks. Callers
should check node_type() == NodeType::Symlink before calling, or
handle the error.
§Returns
Ok(String): The symlink target path.Err(NotImplemented): This node is not a symlink or the filesystem does not support readlink.Err(FsError(NotASymlink)): The node exists but is not a symlink (used by BlockFS for type-checked readlink).
Sourcefn chmod(&self, _permissions: Permissions) -> Result<(), KernelError>
fn chmod(&self, _permissions: Permissions) -> Result<(), KernelError>
Change permissions on this node
Sourcefn poll_readiness(&self) -> u16
fn poll_readiness(&self) -> u16
Poll readiness for I/O multiplexing (poll/epoll).
Returns a bitmask of ready events using POLL* constants:
- bit 0 (POLLIN=1): readable without blocking
- bit 2 (POLLOUT=4): writable without blocking
- bit 3 (POLLERR=8): error condition
- bit 4 (POLLHUP=16): hangup (peer closed)
Default: regular files are always readable and writable. Pipe nodes override this to check actual buffer state.
Sourcefn as_any(&self) -> Option<&dyn Any>
fn as_any(&self) -> Option<&dyn Any>
Downcast to &dyn core::any::Any for type-specific operations.
Used by syscall handlers that need to extract implementation-specific
state from a VfsNode (e.g., timerfd_settime needs the internal timer
ID from a TimerFdNode). Default returns None; only nodes that need
downcasting override this.