diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index e41a2b61..037e57ab 100644 --- a/ableos/src/scratchpad.rs +++ b/ableos/src/scratchpad.rs @@ -1,24 +1,23 @@ -use alloc::{string::String, vec::Vec}; +use alloc::{ + format, + string::{String, ToString}, + vec::Vec, +}; use ext2::{ - fs::{sync::Synced, Ext2}, - sector::Size1024, + fs::{ + sync::{Inode, Synced}, + Ext2, + }, + sector::{SectorSize, Size1024}, + volume::Volume, }; /// 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()); + let root = fs.root_inode(); + walk(&fs, fs.root_inode(), String::new()); } fn load_fs() -> Synced>> { @@ -27,23 +26,6 @@ fn load_fs() -> Synced>> { 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(), @@ -57,3 +39,29 @@ fn load_fs() -> Synced>> { } use genfs::{DirOptions, Fs, OpenOptions}; +use serde::__private::from_utf8_lossy; + +use crate::{arch::drivers::serial, serial_println}; + +fn walk<'vol, S: SectorSize, V: Volume>( + fs: &'vol Synced>, + inode: Inode, + name: String, +) { + inode.directory().map(|dir| { + for entry in dir { + assert!(entry.is_ok()); + let entry = entry.unwrap(); + let entry_name = from_utf8_lossy(&entry.name); + + println!("{}/{} => {}", name, entry_name, entry.inode,); + if entry_name != "." && entry_name != ".." { + walk( + fs, + fs.inode_nth(entry.inode).unwrap(), + format!("{}/{}", name, entry_name), + ); + } + } + }); +} diff --git a/userland/root_rs/ext2.img b/userland/root_rs/ext2.img index 8bd82ba9..bec644f1 100644 Binary files a/userland/root_rs/ext2.img 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 deleted file mode 100644 index de8a3b2b..00000000 --- a/userland/root_rs/mnt/home/able/kernel.md +++ /dev/null @@ -1 +0,0 @@ -Hi there :>$RED$ \ No newline at end of file