PartitionDevice

Struct PartitionDevice 

Source
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>

Source

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 device
  • start_block - Block index where the partition starts
  • block_count - Number of blocks in the partition
  • block_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);
Source

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);
Source

pub const fn get_start_lba(&self) -> Size

Source

pub const fn get_base_device(&self) -> &D

Get the base device

Source

pub const fn is_valid(&self) -> bool

Check if the partition device is valid (non-zero size)

Trait Implementations§

Source§

impl<'a, D> Debug for PartitionDevice<'a, D>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, D: DirectBaseOperations> DirectBaseOperations for PartitionDevice<'a, D>

Source§

fn read(&self, buffer: &mut [u8], absolute_position: Size) -> Result<usize>

Source§

fn write(&self, buffer: &[u8], absolute_position: Size) -> Result<usize>

Source§

fn write_pattern( &self, pattern: &[u8], count: usize, absolute_position: Size, ) -> Result<usize>

Source§

fn set_position( &self, current_position: Size, position: &Position, ) -> Result<Size>

Source§

fn flush(&self) -> Result<()>

Source§

fn control( &self, command: ControlCommandIdentifier, input: &AnyByLayout, output: &mut AnyByLayout, ) -> Result<()>

Source§

fn open(&self) -> Result<()>

Source§

fn close(&self) -> Result<()>

Source§

fn read_until( &self, buffer: &mut [u8], absolute_position: Size, delimiter: &[u8], ) -> Result<usize>

Source§

fn write_vectored( &self, buffers: &[&[u8]], absolute_position: Size, ) -> Result<usize>

Source§

impl<'a, D: DirectBlockDevice> DirectBlockDevice for PartitionDevice<'a, D>

Source§

impl<'a, D: MountOperations> MountOperations for PartitionDevice<'a, D>

Source§

fn mount(&self) -> Result<()>

Source§

fn unmount(&self) -> Result<()>

Auto Trait Implementations§

§

impl<'a, D> Freeze for PartitionDevice<'a, D>

§

impl<'a, D> RefUnwindSafe for PartitionDevice<'a, D>
where D: RefUnwindSafe,

§

impl<'a, D> Send for PartitionDevice<'a, D>
where D: Sync,

§

impl<'a, D> Sync for PartitionDevice<'a, D>
where D: Sync,

§

impl<'a, D> Unpin for PartitionDevice<'a, D>

§

impl<'a, D> UnwindSafe for PartitionDevice<'a, D>
where D: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> BaseOperations for T

Source§

fn open(&self, _: &mut Context) -> Result<(), Error>

Source§

fn read( &self, _: &mut Context, buffer: &mut [u8], absolute_position: u64, ) -> Result<usize, Error>

Read data from the device at the current position. Read more
Source§

fn write( &self, _: &mut Context, buffer: &[u8], absolute_position: u64, ) -> Result<usize, Error>

Write data to the device at the current position. Read more
Source§

fn write_pattern( &self, _: &mut Context, pattern: &[u8], count: usize, absolute_position: u64, ) -> Result<usize, Error>

Source§

fn write_vectored( &self, _context: &mut Context, buffers: &[&[u8]], absolute_position: u64, ) -> Result<usize, Error>

Source§

fn flush(&self, _: &mut Context) -> Result<(), Error>

Flush any buffered data to the underlying storage. Read more
Source§

fn set_position( &self, _context: &mut Context, current_position: u64, position: &Position, ) -> Result<u64, Error>

Set the current position cursor for read/write operations. Read more
Source§

fn control( &self, _: &mut Context, command: ControlCommandIdentifier, input: &AnyByLayout, output: &mut AnyByLayout, ) -> Result<(), Error>

Source§

fn clone_context(&self, _context: &Context) -> Result<Context, Error>

Source§

fn close(&self, _context: &mut Context) -> Result<()>

Source§

fn read_until( &self, context: &mut Context, buffer: &mut [u8], absolute_position: Size, delimiter: &[u8], ) -> Result<usize>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> BlockDevice for T