pub fn clone_mbr(
source_device: &impl DirectBlockDevice,
target_device: &impl DirectBlockDevice,
) -> Result<()>Expand description
Clone an MBR from one device to another.
This function reads the MBR from a source device, validates it for consistency, and writes it to a target device. This is useful for creating exact copies of partition layouts or backing up partition tables.
§Arguments
Source_device- Device to read the MBR fromTarget_device- Device to write the MBR to
§Returns
Ok(())- MBR successfully clonedErr(Error)- Error reading, validating, or writing MBR
§Examples
extern crate alloc;
use file_system::{MemoryDevice, mbr::{Mbr, PartitionKind, {clone_mbr, has_valid_mbr}}};
let source = MemoryDevice::<512>::new(4 * 1024 * 1024);
let target = MemoryDevice::<512>::new(4 * 1024 * 1024);
// Create a valid MBR on source device first
let mut mbr = Mbr::new_with_signature(0x12345678);
mbr.add_partition(PartitionKind::Fat32Lba, 2048, 1024, true).unwrap();
mbr.write_to_device(&source).unwrap();
// Now clone the MBR to target
clone_mbr(&source, &target).unwrap();
// Both devices now have valid MBRs
assert_eq!(has_valid_mbr(&source), has_valid_mbr(&target));