1
0
Fork 0
forked from AbleOS/ableos

rootfs changes

This commit is contained in:
Able 2022-02-08 04:13:53 -06:00
parent f61d4fe9e7
commit a78570b85f
3 changed files with 39 additions and 32 deletions

View file

@ -1,24 +1,23 @@
use alloc::{string::String, vec::Vec}; use alloc::{
format,
string::{String, ToString},
vec::Vec,
};
use ext2::{ use ext2::{
fs::{sync::Synced, Ext2}, fs::{
sector::Size1024, sync::{Inode, Synced},
Ext2,
},
sector::{SectorSize, Size1024},
volume::Volume,
}; };
/// Experimental scratchpad for testing. /// Experimental scratchpad for testing.
pub fn scratchpad() { pub fn scratchpad() {
let mut fs = load_fs(); let mut fs = load_fs();
{
let found = fs.open(b"/home/able/kernel.md", &OpenOptions::new());
assert!(found.is_ok()); let root = fs.root_inode();
let inode = found.unwrap(); walk(&fs, fs.root_inode(), String::new());
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>>> { fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
@ -27,23 +26,6 @@ fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
let mut volume = Vec::new(); let mut volume = Vec::new();
volume.extend_from_slice(file); 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); let fs = Synced::<Ext2<Size1024, _>>::new(volume);
assert!( assert!(
fs.is_ok(), fs.is_ok(),
@ -57,3 +39,29 @@ fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {
} }
use genfs::{DirOptions, Fs, OpenOptions}; use genfs::{DirOptions, Fs, OpenOptions};
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),
);
}
}
});
}

Binary file not shown.

View file

@ -1 +0,0 @@
Hi there :>$RED$