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)
- Partition
Entry - MBR partition table entry structure (16 bytes).
- Partition
Statistics - Comprehensive statistics about partitions in an MBR.
Enums§
- Error
- Partition
Kind - 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.