pub struct PartitionDevice<'a, D> { /* private fields */ }Expand description
A device implementation that represents a partition within a larger storage device.
This type wraps a base device and provides access to only a specific region (partition) of that device. It maintains its own position cursor and ensures all operations stay within the partition boundaries. This allows file systems to operate on individual partitions without needing to know about the partition layout.
Note: The partition device does not manage position state internally and does not use atomic operations. Thread safety depends on the underlying base device implementation.
§Examples
// Create a memory device for testing
let base_device = MemoryDevice::<512>::new(1024 * 1024);
// Create a partition device for blocks 100-199 (100 blocks of 512 bytes = 51.2KB)
let partition_device = PartitionDevice::new(&base_device, 100, 100, 512);
// Now you can use partition_device like any other device
let data = b"Hello, Partition!";
partition_device.write(data, 0).unwrap();Implementations§
Source§impl<'a, D: BaseOperations> PartitionDevice<'a, D>
impl<'a, D: BaseOperations> PartitionDevice<'a, D>
Sourcepub fn new(
base_device: &'a D,
start_block: Size,
block_count: Size,
block_size: u32,
) -> Self
pub fn new( base_device: &'a D, start_block: Size, block_count: Size, block_size: u32, ) -> Self
Create a new partition device with explicit byte offset and size.
§Arguments
base_device- The underlying storage devicestart_block- Block index where the partition startsblock_count- Number of blocks in the partitionblock_size- Size of each block in bytes
§Examples
let base_device = MemoryDevice::<512>::new(1024 * 1024);
// Create a partition starting at block 128 (64KB) with 256 blocks (128KB)
let partition = PartitionDevice::new(&base_device, 128, 256, 512);Sourcepub const fn get_block_count(&self) -> u32
pub const fn get_block_count(&self) -> u32
Get the number of blocks in this partition.
§Returns
The number of blocks in this partition, where each block is of the partition’s configured block size. The number of 512-byte sectors this partition contains.
§Examples
let base_device = MemoryDevice::<512>::new(1024 * 1024);
let partition = PartitionDevice::new(&base_device, 100, 50, 512);
assert_eq!(partition.get_block_count(), 50);pub const fn get_start_lba(&self) -> Size
Sourcepub const fn get_base_device(&self) -> &D
pub const fn get_base_device(&self) -> &D
Get the base device