Function restore_mbr

Source
pub fn restore_mbr(device: &Device, backup: &[u8; 512]) -> Result<()>
Expand description

Restore an MBR from a backup byte array.

This function takes a previously created MBR backup and writes it to a device. The backup is validated before writing to ensure data integrity. This is the counterpart to backup_mbr for disaster recovery scenarios.

§Arguments

  • Device - The storage device to restore the MBR to
  • Backup - 512-byte array containing the MBR backup

§Returns

  • Ok(()) - MBR successfully restored
  • Err(Error) - Error validating backup or writing to device

§Examples

extern crate alloc;
use file_system::*;

let device = create_device!(Memory_device_type::<512>::new(4 * 1024 * 1024));
// Create a valid MBR first
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();

// Create a backup
let backup = backup_mbr(&device).unwrap();

// Simulate corruption or need to restore
Restore_mbr(&device, &backup).unwrap();

assert!(Has_valid_mbr(&device));