gpt

Crates.iogpt
lib.rsgpt
version4.0.0
sourcesrc
created_at2017-04-14 19:44:20.604648
updated_at2024-09-13 16:01:17.541565
descriptionA pure-Rust library to work with GPT partition tables.
homepage
repositoryhttps://github.com/Quyzi/gpt
max_upload_size
id10604
size140,743
Sören Meier (soerenmeier)

documentation

https://docs.rs/gpt

README

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(())
}
Commit count: 207

cargo fmt