Giter Club home page Giter Club logo

gpt's Introduction

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(())
}

gpt's People

Contributors

4ldo2 avatar berke avatar calebccff avatar cecton avatar cholcombe973 avatar dependabot-preview[bot] avatar dependabot-support avatar erichdongubler avatar gradzik avatar kevinhoffman avatar lucab avatar mzhong1 avatar oldgalileo avatar quyzi avatar soerenmeier avatar

gpt's Issues

Add calculation for minimum disk length

Minimum disk length check looks something like:

const PARTITION_ENTRIES_MIN_BYTES: u64 = 2u64.pow(14);

fn minimum_disk_length_bytes(lb_size: LogicalBlockSize, pmbr: bool) -> u32 {
    let part_entries_min_blocks: u32 =
        (PARTITION_ENTRIES_MIN_BYTES / Into::<u64>::into(lb_size)) as u32;

    let size = if pmbr { 1 } else { 0 };
    return size + 2 // primary and backup headers
        + (2 * part_entries_min_blocks);
}

Helper for calculating disk size

Given lb_size: LogicalBlockSize, pmbr: bool, partitions: Vec<u64>, and alignment: Option<u64>, it should be straight forward to calculate the minimum disk size necessary to host the number of partitions. This would, at minimum, be useful for integration testing against this library to reduce code duplication.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.