1
0
Fork 0
forked from koniifer/ableos
ableos-framebuffer/ableos/src/filesystem/mod.rs

49 lines
1.3 KiB
Rust
Raw Normal View History

use {
alloc::{format, string::String, vec::Vec},
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());
);