use alloc::{ format, string::{String, ToString}, vec::Vec, }; use ext2::{ fs::{ sync::{Inode, Synced}, Ext2, }, sector::{SectorSize, Size1024}, volume::Volume, }; /// Experimental scratchpad for testing. pub fn scratchpad() { let mut fs = load_fs(); let root = fs.root_inode(); walk(&fs, fs.root_inode(), String::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 = Synced::>::new(volume); assert!( fs.is_ok(), "Err({:?})", fs.err().unwrap_or_else(|| unreachable!()), ); let fs = fs.unwrap(); fs } 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), ); } } }); }