pub struct PartitionDevice { /* 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.
§Thread Safety
The partition device is thread-safe and uses atomic operations for position management. Multiple threads can safely access the same partition device simultaneously.
§Examples
// Create a memory device for testing
let base_device = create_device!(Memory_device_type::<512>::new(1024 * 1024));
// Create a partition device for sectors 100-199 (50KB partition)
let partition = Partition_device_type::New_from_lba(base_device, 100, 100);
let partition_device = create_device!(partition);
// Now you can use partition_device like any other device
let data = b"Hello, Partition!";
partition_device.Write(data).unwrap();
Implementations§
Source§impl PartitionDevice
impl PartitionDevice
Sourcepub fn new(base_device: Device, offset: u64, size: u64) -> Self
pub fn new(base_device: Device, offset: u64, size: u64) -> Self
Create a new partition device with explicit byte offset and size.
§Arguments
base_device
- The underlying storage deviceoffset
- Byte offset from the beginning of the base devicesize
- Size of the partition in bytes
§Examples
let base_device = create_device!(Memory_device_type::<512>::new(1024 * 1024));
// Create a partition starting at 64KB with 128KB size
let partition = Partition_device_type::new(base_device, 64 * 1024, 128 * 1024);
Sourcepub fn new_from_lba(
base_device: Device,
start_lba: u32,
sector_count: u32,
) -> Self
pub fn new_from_lba( base_device: Device, start_lba: u32, sector_count: u32, ) -> Self
Create a partition device from LBA (Logical Block Address) parameters.
This is a convenience method for creating partition devices using standard disk partitioning terminology. It assumes 512-byte sectors.
§Arguments
base_device
- The underlying storage devicestart_lba
- Starting logical block address (sector number)sector_count
- Number of 512-byte sectors in this partition
§Examples
let base_device = create_device!(Memory_device_type::<512>::new(1024 * 1024));
// Create a partition starting at sector 2048 with 1024 sectors (512KB)
let partition = Partition_device_type::New_from_lba(base_device, 2048, 1024);
Sourcepub fn get_offset(&self) -> u64
pub fn get_offset(&self) -> u64
Get the byte offset of this partition within the base device.
§Returns
The absolute byte offset from the beginning of the base device.
§Examples
let base_device = create_device!(Memory_device_type::<512>::new(1024 * 1024));
let partition = Partition_device_type::New_from_lba(base_device, 100, 50);
assert_eq!(partition.get_offset(), 100 * 512);
Sourcepub fn get_partition_size(&self) -> u64
pub fn get_partition_size(&self) -> u64
Get the size of this partition in bytes.
§Returns
The total size of the partition in bytes.
§Examples
let base_device = create_device!(Memory_device_type::<512>::new(1024 * 1024));
let partition = Partition_device_type::New_from_lba(base_device, 100, 50);
assert_eq!(partition.get_partition_size(), 50 * 512);
Sourcepub fn get_start_lba(&self) -> u32
pub fn get_start_lba(&self) -> u32
Get the starting LBA (Logical Block Address) of this partition.
§Returns
The sector number where this partition starts (assuming 512-byte sectors).
§Examples
let base_device = create_device!(Memory_device_type::<512>::new(1024 * 1024));
let partition = Partition_device_type::New_from_lba(base_device, 100, 50);
assert_eq!(partition.get_start_lba(), 100);
Sourcepub fn get_sector_count(&self) -> u32
pub fn get_sector_count(&self) -> u32
Get the size in sectors of this partition.
§Returns
The number of 512-byte sectors this partition contains.
§Examples
let base_device = create_device!(Memory_device_type::<512>::new(1024 * 1024));
let partition = Partition_device_type::New_from_lba(base_device, 100, 50);
assert_eq!(partition.get_sector_count(), 50);
Sourcepub fn get_position(&self) -> u64
pub fn get_position(&self) -> u64
Get the current position within the partition
Sourcepub fn get_base_device(&self) -> &Device
pub fn get_base_device(&self) -> &Device
Get the base device
Sourcepub fn get_remaining_bytes(&self) -> u64
pub fn get_remaining_bytes(&self) -> u64
Get remaining bytes that can be read/written from current position