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
- Call
enablewhen the user connects to a host and wants to share storage. - The implementation unmounts the onboard partition, configures the USB gadget, and exposes the storage to the host.
- Call
disablewhen the user disconnects. - 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§
Sourcefn enable(&self) -> Result<(), UsbError>
fn enable(&self) -> Result<(), UsbError>
Enables USB mass storage mode.
This method performs the following operations:
- Syncs filesystem buffers and drops caches
- Unmounts
/mnt/onboard(and/mnt/sdif present) - 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:
UsbError::Partitionif unmounting failsUsbError::GadgetConfigif USB gadget configuration failsUsbError::KernelModuleif module loading fails
§Example
ⓘ
use cadmus_core::device::usb::UsbManager;
usb_manager.enable()?;Sourcefn disable(&self) -> Result<(), UsbError>
fn disable(&self) -> Result<(), UsbError>
Disables USB mass storage mode.
This method performs the following operations:
- Disables the USB gadget
- Tears down the USB gadget configuration
- Runs filesystem checks with
dosfsck - Remounts
/mnt/onboard(and/mnt/sdif 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:
UsbError::KernelModuleif module unloading failsUsbError::Filesystemif filesystem check/repair failsUsbError::Partitionif remounting fails
§Example
ⓘ
use cadmus_core::device::usb::UsbManager;
usb_manager.disable()?;