backup_mbr

Function backup_mbr 

Source
pub fn backup_mbr(device: &impl DirectBlockDevice) -> Result<[u8; 512]>
Expand description

Create a backup of an MBR as a byte array.

This function reads the MBR from a device and returns it as a 512-byte array. This backup can be stored and later restored using restore_mbr. This is essential for disaster recovery and partition table management.

§Arguments

  • Device - The storage device to backup the MBR from

§Returns

  • Ok([u8; 512]) - 512-byte array containing the complete MBR
  • Err(Error) - Error reading MBR from device

§Examples

extern crate alloc;
use file_system::{MemoryDevice, mbr::{Mbr, PartitionKind, {backup_mbr, restore_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 backup
let backup = backup_mbr(&device).unwrap();

// Store backup somewhere safe...
// Later, restore it if needed
restore_mbr(&device, &backup).unwrap();