6 releases

0.1.5 Jan 11, 2021
0.1.4 May 16, 2020
0.1.3 Feb 3, 2020
0.1.2 Oct 27, 2019
0.1.1 Jul 1, 2017

#92 in Filesystem

28 downloads per month
Used in ext4

MIT license

25KB
427 lines

This crate can parse GPT and basic MBR partition tables.

Build status

Documentation and Examples

https://docs.rs/bootsector

Limitations

  • MBR extended partitions are not read (although they are returned, so you could read them yourself). This should be implemented.
  • GPT backup tables are not validated, which is "kinda" required by the spec. This could be implemented, but isn't super important, unless you're doing data recovery.
  • Sector sizes apart from 512 bytes are not well tested. These devices don't seem to exist as of 2017.

MSRV

Rust 1.34 (TryFrom) is supported, and checked by Travis. Updating this is a semver bump.


lib.rs:

Read basic MBR and GPT partition tables from a reader.

Examples

Load MBR or GPT partitions from a reader:

use std::io;
use bootsector::{list_partitions, open_partition, Options, Attributes};

# fn go<R>(mut reader: R) -> io::Result<()>
# where R: io::Read + io::Seek {
// let reader = ...;
let partitions = list_partitions(&mut reader, &Options::default())?;
let part = &partitions[0];

// See what type of partition this is
match part.attributes {
    Attributes::GPT {
        type_uuid,
        ..
    } => println!("gpt: {:?}", type_uuid),
    Attributes::MBR {
        type_code,
        ..
    } => println!("mbr: {:x}", type_code),
}

let part_reader = open_partition(reader, part);
// part_reader.read_exact(...
# Ok(())
# }

Dependencies

~48KB