2022-03-11 13:51:47 -06:00
|
|
|
use ext2::{
|
|
|
|
fs::{
|
|
|
|
sync::{Inode, Synced},
|
|
|
|
Ext2,
|
2022-02-09 07:08:40 -06:00
|
|
|
},
|
2022-03-11 13:51:47 -06:00
|
|
|
sector::{SectorSize, Size1024},
|
|
|
|
volume::Volume,
|
2022-02-09 07:08:40 -06:00
|
|
|
};
|
2022-04-11 15:51:54 -05:00
|
|
|
use spin::Lazy;
|
2022-02-09 07:08:40 -06:00
|
|
|
|
2022-04-11 17:23:11 -05:00
|
|
|
pub static FILE_SYSTEM: Lazy<spin::Mutex<Synced<Ext2<Size1024, Vec<u8>>>>> =
|
|
|
|
Lazy::new(|| spin::Mutex::new(load_fs()));
|
2022-02-09 07:08:40 -06:00
|
|
|
|
2022-04-11 15:51:54 -05:00
|
|
|
pub fn walk<S: SectorSize, V: Volume<u8, S>>(
|
|
|
|
fs: &Synced<Ext2<S, V>>,
|
2022-02-09 07:08:40 -06:00
|
|
|
inode: Inode<S, V>,
|
|
|
|
name: String,
|
|
|
|
) {
|
2022-04-11 15:51:54 -05:00
|
|
|
if let Some(dir) = inode.directory() {
|
2022-02-09 07:08:40 -06:00
|
|
|
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),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
}
|
2022-02-09 07:08:40 -06:00
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
|
2022-04-11 17:23:11 -05:00
|
|
|
fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
|
|
|
|
let mut volume = Vec::new();
|
|
|
|
volume.extend_from_slice(include_bytes!("../../../userland/root_fs/ext2.img"));
|
|
|
|
|
|
|
|
Synced::<Ext2<Size1024, _>>::new(volume).unwrap()
|
|
|
|
}
|