21 releases (4 stable)

new 4.0.0-rc.3 Apr 21, 2024
4.0.0-rc.1 Nov 18, 2023
3.1.0 Jul 4, 2023
3.0.0 Oct 15, 2021
0.1.7 Apr 24, 2017

#34 in Filesystem

Download history 3993/week @ 2024-01-03 4160/week @ 2024-01-10 4602/week @ 2024-01-17 4479/week @ 2024-01-24 3257/week @ 2024-01-31 3159/week @ 2024-02-07 3878/week @ 2024-02-14 4138/week @ 2024-02-21 4209/week @ 2024-02-28 3941/week @ 2024-03-06 4802/week @ 2024-03-13 5166/week @ 2024-03-20 4433/week @ 2024-03-27 5601/week @ 2024-04-03 3512/week @ 2024-04-10 3348/week @ 2024-04-17

17,838 downloads per month
Used in 19 crates (15 directly)

MIT license

110KB
2K SLoC

gpt

crates.io minimum rust 1.63 Documentation

A pure-Rust library to work with GPT partition tables.

gpt provides support for manipulating (R/W) GPT headers and partition tables. It supports any that implements the Read + Write + Seek + Debug traits.

Example

use gpt;

use std::io;

fn main() {
    // Inspect disk image, handling errors.
    if let Err(e) = run() {
        eprintln!("Failed to inspect image: {}", e);
        std::process::exit(1)
    }
}

fn run() -> io::Result<()> {
    // First parameter is target disk image (optional, default: fixtures sample)
    let sample = "tests/fixtures/gpt-linux-disk-01.img".to_string();
    let input = std::env::args().nth(1).unwrap_or(sample);

    // Open disk image.
    let diskpath = std::path::Path::new(&input);
    let cfg = gpt::GptConfig::new().writable(false);
    let disk = cfg.open(diskpath)?;

    // Print GPT layout.
    println!("Disk (primary) header: {:#?}", disk.primary_header());
    println!("Partition layout: {:#?}", disk.partitions());

    Ok(())
}

Dependencies

~575KB
~11K SLoC