forked from theseus-os/Theseus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com>
- Loading branch information
Showing
5 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "vfs" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
path = { path = "../path" } | ||
memory = { path = "../memory" } | ||
spin = "0.9.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use alloc::boxed::Box; | ||
|
||
pub trait FileSystem { | ||
type File: File; | ||
type Directory: Directory<File = Self::File>; | ||
|
||
fn root(&self) -> Self::Directory; | ||
|
||
// fn to_dyn(self) -> Box<dyn FileSystem<File = dyn File<File = dyn File, Directory = dyn Directory>, Directory = dyn Directory>>; | ||
} | ||
|
||
static X: Box<dyn FileSystem<File = dyn File, Directory = dyn Directory<File = dyn File>>> = | ||
todo!(); | ||
|
||
pub trait Node { | ||
// type Directory: Directory; | ||
fn parent(&self); | ||
fn name(&self) -> &str; | ||
// fn as_type(&self) -> NodeType<Self::File, Self::Directory>; | ||
} | ||
|
||
pub enum NodeType<F, D> | ||
where | ||
Self: ?Sized, | ||
{ | ||
File(F), | ||
Directory(D), | ||
} | ||
|
||
pub trait Directory: Node { | ||
type File: File; | ||
|
||
fn create_dir(&self, name: &str); | ||
|
||
fn create_file(&self, name: &str); | ||
|
||
fn mount<T>(&self, file_system: T) | ||
where | ||
T: FileSystem; | ||
|
||
fn get(&self, name: &str) -> NodeType<Self::File, Self>; | ||
} | ||
|
||
pub trait File: Node { | ||
// TODO | ||
fn read(&self); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// The tracking issue (#36887) has been open since 2016; I don't think it's | ||
// getting removed any time soon. | ||
#![allow(invalid_type_param_default)] | ||
#![feature(associated_type_defaults)] | ||
#![no_std] | ||
|
||
mod implementor; | ||
mod temp; | ||
|
||
extern crate alloc; | ||
|
||
use alloc::boxed::Box; | ||
|
||
struct FileSystem { | ||
// inner: Box<dyn implementor::FileSystem>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// #![no_std] | ||
// | ||
// extern crate alloc; | ||
// | ||
// use alloc::{string::String, sync::Arc, vec::Vec}; | ||
// use memory::MappedPages; | ||
// use path::{Path, PathBuf}; | ||
// use spin::Mutex; | ||
// | ||
// pub type NodeRef<Fs, Kind> = Arc<dyn Node<Fs, FileSystem = Fs, Kind = Kind>>; | ||
// | ||
// impl<T, Fs> Node<dyn FileSystem> for T | ||
// where | ||
// T: Node<Fs>, | ||
// { | ||
// type Kind = (); | ||
// | ||
// fn name(&self) -> String { | ||
// todo!() | ||
// } | ||
// | ||
// fn parent(&self) -> Option<NodeRef<Self::FileSystem, Directory>> { | ||
// todo!() | ||
// } | ||
// | ||
// fn absolute_path(&self) -> PathBuf { | ||
// todo!() | ||
// } | ||
// | ||
// fn as_specific(&self) -> SpecificNodeKind<Self::FileSystem> { | ||
// todo!() | ||
// } | ||
// } | ||
// | ||
// pub trait Node<T> | ||
// where | ||
// T: FileSystem, | ||
// { | ||
// type FileSystem: FileSystem = T; | ||
// | ||
// type Kind: NodeKind; | ||
// | ||
// fn name(&self) -> String; | ||
// | ||
// fn parent(&self) -> Option<NodeRef<Self::FileSystem, Directory>>; | ||
// | ||
// fn absolute_path(&self) -> PathBuf; | ||
// | ||
// fn as_specific(&self) -> SpecificNodeKind<Self::FileSystem>; | ||
// } | ||
// | ||
// pub trait FileNode<T>: Node<T> | ||
// where | ||
// T: FileSystem, | ||
// { | ||
// fn as_mapping(&self) -> Result<&MappedPages, &'static str>; | ||
// } | ||
// | ||
// pub trait DirectoryNode<T>: Node<T> | ||
// where | ||
// T: FileSystem, | ||
// { | ||
// fn get<Kind = Any>(&self, path: &Path) -> Option<NodeRef<Self::FileSystem, Kind>> | ||
// where | ||
// Kind: NodeKind; | ||
// | ||
// fn insert<Kind>( | ||
// &mut self, | ||
// node: NodeRef<Self::FileSystem, Kind>, | ||
// ) -> Result<Option<NodeRef<Self::FileSystem, Kind>>, &'static str> | ||
// where | ||
// Kind: NodeKind; | ||
// | ||
// fn remove<Kind>( | ||
// &mut self, | ||
// node: NodeRef<Self::FileSystem, Kind>, | ||
// ) -> Option<NodeRef<Self::FileSystem, Kind>> | ||
// where | ||
// Kind: NodeKind; | ||
// | ||
// fn list(&self) -> Vec<NodeRef<Self::FileSystem, Any>>; | ||
// } | ||
// | ||
// pub struct Any; | ||
// impl private::Sealed for Any {} | ||
// | ||
// impl NodeKind for Any { | ||
// fn from_any<Fs>(node: NodeRef<Fs, Any>) -> Option<NodeRef<Fs, Self>> | ||
// where | ||
// Fs: FileSystem, | ||
// { | ||
// Some(node) | ||
// } | ||
// } | ||
// | ||
// pub struct Directory; | ||
// | ||
// impl private::Sealed for Directory {} | ||
// impl NodeKind for Directory { | ||
// fn from_any<Fs>(node: NodeRef<Fs, Any>) -> Option<NodeRef<Fs, Self>> | ||
// where | ||
// Fs: FileSystem, | ||
// { | ||
// match node.lock().as_specific() { | ||
// SpecificNodeKind::Directory(d) => Some(d), | ||
// _ => None, | ||
// } | ||
// } | ||
// } | ||
// | ||
// pub struct File; | ||
// | ||
// impl private::Sealed for File {} | ||
// impl NodeKind for File { | ||
// fn from_any<Fs>(node: NodeRef<Fs, Any>) -> Option<NodeRef<Fs, Self>> | ||
// where | ||
// Fs: FileSystem, | ||
// { | ||
// match node.lock().as_specific() { | ||
// SpecificNodeKind::File(f) => Some(f), | ||
// _ => None, | ||
// } | ||
// } | ||
// } | ||
// | ||
// pub trait DirectoryGetKind: private::Sealed {} | ||
// | ||
// pub trait NodeKind: private::Sealed { | ||
// fn from_any<Fs>(node: NodeRef<Fs, Any>) -> Option<NodeRef<Fs, Self>> | ||
// where | ||
// Fs: FileSystem; | ||
// } | ||
// | ||
// pub enum SpecificNodeKind<Fs> { | ||
// File(NodeRef<Fs, File>), | ||
// Directory(NodeRef<Fs, Directory>), | ||
// } | ||
// | ||
// pub trait FileSystem {} | ||
// | ||
// mod private { | ||
// pub trait Sealed {} | ||
// } |