Skip to content

Commit

Permalink
Writes end of entries
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Nov 9, 2024
1 parent ee94fbb commit 2d67fbc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
37 changes: 23 additions & 14 deletions dumper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,36 @@ fn run<K: Kernel>(k: K) {

unsafe { k.mtx_unlock_flags(mtx.ptr(), 0, c"".as_ptr(), 0) };

// Flush data.
if ok {
let td = K::Pcpu::curthread();
let errno = unsafe { k.kern_fsync(td, fd.as_raw_fd(), 1) };
if !ok {
return;
}

if errno != 0 {
let m = format!("Couldn't flush data to {} ({})", DUMP_FILE, errno);
notify(k, &m);
return;
}
// Write end entry.
if !write_dump(
k,
fd.as_raw_fd(),
core::slice::from_ref(&FirmwareDump::<()>::ITEM_END),
) {
return;
}

drop(fd);
// Flush data.
let td = K::Pcpu::curthread();
let errno = unsafe { k.kern_fsync(td, fd.as_raw_fd(), 1) };

// Notify the user.
if ok {
notify(k, "Dump completed!");
if errno != 0 {
let m = format!("Couldn't flush data to {} ({})", DUMP_FILE, errno);
notify(k, &m);
return;
}

// Notify the user.
notify(k, "Dump completed!");
}

unsafe fn dump_mount<K: Kernel>(k: K, fd: c_int, _: *mut K::Mount, _: MtxLock<K>) -> bool {
unsafe fn dump_mount<K: Kernel>(k: K, fd: c_int, _: *mut K::Mount, lock: MtxLock<K>) -> bool {
drop(lock);

// Write header.
if !write_dump(
k,
Expand Down
5 changes: 2 additions & 3 deletions obfw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ pub struct FirmwareDump<F> {

impl<F> FirmwareDump<F> {
pub const MAGIC: &'static [u8; 4] = b"\x7FOBF";

const ITEM_END: u8 = 0;
const ITEM_PARTITION: u8 = 1;
pub const ITEM_END: u8 = 0;
pub const ITEM_PARTITION: u8 = 1;

pub fn new(file: F) -> Self {
Self { file }
Expand Down

0 comments on commit 2d67fbc

Please sign in to comment.