#![no_std]
extern crate alloc;
mod macros;
mod structs;
pub mod path;
use alloc::sync::Arc;
use axerrno::{AxError, AxResult, ax_err};
pub use self::structs::{FileSystemInfo, VfsDirEntry, VfsNodeAttr, VfsNodePerm, VfsNodeType};
pub type VfsNodeRef = Arc<dyn VfsNodeOps>;
pub type VfsError = AxError;
pub type VfsResult<T = ()> = AxResult<T>;
pub trait VfsOps: Send + Sync {
fn mount(&self, _path: &str, _mount_point: VfsNodeRef) -> VfsResult {
Ok(())
}
fn umount(&self) -> VfsResult {
Ok(())
}
fn format(&self) -> VfsResult {
ax_err!(Unsupported)
}
fn statfs(&self) -> VfsResult<FileSystemInfo> {
ax_err!(Unsupported)
}
fn root_dir(&self) -> VfsNodeRef;
}
pub trait VfsNodeOps: Send + Sync {
fn open(&self) -> VfsResult {
Ok(())
}
fn release(&self) -> VfsResult {
Ok(())
}
fn get_attr(&self) -> VfsResult<VfsNodeAttr> {
ax_err!(Unsupported)
}
fn read_at(&self, _offset: u64, _buf: &mut [u8]) -> VfsResult<usize> {
ax_err!(InvalidInput)
}
fn write_at(&self, _offset: u64, _buf: &[u8]) -> VfsResult<usize> {
ax_err!(InvalidInput)
}
fn fsync(&self) -> VfsResult {
ax_err!(InvalidInput)
}
fn truncate(&self, _size: u64) -> VfsResult {
ax_err!(InvalidInput)
}
fn parent(&self) -> Option<VfsNodeRef> {
None
}
fn lookup(self: Arc<Self>, _path: &str) -> VfsResult<VfsNodeRef> {
ax_err!(Unsupported)
}
fn create(&self, _path: &str, _ty: VfsNodeType) -> VfsResult {
ax_err!(Unsupported)
}
fn remove(&self, _path: &str) -> VfsResult {
ax_err!(Unsupported)
}
fn read_dir(&self, _start_idx: usize, _dirents: &mut [VfsDirEntry]) -> VfsResult<usize> {
ax_err!(Unsupported)
}
fn rename(&self, _src_path: &str, _dst_path: &str) -> VfsResult {
ax_err!(Unsupported)
}
fn as_any(&self) -> &dyn core::any::Any {
unimplemented!()
}
}
#[doc(hidden)]
pub mod __priv {
pub use alloc::sync::Arc;
pub use axerrno::ax_err;
}