#partition-table #disk-image #header

gpt

A pure-Rust library to work with GPT partition tables

23 releases (6 stable)

new 4.1.0 Mar 16, 2025
4.0.0 Sep 13, 2024
4.0.0-rc.3 Apr 21, 2024
4.0.0-rc.1 Nov 18, 2023
0.1.7 Apr 24, 2017

#211 in Filesystem

Download history 3301/week @ 2024-11-26 4732/week @ 2024-12-03 4588/week @ 2024-12-10 4279/week @ 2024-12-17 2899/week @ 2024-12-24 4224/week @ 2024-12-31 4687/week @ 2025-01-07 4992/week @ 2025-01-14 5763/week @ 2025-01-21 4548/week @ 2025-01-28 4170/week @ 2025-02-04 3884/week @ 2025-02-11 3850/week @ 2025-02-18 3710/week @ 2025-02-25 3239/week @ 2025-03-04 2642/week @ 2025-03-11

13,952 downloads per month
Used in 20 crates (15 directly)

MIT license

115KB
2K SLoC

gpt

crates.io minimum rust 1.65 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 std::error::Error;

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

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

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

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

    Ok(())
}

Dependencies

~445–600KB
~12K SLoC