Function create_all_partition_devices

Source
pub fn create_all_partition_devices(
    base_device: Device,
    mbr: &Mbr,
) -> Result<Vec<PartitionDevice>>
Expand description

Create partition devices for all valid partitions in an MBR.

This function iterates through all partition entries in an MBR and creates PartitionDevice instances for each valid partition. This is useful when you need to access all partitions on a disk programmatically.

§Arguments

  • Base_device - The underlying storage device containing all partitions
  • Mbr - The MBR structure containing partition information

§Returns

  • Ok(Vec<PartitionDevice>) - Vector of partition devices for all valid partitions
  • Err(Error) - Error if any partition device creation fails

§Examples

extern crate alloc;
use file_system::*;

let device = create_device!(Memory_device_type::<512>::new(4 * 1024 * 1024));
// Create an MBR with multiple partitions
let mut mbr = MBR_type::New_with_signature(0x12345678);
mbr.Add_partition(Partition_type_type::Fat32_lba, 2048, 1024, true).unwrap();
mbr.Add_partition(Partition_type_type::Linux, 4096, 2048, false).unwrap();
mbr.Write_to_device(&device).unwrap();

// Read it back and create all partition devices
let mbr = MBR_type::Read_from_device(&device).unwrap();
let partition_devices = mbr.Create_all_partition_devices(device).unwrap();
println!("Created {} partition devices", partition_devices.len());

for (i, partition) in partition_devices.iter().enumerate() {
    println!("Partition {}: {} sectors", i, partition.get_sector_count());
}