scan_mbr_partitions

Function scan_mbr_partitions 

Source
pub fn scan_mbr_partitions(
    device: &impl DirectBlockDevice,
) -> Result<Vec<(usize, PartitionEntry)>>
Expand description

Scan a device for MBR and return partition information.

This function reads the MBR from a device and extracts information about all valid partitions. It returns a vector of tuples containing the partition index and the partition entry for each valid partition found.

§Arguments

  • Device - The storage device to scan for MBR partitions

§Returns

  • Ok(Vec<(usize, PartitionEntry)>) - List of valid partitions with their indices
  • Err(Error) - Error reading MBR or device access failure

§Examples

extern crate alloc;
use file_system::{MemoryDevice, mbr::{Mbr, PartitionKind, scan_mbr_partitions}};

let device = MemoryDevice::<512>::new(4 * 1024 * 1024);

// Create and write an 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();

match scan_mbr_partitions(&device) {
    Ok(partitions) => {
        println!("Found {} valid partitions", partitions.len());
        for (index, partition) in partitions {
            println!("Partition {}: {:?}", index, partition.kind);
        }
    }
    Err(e) => println!("Failed to scan partitions: {}", e),
}