pub mod bind;
pub mod fdtable;
pub mod file;
pub mod mount;
use async_trait::async_trait;
use std::path::{Path, PathBuf};
use std::result::Result as StdResult;
#[derive(Debug)]
pub enum VfsError {
NotFound,
PermissionDenied,
AlreadyExists,
InvalidInput(String),
IoError(std::io::Error),
Other(String),
}
impl From<std::io::Error> for VfsError {
fn from(err: std::io::Error) -> Self {
VfsError::IoError(err)
}
}
impl std::fmt::Display for VfsError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
VfsError::NotFound => write!(f, "Not found"),
VfsError::PermissionDenied => write!(f, "Permission denied"),
VfsError::AlreadyExists => write!(f, "Already exists"),
VfsError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
VfsError::IoError(err) => write!(f, "IO error: {}", err),
VfsError::Other(msg) => write!(f, "{}", msg),
}
}
}
impl std::error::Error for VfsError {}
pub type VfsResult<T> = StdResult<T, VfsError>;
use file::BoxedFileOps;
#[async_trait]
pub trait Vfs: Send + Sync {
fn translate_path(&self, path: &Path) -> VfsResult<PathBuf>;
fn is_virtual(&self) -> bool {
false
}
async fn open(&self, _path: &Path, _flags: i32, _mode: u32) -> VfsResult<BoxedFileOps> {
Err(VfsError::Other(
"open() not supported by this VFS".to_string(),
))
}
async fn stat(&self, _path: &Path) -> VfsResult<libc::stat> {
Err(VfsError::Other(
"stat() not supported by this VFS".to_string(),
))
}
async fn lstat(&self, _path: &Path) -> VfsResult<libc::stat> {
Err(VfsError::Other(
"lstat() not supported by this VFS".to_string(),
))
}
async fn symlink(&self, _target: &Path, _linkpath: &Path) -> VfsResult<()> {
Err(VfsError::Other(
"symlink() not supported by this VFS".to_string(),
))
}
async fn readlink(&self, _path: &Path) -> VfsResult<PathBuf> {
Err(VfsError::Other(
"readlink() not supported by this VFS".to_string(),
))
}
async fn link(&self, _oldpath: &Path, _newpath: &Path) -> VfsResult<()> {
Err(VfsError::Other(
"link() not supported by this VFS".to_string(),
))
}
}
pub type BoxedVfs = Box<dyn Vfs>;