From ca80c178195abf6becdba25995a42bf381e7861f Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 9 May 2023 01:07:52 -0500 Subject: [PATCH] prelim VFS work --- Cargo.lock | 4 ++++ Cargo.toml | 2 ++ drivers/vfs/Cargo.toml | 9 +++++++++ drivers/vfs/src/main.rs | 18 ++++++++++++++++++ libraries/os_core/src/lib.rs | 4 ++++ libraries/std/src/io.rs | 9 --------- libraries/std/src/lib.rs | 2 ++ libraries/std/src/path.rs | 18 ++++++++++++++++++ libraries/std/src/prelude/rust_2021/mod.rs | 3 +++ 9 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 drivers/vfs/Cargo.toml create mode 100644 drivers/vfs/src/main.rs create mode 100644 libraries/std/src/path.rs diff --git a/Cargo.lock b/Cargo.lock index 05d0c4b..1f426fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -644,6 +644,10 @@ dependencies = [ "serde", ] +[[package]] +name = "vfs" +version = "0.1.0" + [[package]] name = "vgable" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 0297fd4..5f125ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,8 @@ members = [ "drivers/graphics/novideo", "drivers/graphics/vgable", + "drivers/vfs", + "drivers/keyboards/ps2_keyboard", "drivers/mice/ps2_mouse", diff --git a/drivers/vfs/Cargo.toml b/drivers/vfs/Cargo.toml new file mode 100644 index 0000000..1ebe67e --- /dev/null +++ b/drivers/vfs/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "vfs" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +# std = { path = "../../libraries/std" } diff --git a/drivers/vfs/src/main.rs b/drivers/vfs/src/main.rs new file mode 100644 index 0000000..f533fd9 --- /dev/null +++ b/drivers/vfs/src/main.rs @@ -0,0 +1,18 @@ +// #![no_std] + +use std::path::Path; +// use std::prelude::rust_2021::alloc; +extern crate alloc; +use alloc::vec::Vec; + +fn main() {} + +pub type File = Vec; +// TODO: implement better VFS api +pub trait FileIO { + fn read(file: &mut File, file_address: u64, read_length: u64); + fn write(file: &mut File, file_address: u64, dest_ptr: u64, src_len: usize); + fn open(path: Path); + fn close(file: &mut File); +} +pub enum FileError {} diff --git a/libraries/os_core/src/lib.rs b/libraries/os_core/src/lib.rs index b26d894..d630f84 100644 --- a/libraries/os_core/src/lib.rs +++ b/libraries/os_core/src/lib.rs @@ -24,3 +24,7 @@ pub struct Result { pub ok: T, pub err: ExternErrors, } + +pub struct Path { + parts: String, +} diff --git a/libraries/std/src/io.rs b/libraries/std/src/io.rs index b7092ce..aa3981f 100644 --- a/libraries/std/src/io.rs +++ b/libraries/std/src/io.rs @@ -1,12 +1,3 @@ pub enum IOErrors { UnknownError, } - -// pub struct Port { -// inner: T, -// } -// impl Port { -// pub fn read(&self) -> Result { -// Ok(self.inner) -// } -// } diff --git a/libraries/std/src/lib.rs b/libraries/std/src/lib.rs index b781d37..4ec7c26 100644 --- a/libraries/std/src/lib.rs +++ b/libraries/std/src/lib.rs @@ -23,6 +23,8 @@ pub mod prelude; use versioning::Version; +pub mod path; + pub const VERSION: Version = Version::new(0, 1, 0); // extern crate alloc; diff --git a/libraries/std/src/path.rs b/libraries/std/src/path.rs new file mode 100644 index 0000000..89840db --- /dev/null +++ b/libraries/std/src/path.rs @@ -0,0 +1,18 @@ +use alloc::string::{String, ToString}; + +pub struct Path { + pub path: Vec, +} +impl Path { + pub fn new(path: String) -> Self { + let mut path_vec_string = alloc::vec![]; + + for part in path.split(&['\\', '/'][..]) { + path_vec_string.push(part.to_string()); + } + + Path { + path: path_vec_string, + } + } +} diff --git a/libraries/std/src/prelude/rust_2021/mod.rs b/libraries/std/src/prelude/rust_2021/mod.rs index 32d3435..bd6db04 100644 --- a/libraries/std/src/prelude/rust_2021/mod.rs +++ b/libraries/std/src/prelude/rust_2021/mod.rs @@ -6,3 +6,6 @@ pub use crate::print_char; pub use core::panic; pub use versioning; + +extern crate alloc; +pub use alloc::vec::Vec;