1
0
Fork 0
forked from AbleOS/ableos
ableOS_v1Change/ableos/src/scratchpad.rs

60 lines
1.3 KiB
Rust
Raw Normal View History

2022-02-08 03:01:29 -06:00
use alloc::{string::String, vec::Vec};
use ext2::{
fs::{sync::Synced, Ext2},
sector::Size1024,
};
/// Experimental scratchpad for testing.
pub fn scratchpad() {
let mut fs = load_fs();
{
let found = fs.open(b"/home/able/kernel.md", &OpenOptions::new());
assert!(found.is_ok());
let inode = found.unwrap();
let mut vec = Vec::new();
assert!(inode.read_to_end(&mut vec).is_ok());
println!("{}", String::from_utf8_lossy(&vec));
}
// let x = fs.create_dir(b"/config/", &DirOptions::new());
}
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 = Ext2::<Size512, _>::new(volume);
match fs {
Ok(filesystem) => {
info!("{}", filesystem.total_inodes_count());
let vers = filesystem.version();
info!("version: {}.{}", vers.0, vers.1);
}
Err(_) => todo!(),
}
*/
// let abc: Result<, _> = Synced::new(volume);
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};