pub fn create_partition_device(
base_device: Device,
partition: &PartitionEntry,
) -> Result<PartitionDevice>
Expand description
Create a partition device from an MBR partition entry.
This function takes a base device and a partition entry from an MBR, and creates
a PartitionDevice
that represents just that partition. The resulting
partition device can be used for all standard device operations, but will only
access the sectors allocated to that specific partition.
§Arguments
Base_device
- The underlying storage device containing the partitionPartition
- MBR partition entry describing the partition layout
§Returns
Ok(Partition_device_type)
- Successfully created partition deviceErr(Error::InvalidParameter)
- Partition entry is invalid
§Examples
extern crate alloc;
use file_system::*;
let device = create_device!(Memory_device_type::<512>::new(4 * 1024 * 1024));
// First create and write an MBR to the device
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();
// Now read it back and create partition device
let mbr = MBR_type::Read_from_device(&device).unwrap();
if let Some(partition) = mbr.get_valid_partitions().first() {
let partition_device = Create_partition_device(device, partition).unwrap();
// Now you can use partition_device for I/O operations
}