Function validate_mbr

Source
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 consistent
  • Err(Error::Corrupted) - MBR is invalid or corrupted

§Examples

extern crate alloc;
use file_system::*;

let device = create_device!(Memory_device_type::<512>::new(4 * 1024 * 1024));
// First create and write a valid MBR
let mut mbr = MBR_type::New_with_signature(0x12345678);
mbr.Add_partition(Partition_type_type::Fat32_lba, 2048, 1024, true).unwrap();
mbr.Write_to_device(&device).unwrap();

// Read it back and validate
let mbr = MBR_type::Read_from_device(&device).unwrap();
match mbr.Validate() {
    Ok(()) => println!("MBR is valid"),
    Err(Error::Corrupted) => println!("MBR is corrupted"),
    Err(e) => println!("Validation error: {}", e),
}