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,
impl<'dev, 'd, A, M> MscLun<'dev, 'd, A, M>where
A: UsbHostAllocator<'d>,
M: RawMutex,
Sourcepub fn cached_capacity(&self) -> Option<BlockCapacity>
pub fn cached_capacity(&self) -> Option<BlockCapacity>
Cached BlockCapacity, if capacity has
been called.
Sourcepub fn invalidate_capacity(&mut self)
pub fn invalidate_capacity(&mut self)
Clear the cached capacity so the next I/O re-fetches it.
Sourcepub async fn inquiry<'a>(
&mut self,
buf: &'a mut [u8; 36],
) -> Result<InquiryData<'a>, MscError>
pub async fn inquiry<'a>( &mut self, buf: &'a mut [u8; 36], ) -> Result<InquiryData<'a>, MscError>
Run INQUIRY (standard data, 36 bytes).
Sourcepub async fn request_sense(&mut self) -> Result<SenseData, MscError>
pub async fn request_sense(&mut self) -> Result<SenseData, MscError>
Read SCSI sense data via REQUEST SENSE.
Sourcepub async fn test_unit_ready(&mut self) -> Result<bool, MscError>
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.
Sourcepub async fn prevent_medium_removal(
&mut self,
prevent: bool,
) -> Result<(), MscError>
pub async fn prevent_medium_removal( &mut self, prevent: bool, ) -> Result<(), MscError>
Enable or disable medium removal by the user.
Sourcepub async fn capacity(&mut self) -> Result<BlockCapacity, MscError>
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.
Sourcepub async fn read_blocks(
&mut self,
lba: u64,
buf: &mut [u8],
) -> Result<(), MscError>
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.
Sourcepub async fn write_blocks(
&mut self,
lba: u64,
buf: &[u8],
) -> Result<(), MscError>
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.