Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com>
  • Loading branch information
tsoutsman committed Dec 12, 2023
1 parent 6fd531f commit 3ffb908
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions kernel/vfs/Cargo.toml
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"
47 changes: 47 additions & 0 deletions kernel/vfs/src/implementor.rs
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);
}
16 changes: 16 additions & 0 deletions kernel/vfs/src/lib.rs
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>,
}
143 changes: 143 additions & 0 deletions kernel/vfs/src/temp.rs
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 {}
// }

0 comments on commit 3ffb908

Please sign in to comment.