21 releases (4 stable)

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 4008/week @ 2024-01-25 3098/week @ 2024-02-01 3567/week @ 2024-02-08 3689/week @ 2024-02-15 4391/week @ 2024-02-22 4047/week @ 2024-02-29 4286/week @ 2024-03-07 4772/week @ 2024-03-14 4987/week @ 2024-03-21 4876/week @ 2024-03-28 5176/week @ 2024-04-04 3326/week @ 2024-04-11 4567/week @ 2024-04-18 4832/week @ 2024-04-25 3209/week @ 2024-05-02 2736/week @ 2024-05-09

16,000 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

~425–570KB
~11K SLoC