Crate ape_mbr

Crate ape_mbr 

Source
Expand description

MIT License Crates.io Documentation APE

§simple crate to interface between a disk and it’s partitions

This crate is especially designed to provide an interface between a disk and a file system library, where both are able to implement embedded_io.

Dead simple, as it should be.

§Usage

This crate can be used by adding ape-mbr to the dependencies in your project’s Cargo.toml.

[dependencies]
ape-mbr = "0.1.0"

§Examples

Here’s ape-mbr being coupled with ape-fatfs

use std::io::prelude::*;
use ape_fatfs::{
    fs::{
        FsOptions,
        FileSystem,
    },
    io::{
        StdIoWrapper
    }
};

use ape_mbr::{
    PartitionId,
    MBR,
};

fn main() {
    // Initialize the MBR
    let img_file = std::fs::OpenOptions::new().read(true).write(true)
        .open("test.img").unwrap();

    let img_file = StdIoWrapper::new(img_file);
    
    let mut mbr = MBR::new(img_file).unwrap();
    let mut p1 = mbr.get_partition(PartitionId::One).unwrap();
     
    let fs = FileSystem::new(p1, FsOptions::new()).unwrap();
    let root_dir = fs.root_dir();

    // Write a file
    root_dir.create_dir("foo").unwrap();
    let mut file = root_dir.create_file("foo/hello.txt").unwrap();
    file.truncate().unwrap();
    file.write_all(b"Hello World!").unwrap();

    // Read a directory
    let dir = root_dir.open_dir("foo").unwrap();
    for r in dir.iter() {
        let entry = r.unwrap();
        println!("{}", entry.file_name());
    }
}

Modules§

types
Types of partitions that are detectable through the SystemID field.

Structs§

MBR
Used to grab partitions from the MBR
Partition
Used to interface with partitions
PartitionRecord
Used to store data about partitions in the MBR

Enums§

PartitionId
ID of each partition

Constants§

BLOCK_SIZE
Size of blocks in bytes
BOOT_FLAG_OFFSET
Offset of the boot indicator flag in a partition record
RECORDS_START
Offset to the start of the partition records
RECORD_COUNT
Number of record in MBR
RECORD_LEN
Length of each record in bytes
RELATIVE_SECTOR_OFFSET
Offset of the relative sector field in a partition record
SYSTEM_ID_OFFSET
Offset of the system id field in a partition record
TOTAL_SECTORS_OFFSET
Offset of the total sectors field in a partition record

Functions§

lba_to_u64
Convert an LBA address to a u64