⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

MassStorageDevice

Struct MassStorageDevice 

Source
pub struct MassStorageDevice {
    pub device_address: u8,
    pub bulk_in_ep: u8,
    pub bulk_out_ep: u8,
    pub lun: u8,
    pub max_lun: u8,
    pub cached_block_size: u32,
    pub cached_total_blocks: u64,
    pub state: MassStorageState,
    pub last_sense: Option<SenseData>,
}
Expand description

USB Mass Storage device using Bulk-Only Transport (BOT)

Fields§

§device_address: u8

USB device address on the bus

§bulk_in_ep: u8

Bulk-In endpoint address

§bulk_out_ep: u8

Bulk-Out endpoint address

§lun: u8

Active Logical Unit Number

§max_lun: u8

Maximum number of LUNs supported by the device

§cached_block_size: u32

Cached block (sector) size in bytes

§cached_total_blocks: u64

Cached total block count

§state: MassStorageState

Current device state

§last_sense: Option<SenseData>

Last sense data from REQUEST SENSE

Implementations§

Source§

impl MassStorageDevice

Source

pub fn new(device_address: u8, bulk_in_ep: u8, bulk_out_ep: u8) -> Self

Create a new mass storage device handle.

device_address: USB device address on the bus bulk_in_ep: endpoint address for Bulk-In transfers bulk_out_ep: endpoint address for Bulk-Out transfers

Source

pub fn set_lun(&mut self, lun: u8)

Set the active Logical Unit Number

Source

pub fn build_inquiry_cdb(allocation_length: u8) -> [u8; 6]

Build a SCSI INQUIRY command (6-byte CDB)

Source

pub fn build_test_unit_ready_cdb() -> [u8; 6]

Build a SCSI TEST UNIT READY command (6-byte CDB)

Source

pub fn build_request_sense_cdb(allocation_length: u8) -> [u8; 6]

Build a SCSI REQUEST SENSE command (6-byte CDB)

Source

pub fn build_read_capacity_10_cdb() -> [u8; 10]

Build a SCSI READ CAPACITY(10) command (10-byte CDB)

Source

pub fn build_read_10_cdb(lba: u32, transfer_length: u16) -> [u8; 10]

Build a SCSI READ(10) command (10-byte CDB)

Source

pub fn build_write_10_cdb(lba: u32, transfer_length: u16) -> [u8; 10]

Build a SCSI WRITE(10) command (10-byte CDB)

Source

pub fn initialize(&mut self) -> Result<InquiryData, KernelError>

Initialize the device: INQUIRY, TEST UNIT READY, READ CAPACITY.

On success, cached_block_size and cached_total_blocks are populated and the device transitions to the Ready state.

Source

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

Issue a SCSI REQUEST SENSE command and cache the result

Trait Implementations§

Source§

impl BlockDevice for MassStorageDevice

Source§

fn read_blocks( &self, lba: u64, count: u32, buf: &mut [u8], ) -> Result<usize, KernelError>

Read count blocks starting at logical block address lba into buf. Returns the number of bytes actually read.
Source§

fn write_blocks( &self, lba: u64, count: u32, buf: &[u8], ) -> Result<usize, KernelError>

Write count blocks starting at logical block address lba from buf. Returns the number of bytes actually written.
Source§

fn block_size(&self) -> u32

Get the block (sector) size in bytes
Source§

fn total_blocks(&self) -> u64

Get the total number of blocks on the device
Source§

impl Debug for MassStorageDevice

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for MassStorageDevice

§

impl RefUnwindSafe for MassStorageDevice

§

impl Send for MassStorageDevice

§

impl Sync for MassStorageDevice

§

impl Unpin for MassStorageDevice

§

impl UnwindSafe for MassStorageDevice

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.