ableos_userland/drivers/vfs/src/main.rs

106 lines
3.1 KiB
Rust

// #![no_std]
#![feature(async_fn_in_trait)]
pub mod cache;
extern crate alloc;
use alloc::vec::Vec;
pub type Path = String;
fn main() {
let vfs = VFS::new();
// TODO: load config for the vfs
// advertise the VFS service
// wait on proccesses to subscribe and send messages
}
// NOTE: in the implementation this should be a basevalue of some randomized value to
// prevent the ability to check how many files are open on the system
pub type FileID = u64;
pub trait FileIO {
// Store the FileID in the VFS to allow multiple programs to have a FileID without conflicting
fn s_open(path: Path) -> Result<FileID, FileIOError>;
async fn a_open(path: Path) -> Result<FileID, FileIOError>;
// Close the file and flush changes to disk
fn s_close(file_id: FileID) -> Result<(), FileIOError>;
async fn a_close(file_id: FileID) -> Result<(), FileIOError>;
// Offset into the file to allow for things like reading a specific value
// Length from the offset
fn s_read(file_id: FileID, offset: usize, length: u64) -> Result<Vec<u8>, FileIOError>;
async fn a_read(file_id: FileID, offset: usize, length: u64) -> Result<Vec<u8>, FileIOError>;
// Offset into the file to allow for things like reading a specific value
fn s_write(file_id: FileID, offset: usize, data: Vec<u8>) -> Result<(), FileIOError>;
async fn a_write(file_id: FileID, offset: usize, data: Vec<u8>) -> Result<(), FileIOError>;
}
pub enum FileIOError {
NoMountPoint,
}
pub struct MountPoint {
mount: Path,
// Use this to send the file requests to the right filesystem driver
filesystem_proc_id: u64,
}
pub struct VFS {
// If a file is used twice move it from first cache to second cache
// This is under the assumption that if you write to a file twice you will write again
first_layer: Cache,
second_layer: Cache,
mount_point_list: Vec<MountPoint>,
}
impl VFS {
fn new() -> Self {
Self {
first_layer: Cache::default(),
second_layer: Cache::default(),
mount_point_list: Vec::new(),
}
}
fn resolve_mountpoint(self, path: Path) -> Result<MountPoint, FileIOError> {
return Err(FileIOError::NoMountPoint);
}
}
impl FileIO for VFS {
fn s_open(path: Path) -> Result<FileID, FileIOError> {
// Break up the path into a mountpoint and a path fragment
todo!()
}
async fn a_open(path: Path) -> Result<FileID, FileIOError> {
todo!()
}
fn s_close(file_id: FileID) -> Result<(), FileIOError> {
todo!()
}
async fn a_close(file_id: FileID) -> Result<(), FileIOError> {
todo!()
}
fn s_read(file_id: FileID, offset: usize, length: u64) -> Result<Vec<u8>, FileIOError> {
todo!()
}
async fn a_read(file_id: FileID, offset: usize, length: u64) -> Result<Vec<u8>, FileIOError> {
todo!()
}
fn s_write(file_id: FileID, offset: usize, data: Vec<u8>) -> Result<(), FileIOError> {
todo!()
}
async fn a_write(file_id: FileID, offset: usize, data: Vec<u8>) -> Result<(), FileIOError> {
todo!()
}
}