pub fn restore_mbr(
device: &impl DirectBlockDevice,
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 toBackup- 512-byte array containing the MBR backup
§Returns
Ok(())- MBR successfully restoredErr(Error)- Error validating backup or writing to device
§Examples
extern crate alloc;
use file_system::{MemoryDevice, mbr::{Mbr, PartitionKind, {backup_mbr, restore_mbr, has_valid_mbr}}};
let device = MemoryDevice::<512>::new(4 * 1024 * 1024);
// Create a valid MBR first
let mut mbr = Mbr::new_with_signature(0x12345678);
mbr.add_partition(PartitionKind::Fat32Lba, 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));