UsbManager

Trait UsbManager 

Source
pub trait UsbManager: Send + Sync {
    // Required methods
    fn enable(&self) -> Result<(), UsbError>;
    fn disable(&self) -> Result<(), UsbError>;
}
Expand description

Trait for USB mass storage gadget management.

This trait abstracts over platform-specific implementations that enable USB mass storage mode for exposing device storage to a host computer.

§Lifecycle

  1. Call enable when the user connects to a host and wants to share storage.
  2. The implementation unmounts the onboard partition, configures the USB gadget, and exposes the storage to the host.
  3. Call disable when the user disconnects.
  4. The implementation disables the gadget, runs filesystem checks, and remounts the partition.

§Example

use cadmus_core::device::usb::{UsbManager, UsbError};

// Enable USB sharing
usb_manager.enable()?;

// ... device is now in USB mass storage mode ...

// Disable USB sharing
usb_manager.disable()?;

Required Methods§

Source

fn enable(&self) -> Result<(), UsbError>

Enables USB mass storage mode.

This method performs the following operations:

  1. Syncs filesystem buffers and drops caches
  2. Unmounts /mnt/onboard (and /mnt/sd if present)
  3. Configures and enables the USB mass storage gadget

After this call returns successfully, the Kobo’s internal storage is accessible to the connected USB host.

§Errors

Returns UsbError if any step fails:

§Example
use cadmus_core::device::usb::UsbManager;

usb_manager.enable()?;
Source

fn disable(&self) -> Result<(), UsbError>

Disables USB mass storage mode.

This method performs the following operations:

  1. Disables the USB gadget
  2. Tears down the USB gadget configuration
  3. Runs filesystem checks with dosfsck
  4. Remounts /mnt/onboard (and /mnt/sd if present)

If filesystem corruption is detected and cannot be repaired, this method may trigger a reboot by returning an error.

§Errors

Returns UsbError if any step fails:

§Example
use cadmus_core::device::usb::UsbManager;

usb_manager.disable()?;

Implementors§