Function clone_mbr

Source
pub fn clone_mbr(source_device: &Device, target_device: &Device) -> 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 from
  • Target_device - Device to write the MBR to

§Returns

  • Ok(()) - MBR successfully cloned
  • Err(Error) - Error reading, validating, or writing MBR

§Examples

extern crate alloc;
use file_system::*;

let source = create_device!(Memory_device_type::<512>::new(4 * 1024 * 1024));
let target = create_device!(Memory_device_type::<512>::new(4 * 1024 * 1024));

// Create a valid MBR on source device 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(&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));