diff --git a/Cargo.lock b/Cargo.lock index 39613d3..b26c7fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,7 +24,7 @@ version = "0.1.0" [[package]] name = "okf" version = "0.1.0" -source = "git+https://github.com/obhq/kernel-framework.git#dd2974f037b0bf793a29c374d7ddfc9a43d7a6dd" +source = "git+https://github.com/obhq/kernel-framework.git#42bab58bd5b69a9e3ad12d9cc3af2915d38916ca" dependencies = [ "bitflags", "okf-macros", @@ -33,7 +33,7 @@ dependencies = [ [[package]] name = "okf-1100" version = "0.1.0" -source = "git+https://github.com/obhq/kernel-framework.git#dd2974f037b0bf793a29c374d7ddfc9a43d7a6dd" +source = "git+https://github.com/obhq/kernel-framework.git#42bab58bd5b69a9e3ad12d9cc3af2915d38916ca" dependencies = [ "okf", ] @@ -41,7 +41,7 @@ dependencies = [ [[package]] name = "okf-macros" version = "0.1.0" -source = "git+https://github.com/obhq/kernel-framework.git#dd2974f037b0bf793a29c374d7ddfc9a43d7a6dd" +source = "git+https://github.com/obhq/kernel-framework.git#42bab58bd5b69a9e3ad12d9cc3af2915d38916ca" dependencies = [ "proc-macro2", "quote", diff --git a/dumper/src/main.rs b/dumper/src/main.rs index a39ee08..5337630 100644 --- a/dumper/src/main.rs +++ b/dumper/src/main.rs @@ -6,12 +6,13 @@ use alloc::format; use core::arch::global_asm; use core::cmp::min; use core::ffi::{c_int, CStr}; +use core::hint::unreachable_unchecked; use core::mem::zeroed; use core::panic::PanicInfo; use obfw::FirmwareDump; use okf::fd::{openat, write_all, OpenFlags, AT_FDCWD}; use okf::lock::MtxLock; -use okf::mount::{Filesystem, FsStats, Mount}; +use okf::mount::{Filesystem, FsOps, FsStats, Mount}; use okf::pcpu::Pcpu; use okf::uio::UioSeg; use okf::{kernel, Allocator, Kernel}; @@ -162,12 +163,19 @@ unsafe fn dump_mount(k: K, fd: c_int, mp: *mut K::Mount, lock: MtxLoc // Check filesystem type. let fs = (*mp).fs(); - let name = CStr::from_ptr((*fs).name()).to_bytes(); + let fs = CStr::from_ptr((*fs).name()).to_bytes(); - if !matches!(name, b"exfatfs" | b"ufs") { + if !matches!(fs, b"exfatfs" | b"ufs") { return true; } + // All interested partition should have mounted from as a valid UTF-8. + let stats = (*mp).stats(); + let path = match CStr::from_ptr((*stats).mounted_from()).to_str() { + Ok(v) => v, + Err(_) => return true, + }; + // Write entry type. if !write_dump(k, fd, &[FirmwareDump::<()>::ITEM_PARTITION]) { return false; @@ -179,18 +187,26 @@ unsafe fn dump_mount(k: K, fd: c_int, mp: *mut K::Mount, lock: MtxLoc } // Write filesystem type. - if !write_dump(k, fd, &name.len().to_le_bytes()) || !write_dump(k, fd, name) { + if !write_dump(k, fd, &fs.len().to_le_bytes()) || !write_dump(k, fd, fs) { return false; } // Write mounted from. - let stats = (*mp).stats(); - let path = CStr::from_ptr((*stats).mounted_from()).to_bytes(); - - if !write_dump(k, fd, &path.len().to_le_bytes()) || !write_dump(k, fd, path) { + if !write_dump(k, fd, &path.len().to_le_bytes()) || !write_dump(k, fd, path.as_bytes()) { return false; } + // Get root vnode. + let vp = match (*mp).ops().root(mp, K::LK_SHARED) { + Ok(v) => v, + Err(e) => { + notify(k, &format!("Couldn't get root vnode of {} ({})", path, e)); + return false; + } + }; + + k.vput(vp); + true } @@ -201,7 +217,7 @@ fn write_dump(k: K, fd: c_int, data: &[u8]) -> bool { match unsafe { write_all(k, fd, data, UioSeg::Kernel, td) } { Ok(_) => true, Err(e) => { - let m = format!("Could not write {} ({})", DUMP_FILE, c_int::from(e)); + let m = format!("Couldn't write {} ({})", DUMP_FILE, c_int::from(e)); notify(k, &m); false } @@ -248,7 +264,7 @@ fn notify(k: K, msg: &str) { #[panic_handler] fn panic(_: &PanicInfo) -> ! { // Nothing to do here since we enabled panic_immediate_abort. - loop {} + unsafe { unreachable_unchecked() }; } /// By OSM-Made.