usbh-scsi 0.1.0

A library to communicate with scsi to usb devices from a host
Documentation
  • Coverage
  • 78.79%
    78 out of 99 items documented4 out of 47 items with examples
  • Size
  • Source code size: 51.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.49 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • BjornTheProgrammer

USBh-SCSI

A userspace library for sending SCSI commands to USB Mass Storage devices via the Bulk-Only Transport (BOT) protocol.

Unlike traditional approaches, this crate does not depend on the operating system’s block device or filesystem layers. Instead, it provides a pure-Rust API for constructing and executing standard SCSI command blocks directly over USB, making it portable across all platforms supported by rusb.

Goals

  • Cross-platform support (Linux, macOS, Windows, etc. via rusb).
  • Easy construction and execution of SCSI commands such as INQUIRY, READ CAPACITY (10), READ(10), and WRITE(10).
  • Clean abstractions for both raw transport and block-level access.

Core Modules

  • commands — strongly-typed definitions of SCSI commands and the CommandBlock trait for generating Command Descriptor Blocks (CDBs).
  • storage — device discovery, opening/closing devices, bulk I/O, and SCSI command execution over USB BOT. Includes UsbBlockDevice for sector-oriented reads/writes.

Usage

Add to your Cargo.toml:

cargo add usbh-scsi

Example

use usbh_scsi::storage::UsbMassStorage;
use usbh_scsi::commands::inquiry::InquiryCommand;
use usbh_scsi::commands::cbw::Direction;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    // Enumerate all attached MSC devices
    let mut devices = UsbMassStorage::list()?;
    if let Some(closed) = devices.pop() {
        // Open the first one
        let mut dev = closed.open()?;

        // Send an INQUIRY command
        let cmd = InquiryCommand::new(0);
        let mut buf = [0u8; 36];
        dev.execute_command(1, buf.len() as u32, Direction::In, &cmd, Some(&mut buf))?;

        println!("INQUIRY data: {:?}", &buf);
    }
    Ok(())
}

When to Use

  • Use usbh-scsi if you want raw SCSI access to USB devices (e.g. discovering capacity, issuing reads/writes, or building custom tooling).
  • Use usbh-fatfs if you want a filesystem-aware interface for working directly with FAT partitions on USB devices.

Supported Platforms

Works on any platform supported by rusb.