Crates.io | gpt-parser |
lib.rs | gpt-parser |
version | 0.0.10 |
source | src |
created_at | 2022-05-13 00:13:59.292764 |
updated_at | 2023-12-11 14:59:39.168409 |
description | GUID Partition Table (GPT) read-only parser. Endian aware and usable against no_std+alloc. |
homepage | |
repository | https://gitlab.com/aruiz/gpt-parser-rs |
max_upload_size | |
id | 585550 |
size | 19,562 |
gpt-parser is a Rust library for parsing GPT (GUID Partition Table) partition tables as defined by the UEFI standard. It provides an endian-aware, read-only parser that can be used in both standard and embedded Rust environments. This means you can use it on resource-constrained systems where the standard library is not available.
no_std
To use this library in your Rust project, add it as a dependency in your Cargo.toml
:
[dependencies]
gpt-parser = "*"
In a standard Rust environment (with the standard library), you can use the library as follows:
extern crate gpt_parser;
use gpt_parser::{GPTHeader, LBA512};
fn main() {
// Replace 'disk_image' with your disk image data.
let disk_image: &[u8] = /* Load your disk image here */;
// Create an LBA512 instance from your disk image.
let lba = LBA512::from_slice(&disk_image);
// Parse the GPT header.
let gpt_header = match GPTHeader::parse_gpt_header(&lba) {
Ok(header) => header,
Err(err) => {
eprintln!("Error parsing GPT header: {}", err);
return;
}
};
// Access information about the partitions.
let partitions = gpt_header.get_partitions(&lba);
for partition in partitions {
println!("Partition Type: {:?}", partition.part_type);
println!("Partition UUID: {:?}", partition.id);
println!("First LBA: {:?}", partition.first_lba);
println!("Last LBA: {:?}", partition.last_lba);
println!("Attributes: {:?}", partition.attr);
println!("Name: {:?}", partition.name);
}
}
Replace 'disk_image'
with the binary data of your GPT-formatted disk image.
If you want to use this library in an embedded Rust environment (no standard library), enable the no_std
feature in your project's Cargo.toml
:
[dependencies]
gpt-parser = { version = "*", features = ["no_std"] }
In an embedded environment, you may need to provide your own implementation for certain functionality (e.g., memory allocation) as required by your specific platform.
This library includes a set of tests to ensure its correctness. To run the tests, use the following command:
cargo test
This library is open-source and distributed under the terms of the MIT License.
This library was developed by Alberto Ruiz (aruiz@redhat.com).
Contributions to this project are welcome. Please submit issues and pull requests as needed.
This library is based on the UEFI standard for GPT partition tables and uses various Rust libraries to achieve its functionality.
Enjoy using this library to parse GPT partition tables in your projects! If you encounter any issues or have suggestions for improvement, please don't hesitate to reach out.