17 releases (3 stable)

3.0.0 Oct 15, 2021
2.1.0 Oct 15, 2021
2.0.0 Jan 2, 2021
1.0.0 Jan 6, 2020
0.1.7 Apr 24, 2017

#224 in Filesystem

Download history 5561/week @ 2023-02-13 4303/week @ 2023-02-20 5565/week @ 2023-02-27 4720/week @ 2023-03-06 5645/week @ 2023-03-13 3455/week @ 2023-03-20 5997/week @ 2023-03-27 4587/week @ 2023-04-03 5827/week @ 2023-04-10 4311/week @ 2023-04-17 6480/week @ 2023-04-24 3453/week @ 2023-05-01 5299/week @ 2023-05-08 5312/week @ 2023-05-15 6005/week @ 2023-05-22 4679/week @ 2023-05-29

21,571 downloads per month
Used in 11 crates (7 directly)

MIT license

110KB
2K SLoC

gpt

crates.io minimum rust 1.46 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 simplelog::{Config, LevelFilter, SimpleLogger};
use std::io;

fn main() {
    // Setup logging
    let _ = SimpleLogger::init(LevelFilter::Warn, Config::default());

    // 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

~435KB