From a78570b85fd0fa6678798d4e9df433fd5d89b391 Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 8 Feb 2022 04:13:53 -0600 Subject: [PATCH] rootfs changes --- ableos/src/scratchpad.rs | 70 +++++++++++++---------- userland/root_rs/ext2.img | Bin 4194304 -> 4194304 bytes userland/root_rs/mnt/home/able/kernel.md | 1 - 3 files changed, 39 insertions(+), 32 deletions(-) delete mode 100644 userland/root_rs/mnt/home/able/kernel.md diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index e41a2b6..037e57a 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 8bd82ba98d8500f6217f6ff67db231c4668e7e1f..bec644f190645c71e9fca9aab85c7d80ea961aa4 100644 GIT binary patch delta 874 zcmd5&&rcIU6yBM>;iP^5nsPzzZi2CUVhJlRDehHsC+tB;U-u?|t8UZ^pK5ZcBXdkvHjA zl*8&EUF?57%hRgTY_9xd&K%7%X4csbuLz$f=|6P*VtTO>d+;XCsXDP5t;9Z6gWk1r zVBBfOIA8NR_M3es~}R#7PJhq94KsF#vH2!VeLE z7=$N-?W%O2?7Tw!+x81gFYuGaKxg#a@Qf|GdZ-k45>=C}0GR>z( zDdT>MYHpgAmhX=Gcd*ub+J%n|+IghgO;Mat@omA0h_CA1R$YOd_NX(F!B4^Nv zK_9@tW0+wg1`_@vp21GOz1K>1KG$`%Yq$*~kcn8m!Bw5y0 z{s~rzxhHpOO@x`VHrIZq)lu^Qza!Lgy zLUAaSlqyO!rG`>ViC#6$RED$ \ No newline at end of file