diff --git a/Cargo.lock b/Cargo.lock index 35c2f6ea2c..6d54ba5939 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4258,6 +4258,15 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "vfs" +version = "0.1.0" +dependencies = [ + "memory", + "path", + "spin 0.9.4", +] + [[package]] name = "vfs_node" version = "0.1.0" diff --git a/kernel/vfs/Cargo.toml b/kernel/vfs/Cargo.toml new file mode 100644 index 0000000000..9e0e293365 --- /dev/null +++ b/kernel/vfs/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "vfs" +version = "0.1.0" +edition = "2021" + +[dependencies] +path = { path = "../path" } +memory = { path = "../memory" } +spin = "0.9.1" diff --git a/kernel/vfs/src/implementor.rs b/kernel/vfs/src/implementor.rs new file mode 100644 index 0000000000..6b0401dd97 --- /dev/null +++ b/kernel/vfs/src/implementor.rs @@ -0,0 +1,47 @@ +use alloc::boxed::Box; + +pub trait FileSystem { + type File: File; + type Directory: Directory; + + fn root(&self) -> Self::Directory; + + // fn to_dyn(self) -> Box, Directory = dyn Directory>>; +} + +static X: Box>> = + todo!(); + +pub trait Node { + // type Directory: Directory; + fn parent(&self); + fn name(&self) -> &str; + // fn as_type(&self) -> NodeType; +} + +pub enum NodeType +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(&self, file_system: T) + where + T: FileSystem; + + fn get(&self, name: &str) -> NodeType; +} + +pub trait File: Node { + // TODO + fn read(&self); +} diff --git a/kernel/vfs/src/lib.rs b/kernel/vfs/src/lib.rs new file mode 100644 index 0000000000..0c3d2f29fa --- /dev/null +++ b/kernel/vfs/src/lib.rs @@ -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, +} \ No newline at end of file diff --git a/kernel/vfs/src/temp.rs b/kernel/vfs/src/temp.rs new file mode 100644 index 0000000000..8236f9865f --- /dev/null +++ b/kernel/vfs/src/temp.rs @@ -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 = Arc>; +// +// impl Node for T +// where +// T: Node, +// { +// type Kind = (); +// +// fn name(&self) -> String { +// todo!() +// } +// +// fn parent(&self) -> Option> { +// todo!() +// } +// +// fn absolute_path(&self) -> PathBuf { +// todo!() +// } +// +// fn as_specific(&self) -> SpecificNodeKind { +// todo!() +// } +// } +// +// pub trait Node +// where +// T: FileSystem, +// { +// type FileSystem: FileSystem = T; +// +// type Kind: NodeKind; +// +// fn name(&self) -> String; +// +// fn parent(&self) -> Option>; +// +// fn absolute_path(&self) -> PathBuf; +// +// fn as_specific(&self) -> SpecificNodeKind; +// } +// +// pub trait FileNode: Node +// where +// T: FileSystem, +// { +// fn as_mapping(&self) -> Result<&MappedPages, &'static str>; +// } +// +// pub trait DirectoryNode: Node +// where +// T: FileSystem, +// { +// fn get(&self, path: &Path) -> Option> +// where +// Kind: NodeKind; +// +// fn insert( +// &mut self, +// node: NodeRef, +// ) -> Result>, &'static str> +// where +// Kind: NodeKind; +// +// fn remove( +// &mut self, +// node: NodeRef, +// ) -> Option> +// where +// Kind: NodeKind; +// +// fn list(&self) -> Vec>; +// } +// +// pub struct Any; +// impl private::Sealed for Any {} +// +// impl NodeKind for Any { +// fn from_any(node: NodeRef) -> Option> +// where +// Fs: FileSystem, +// { +// Some(node) +// } +// } +// +// pub struct Directory; +// +// impl private::Sealed for Directory {} +// impl NodeKind for Directory { +// fn from_any(node: NodeRef) -> Option> +// 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(node: NodeRef) -> Option> +// 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(node: NodeRef) -> Option> +// where +// Fs: FileSystem; +// } +// +// pub enum SpecificNodeKind { +// File(NodeRef), +// Directory(NodeRef), +// } +// +// pub trait FileSystem {} +// +// mod private { +// pub trait Sealed {} +// }