gpt-partition 0.1.0

GptPartitionCursor implements the Read + Write + Seek + Debug. It's used for backing up or restoring partition images, such as in embedded upgrades.
Documentation

GptPartitionCursor implements the Read + Write + Seek + Debug.

It's used for backing up or restoring partition images, such as in embedded upgrades.

use gpt_partition::Cursor as GptPartitionCursor;
use std::io::{Seek, Write};

fn main() -> Result<(), Box<dyn std::error::Error>>{
    let path = "/dev/mmcblk0";
    let mut pt = GptPartitionCursor::new(path, "boot").unwrap();
    println!("{:#?}", pt);

    // Read to boot.bin
    let mut fout = std::io::BufWriter::new(std::fs::File::create("boot.bin")?);
    std::io::copy(&mut pt, &mut fout).unwrap();

    // Write to /dev/mmcblk0p1
    let mut fin = std::io::BufReader::new(std::fs::File::open("boot.bin")?);
    pt.seek(std::io::SeekFrom::Start(0)).unwrap();
    let size = std::io::copy(&mut fin, &mut pt).unwrap();
    pt.flush().unwrap();
    println!("{:#?}", size == pt.size);

    //
    // hexdump -C /dev/mmcblk0p1 | head
    //

    Ok(())
}