embassy-usb-host

Crates

git

Versions

default

Flavors

MscLun

Struct MscLun 

Source
pub struct MscLun<'dev, 'd, A, M = NoopRawMutex>
where A: UsbHostAllocator<'d>, M: RawMutex,
{ /* private fields */ }
Expand description

Handle for a single Logical Unit.

Borrows the MscDevice for transport access. Convenience methods wrap the SCSI commands a storage host typically needs; power users can issue arbitrary CDBs via MscDevice::command.

Block-I/O methods use the LUN’s cached capacity. The first call to MscLun::capacity fills it; MscLun::invalidate_capacity clears it (useful after a UnitAttention indicating media change).

Implementations§

Source§

impl<'dev, 'd, A, M> MscLun<'dev, 'd, A, M>
where A: UsbHostAllocator<'d>, M: RawMutex,

Source

pub fn lun(&self) -> u8

LUN index.

Source

pub fn cached_capacity(&self) -> Option<BlockCapacity>

Cached BlockCapacity, if capacity has been called.

Source

pub fn invalidate_capacity(&mut self)

Clear the cached capacity so the next I/O re-fetches it.

Source

pub async fn inquiry<'a>( &mut self, buf: &'a mut [u8; 36], ) -> Result<InquiryData<'a>, MscError>

Run INQUIRY (standard data, 36 bytes).

Source

pub async fn request_sense(&mut self) -> Result<SenseData, MscError>

Read SCSI sense data via REQUEST SENSE.

Source

pub async fn test_unit_ready(&mut self) -> Result<bool, MscError>

Probe with TEST UNIT READY.

Returns Ok(true) when the unit is ready, Ok(false) on a transient NotReady or UnitAttention sense (e.g. medium not yet spun up or just inserted). Other failures surface as MscError::Scsi.

Source

pub async fn prevent_medium_removal( &mut self, prevent: bool, ) -> Result<(), MscError>

Enable or disable medium removal by the user.

Source

pub async fn capacity(&mut self) -> Result<BlockCapacity, MscError>

Fetch and cache the LUN’s block capacity.

Uses READ CAPACITY(10); falls back to READ CAPACITY(16) when the device reports the sentinel 0xFFFFFFFF (i.e. the LUN is larger than 2 TiB at 512-byte blocks). The two probes run under a single lock hold.

Source

pub async fn read_blocks( &mut self, lba: u64, buf: &mut [u8], ) -> Result<(), MscError>

Read buf.len() / block_size blocks starting at lba.

buf.len() must be a non-zero multiple of block_size.

Uses READ(10) when lba fits in u32 and the chunk count fits in u16, else READ(16). Large reads are transparently split into chunks of up to 65 535 blocks per command, all issued under a single transport lock hold.

Source

pub async fn write_blocks( &mut self, lba: u64, buf: &[u8], ) -> Result<(), MscError>

Write buf.len() / block_size blocks starting at lba.

buf.len() must be a non-zero multiple of block_size.

Uses WRITE(10) when lba fits in u32 and the chunk count fits in u16, else WRITE(16). Large writes are transparently split into chunks of up to 65 535 blocks per command, all issued under a single transport lock hold.

Source

pub async fn flush(&mut self) -> Result<(), MscError>

Flush the device’s write cache (SYNCHRONIZE CACHE(10) over the entire LUN).

Auto Trait Implementations§

§

impl<'dev, 'd, A, M> Freeze for MscLun<'dev, 'd, A, M>

§

impl<'dev, 'd, A, M = NoopRawMutex> !RefUnwindSafe for MscLun<'dev, 'd, A, M>

§

impl<'dev, 'd, A, M> Send for MscLun<'dev, 'd, A, M>
where M: Sync, <A as UsbHostAllocator<'d>>::Pipe<Control, InOut>: Send, <A as UsbHostAllocator<'d>>::Pipe<Bulk, In>: Send, <A as UsbHostAllocator<'d>>::Pipe<Bulk, Out>: Send,

§

impl<'dev, 'd, A, M> Sync for MscLun<'dev, 'd, A, M>
where M: Sync, <A as UsbHostAllocator<'d>>::Pipe<Control, InOut>: Send, <A as UsbHostAllocator<'d>>::Pipe<Bulk, In>: Send, <A as UsbHostAllocator<'d>>::Pipe<Bulk, Out>: Send,

§

impl<'dev, 'd, A, M> Unpin for MscLun<'dev, 'd, A, M>

§

impl<'dev, 'd, A, M = NoopRawMutex> !UnwindSafe for MscLun<'dev, 'd, A, M>

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