KoboUsbOperations

Trait KoboUsbOperations 

Source
pub trait KoboUsbOperations {
    // Required method
    fn metadata(&self) -> &DeviceMetadata;

    // Provided methods
    fn sync_and_drop_caches(&self) -> Result<(), UsbError> { ... }
    fn is_mounted(&self, mount_point: &str) -> Result<bool, UsbError> { ... }
    fn unmount_partition(&self, mount_point: &str) -> Result<(), UsbError> { ... }
    fn prepare_for_usb_share(&self) -> Result<(), UsbError> { ... }
    fn remount_partitions(&self) -> Result<(), UsbError> { ... }
    fn check_filesystem(&self) -> Result<(), UsbError> { ... }
}
Expand description

Trait providing common USB operations for Kobo devices.

Implementors must provide access to the device metadata via the metadata method. All other methods have default implementations that use the metadata.

§Example

use cadmus_core::device::usb::kobo::operations::KoboUsbOperations;
use cadmus_core::device::DeviceMetadata;

struct MyUsbManager {
    metadata: DeviceMetadata,
}

impl KoboUsbOperations for MyUsbManager {
    fn metadata(&self) -> &DeviceMetadata {
        &self.metadata
    }
}

manager.prepare_for_usb_share()?;

Required Methods§

Source

fn metadata(&self) -> &DeviceMetadata

Provides access to the device metadata.

Implementors must return a reference to their DeviceMetadata, which is used by the default implementations of other trait methods.

Provided Methods§

Source

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

Syncs filesystem buffers and drops caches.

This function ensures all pending writes are flushed to disk before unmounting partitions for USB mass storage mode.

§Errors

Returns UsbError::Io if the sync command or cache drop fails.

Source

fn is_mounted(&self, mount_point: &str) -> Result<bool, UsbError>

Checks if a mount point is currently mounted.

Uses procfs to read mount information and checks if the mount_point appears in the list.

§Errors

Returns UsbError::Io if mount information cannot be read. Callers should treat a read failure as an error rather than assuming the filesystem is unmounted.

Source

fn unmount_partition(&self, mount_point: &str) -> Result<(), UsbError>

Unmounts a partition lazily.

Detaches the filesystem immediately but cleans up references in the background.

§Errors

Returns UsbError::Partition if the unmount operation fails.

Source

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

Prepares the system for USB mass storage mode.

Performs the necessary cleanup before enabling USB sharing:

  • Syncs filesystem buffers
  • Drops page caches
  • Unmounts /mnt/onboard and /mnt/sd if mounted
§Errors

Returns UsbError::Partition if unmounting fails critically.

Source

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

Remounts partitions after USB sharing is disabled.

Mounts the onboard partition and optionally the SD card if present. Uses vfat filesystem with noatime, nodiratime, shortname=mixed, and utf8 options.

§Errors

Returns UsbError::Partition if mounting the onboard partition fails.

Source

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

Runs filesystem check and repair.

Runs dosfsck -a -w on the partition up to twice. The first run attempts automatic repair. If it exits with a non-zero status (exit code 1 means recoverable errors were found; see fsck.fat(8)), a second run is performed to verify the repairs. Only after both runs fail is the filesystem considered unrecoverable.

§dosfsck exit codes
CodeMeaning
0No errors found
1Recoverable errors found (or internal inconsistency)
2Usage error – filesystem was not accessed

The two-pass approach mirrors the original shell script behaviour: the first pass repairs, and the second pass confirms the result.

§Errors

Returns UsbError::Partition if /mnt/onboard is still mounted, to prevent running dosfsck on a live filesystem. Returns UsbError::Filesystem if filesystem corruption is detected and cannot be repaired. Returns UsbError::Io if the command fails to execute.

Implementors§