forked from AbleOS/ableos
46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
use ext2::{
|
|
fs::{
|
|
sync::{Inode, Synced},
|
|
Ext2,
|
|
},
|
|
sector::{SectorSize, Size1024},
|
|
volume::Volume,
|
|
};
|
|
|
|
fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
|
|
let mut volume = Vec::new();
|
|
volume.extend_from_slice(include_bytes!("../../../userland/root_rs/ext2.img"));
|
|
|
|
let fs = Synced::<Ext2<Size1024, _>>::new(volume).unwrap();
|
|
|
|
fs
|
|
}
|
|
|
|
// use serde::__private::from_utf8_lossy;
|
|
|
|
pub fn walk<'vol, S: SectorSize, V: Volume<u8, S>>(
|
|
fs: &'vol Synced<Ext2<S, V>>,
|
|
inode: Inode<S, V>,
|
|
name: String,
|
|
) {
|
|
inode.directory().map(|dir| {
|
|
for entry in dir {
|
|
assert!(entry.is_ok());
|
|
let entry = entry.unwrap();
|
|
let entry_name = String::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),
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
lazy_static::lazy_static!(
|
|
pub static ref FILE_SYSTEM:spin::Mutex<Synced<Ext2<Size1024, Vec<u8>>>>= spin::Mutex::new(load_fs());
|
|
);
|