pub fn backup_mbr(device: &Device) -> 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 MBRErr(Error)
- Error reading MBR from 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 backup
let backup = Backup_mbr(&device).unwrap();
// Store backup somewhere safe...
// Later, restore it if needed
Restore_mbr(&device, &backup).unwrap();