Struct PartitionDevice

Source
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

Source

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 device
  • offset - Byte offset from the beginning of the base device
  • size - 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);
Source

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 device
  • start_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);
Source

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

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

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

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

pub fn get_position(&self) -> u64

Get the current position within the partition

Source

pub fn get_base_device(&self) -> &Device

Get the base device

Source

pub fn is_valid(&self) -> bool

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

Source

pub fn get_remaining_bytes(&self) -> u64

Get remaining bytes that can be read/written from current position

Source

pub fn is_at_end(&self) -> bool

Check if we’re at the end of the partition

Trait Implementations§

Source§

impl Clone for PartitionDevice

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PartitionDevice

Source§

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

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

impl DeviceTrait for PartitionDevice

Source§

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

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

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

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

fn get_size(&self) -> Result<Size>

Get the total size of the device in bytes. Read more
Source§

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

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

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

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

fn is_a_block_device(&self) -> bool

Check if this device is a block device. Read more
Source§

fn get_block_size(&self) -> Result<usize>

Get the block size of the device in bytes. Read more
Source§

fn is_a_terminal(&self) -> bool

Check if this device represents a terminal/console device. Read more
Source§

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

Erase the entire device. Read more
Source§

fn dump_device(&self) -> Result<Vec<u8>>

Create a complete dump of the device contents. Read more
Source§

impl Display for PartitionDevice

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.