2022-02-08 04:13:53 -06:00
|
|
|
use alloc::{
|
|
|
|
format,
|
|
|
|
string::{String, ToString},
|
|
|
|
vec::Vec,
|
|
|
|
};
|
2022-02-08 03:01:29 -06:00
|
|
|
use ext2::{
|
2022-02-08 04:13:53 -06:00
|
|
|
fs::{
|
|
|
|
sync::{Inode, Synced},
|
|
|
|
Ext2,
|
|
|
|
},
|
|
|
|
sector::{SectorSize, Size1024},
|
|
|
|
volume::Volume,
|
2022-02-08 03:01:29 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Experimental scratchpad for testing.
|
|
|
|
pub fn scratchpad() {
|
|
|
|
let mut fs = load_fs();
|
|
|
|
|
2022-02-08 04:13:53 -06:00
|
|
|
let root = fs.root_inode();
|
|
|
|
walk(&fs, fs.root_inode(), String::new());
|
2022-02-08 03:01:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
|
|
|
|
let file = include_bytes!("../../userland/root_rs/ext2.img");
|
|
|
|
|
|
|
|
let mut volume = Vec::new();
|
|
|
|
volume.extend_from_slice(file);
|
|
|
|
|
|
|
|
let fs = Synced::<Ext2<Size1024, _>>::new(volume);
|
|
|
|
assert!(
|
|
|
|
fs.is_ok(),
|
|
|
|
"Err({:?})",
|
|
|
|
fs.err().unwrap_or_else(|| unreachable!()),
|
|
|
|
);
|
|
|
|
|
|
|
|
let fs = fs.unwrap();
|
|
|
|
|
|
|
|
fs
|
|
|
|
}
|
|
|
|
|
|
|
|
use genfs::{DirOptions, Fs, OpenOptions};
|
2022-02-08 04:13:53 -06:00
|
|
|
use serde::__private::from_utf8_lossy;
|
|
|
|
|
|
|
|
use crate::{arch::drivers::serial, serial_println};
|
|
|
|
|
|
|
|
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 = 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),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|