Module mbr

Module mbr 

Source
Expand description

Master Boot Record (MBR) module

This module provides functionality for working with MBR (Master Boot Record) partition tables, which are used in traditional BIOS-based systems.

§Features

  • Parse and validate MBR structures from raw bytes or devices
  • Create and modify MBR partition tables
  • Work with individual partition entries
  • Create partition devices for accessing individual partitions
  • Utility functions for common MBR operations
  • Type-safe partition type enumeration

§Examples

extern crate alloc;

use file_system::{MemoryDevice, mbr::{Mbr, PartitionKind, create_partition_device}};

let device = MemoryDevice::<512>::new(4 * 1024 * 1024);

// Create a new MBR
let mut mbr = Mbr::new_with_signature(0x12345678);
// Add a FAT32 partition
mbr.add_partition(PartitionKind::Fat32Lba, 2048, 204800, true).unwrap();

// Write MBR to the device
mbr.write_to_device(&device).unwrap();

// Read MBR from a device
let mbr = Mbr::read_from_device(&device).unwrap();

// Display MBR information
println!("{}", mbr);

// Get all valid partitions
let partitions = mbr.get_valid_partitions();

// Create a partition device
if let Some(partition) = partitions.first() {
    let partition_device = create_partition_device(&device, partition).unwrap();
}

Structs§

Mbr
Master Boot Record structure (512 bytes)
PartitionEntry
MBR partition table entry structure (16 bytes).
PartitionStatistics
Comprehensive statistics about partitions in an MBR.

Enums§

Error
PartitionKind
MBR partition type enumeration with comprehensive type definitions.

Functions§

backup_mbr
Create a backup of an MBR as a byte array.
clone_mbr
Clone an MBR from one device to another.
create_all_partition_devices
Create partition devices for all valid partitions in an MBR.
create_basic_mbr
Create a basic MBR with a single partition covering most of the disk.
create_partition_device
Create a partition device from an MBR partition entry.
find_partitions_by_type
Find partitions of a specific type within an MBR.
format_disk_and_get_first_partition
Format disk to MBR if it doesn’t contain valid MBR and return first partition device
has_valid_mbr
Check if a device contains a valid MBR.
is_gpt_disk
Check if a device uses GPT (GUID Partition Table) instead of MBR.
restore_mbr
Restore an MBR from a backup byte array.
scan_mbr_partitions
Scan a device for MBR and return partition information.
validate_mbr
Validate MBR structure and partitions for consistency and correctness.

Type Aliases§

Result