pub fn validate_mbr(mbr: &Mbr) -> Result<()>Expand description
Validate MBR structure and partitions for consistency and correctness.
This function performs comprehensive validation of an MBR structure, checking:
- MBR signature validity (0x55AA boot signature)
- Partition overlap detection
- Bootable partition count (at most one partition should be bootable)
§Arguments
Mbr- The MBR structure to validate
§Returns
Ok(())- MBR is valid and consistentErr(Error::Corrupted)- MBR is invalid or corrupted
§Examples
extern crate alloc;
use file_system::{MemoryDevice, mbr::{Mbr, Error, PartitionKind, validate_mbr}};
let device = MemoryDevice::<512>::new(4 * 1024 * 1024);
// First create and write a valid MBR
let mut mbr = Mbr::new_with_signature(0x12345678);
mbr.add_partition(PartitionKind::Fat32Lba, 2048, 1024, true).unwrap();
mbr.write_to_device(&device).unwrap();
// Read it back and validate
let mbr = Mbr::read_from_device(&device).unwrap();
match validate_mbr(&mbr) {
Ok(()) => println!("MBR is valid"),
Err(e) => println!("Validation error: {}", e),
}