diff --git a/ableos/Cargo.lock b/ableos/Cargo.lock index 4210efd..a8ffee7 100644 --- a/ableos/Cargo.lock +++ b/ableos/Cargo.lock @@ -30,8 +30,10 @@ dependencies = [ "acpi", "bootloader", "cpuio", + "ext2", "externc-libm", "facepalm", + "genfs", "hashbrown", "lazy_static", "linked_list_allocator", @@ -46,7 +48,7 @@ dependencies = [ "serde_json", "shadeable", "smoltcp", - "spin", + "spin 0.5.2", "uart_16550", "unicode-width", "vga", @@ -178,6 +180,17 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +[[package]] +name = "ext2" +version = "0.1.1" +source = "git+https://git.ablecorp.us/able/ext2-rs.git#220f66a156bfd5033eecac20372368860749c304" +dependencies = [ + "bitflags", + "genfs", + "rlibc", + "spin 0.9.2", +] + [[package]] name = "externc-libm" version = "0.1.0" @@ -199,6 +212,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e" +[[package]] +name = "genfs" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65b9e52a0ffd4c2f11f9f84e8885a40cb99f490971eee78bbd7ddffd6ac023d6" + [[package]] name = "getrandom" version = "0.2.4" @@ -240,7 +259,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" dependencies = [ - "spin", + "spin 0.5.2", ] [[package]] @@ -489,6 +508,12 @@ dependencies = [ "syn", ] +[[package]] +name = "rlibc" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe" + [[package]] name = "rsdp" version = "2.0.0" @@ -590,6 +615,15 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spin" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" +dependencies = [ + "lock_api", +] + [[package]] name = "spinning_top" version = "0.2.4" diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index eb4db11..5c74b9e 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -57,6 +57,8 @@ unicode-width = "0.1.7" picorand = "*" # watson = "0.4" +genfs = "0.1.0" + acpi = "4.1.0" @@ -94,6 +96,8 @@ features = ["log", "proto-ipv4"] [dependencies.y-compositor-protocol] git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git" +[dependencies.ext2] +git = "https://git.ablecorp.us:443/able/ext2-rs.git" [dependencies.shadeable] path = "../shadeable" diff --git a/ableos/src/ext2fs/mod.rs b/ableos/src/ext2fs/mod.rs deleted file mode 100644 index 85c0f77..0000000 --- a/ableos/src/ext2fs/mod.rs +++ /dev/null @@ -1,93 +0,0 @@ -use alloc::string::{String, ToString}; - -pub enum FileSystemStates { - Null = 0, - Clean = 1, - Error = 2, -} - -pub enum ErrorHandleMethod { - Null = 0, - Ignore = 1, - RemountFileSystem = 2, - Panic = 3, -} - -/// Used by ableOS to identify the creator of the file system -#[repr(C)] -pub enum CreatorOperatingSystemID { - Linux = 0, - GNU_HURD = 1, - // 2 MASIX (an operating system developed by Rémy Card, one of the developers of ext2) - MASIX = 2, - // 3 FreeBSD - FreeBsd = 3, - // 4 Other "Lites" (BSD4.4-Lite derivatives such as NetBSD, OpenBSD, XNU/Darwin, etc.) - LITES = 4, - - AbleOS = 5, - Unknown = 6, -} - -impl CreatorOperatingSystemID { - pub fn to_string(&self) -> String { - match self { - &CreatorOperatingSystemID::Linux => "Linux".to_string(), - &CreatorOperatingSystemID::GNU_HURD => "GNU_HURD".to_string(), - &CreatorOperatingSystemID::MASIX => "MASIX".to_string(), - &CreatorOperatingSystemID::FreeBsd => "FREE_BSD".to_string(), - &CreatorOperatingSystemID::LITES => "LITES".to_string(), - &CreatorOperatingSystemID::AbleOS => "ABLEOS".to_string(), - &CreatorOperatingSystemID::Unknown => "Unknown".to_string(), - } - } - pub fn match_to_int(id: CreatorOperatingSystemID) -> u8 { - match id { - Self::Linux => 0, - Self::GNU_HURD => 1, - Self::MASIX => 2, - Self::FreeBsd => 3, - Self::LITES => 4, - Self::AbleOS => 5, - _ => 6, - } - } - pub fn match_to_enum(id: u8) -> CreatorOperatingSystemID { - match id { - 0 => Self::Linux, - 1 => Self::GNU_HURD, - 2 => Self::MASIX, - 3 => Self::FreeBsd, - 4 => Self::LITES, - 5 => Self::AbleOS, - _ => Self::Unknown, - } - } -} - -/* -0x001 00001 Other—execute permission -0x002 00002 Other—write permission -0x004 00004 Other—read permission -0x008 00010 Group—execute permission -0x010 00020 Group—write permission -0x020 00040 Group—read permission -0x040 00100 User—execute permission -0x080 00200 User—write permission -0x100 00400 User—read permission -0x200 01000 Sticky Bit -0x400 02000 Set group ID -0x800 04000 Set user ID*/ -pub struct FilePermissions(pub u16); - -/* -0x1000 FIFO -0x2000 Character device -0x4000 Directory -0x6000 Block device -0x8000 Regular file -0xA000 Symbolic link -0xC000 Unix socket -*/ - -pub struct InodeType(pub u16); diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 861fb83..b56f07a 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -2,6 +2,8 @@ use acpi::AcpiTables; +use crate::scratchpad; + use { crate::{ arch::{init, sloop}, @@ -83,7 +85,7 @@ pub fn kernel_main() -> ! { } start_facepalm(); - + scratchpad(); sloop() } diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 0ecab3d..6e6a35c 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -32,7 +32,6 @@ pub mod arch; #[macro_use] pub mod print; -pub mod ext2fs; #[macro_use] pub extern crate log; @@ -91,3 +90,6 @@ pub mod tests; pub use tests::*; pub mod syscalls; pub use syscalls::*; + +pub mod scratchpad; +pub use scratchpad::*; diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs new file mode 100644 index 0000000..e41a2b6 --- /dev/null +++ b/ableos/src/scratchpad.rs @@ -0,0 +1,59 @@ +use alloc::{string::String, vec::Vec}; +use ext2::{ + fs::{sync::Synced, Ext2}, + sector::Size1024, +}; + +/// Experimental scratchpad for testing. +pub fn scratchpad() { + let mut fs = load_fs(); + { + let found = fs.open(b"/home/able/kernel.md", &OpenOptions::new()); + + assert!(found.is_ok()); + let inode = found.unwrap(); + let mut vec = Vec::new(); + assert!(inode.read_to_end(&mut vec).is_ok()); + + println!("{}", String::from_utf8_lossy(&vec)); + } + + // let x = fs.create_dir(b"/config/", &DirOptions::new()); +} + +fn load_fs() -> Synced>> { + let file = include_bytes!("../../userland/root_rs/ext2.img"); + + let mut volume = Vec::new(); + volume.extend_from_slice(file); + + /* + let fs = Ext2::::new(volume); + + match fs { + Ok(filesystem) => { + info!("{}", filesystem.total_inodes_count()); + + let vers = filesystem.version(); + info!("version: {}.{}", vers.0, vers.1); + } + + Err(_) => todo!(), + } + + */ + // let abc: Result<, _> = Synced::new(volume); + + let fs = Synced::>::new(volume); + assert!( + fs.is_ok(), + "Err({:?})", + fs.err().unwrap_or_else(|| unreachable!()), + ); + + let fs = fs.unwrap(); + + fs +} + +use genfs::{DirOptions, Fs, OpenOptions}; diff --git a/userland/root_rs/ext2.img b/userland/root_rs/ext2.img new file mode 100644 index 0000000..8bd82ba Binary files /dev/null and b/userland/root_rs/ext2.img differ diff --git a/userland/root_rs/mnt/home/able/kernel.md b/userland/root_rs/mnt/home/able/kernel.md new file mode 100644 index 0000000..de8a3b2 --- /dev/null +++ b/userland/root_rs/mnt/home/able/kernel.md @@ -0,0 +1 @@ +Hi there :>$RED$ \ No newline at end of file