CardSight 0.1.0
C API reference for the CardSight firmware and application
Loading...
Searching...
No Matches
mass_storage.h File Reference

A block device exported as a USB mass storage LUN: the host sees a disk and reads and writes the sectors of the block device behind it. More...

#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  usb_mass_storage_stats
 Transfer counters of the exported disk. More...

Functions

void usb_mass_storage_force_read_only (bool read_only)
 Export read-only whatever the device says.
int usb_mass_storage_start_device (const char *device_name)
 Start the device stack and export a block device.
int usb_mass_storage_stop (void)
 Stop the device stack and release the exported block device.
bool usb_mass_storage_running (void)
 Whether the stack runs and a disk is exported.
bool usb_mass_storage_configured (void)
 Whether the host configured the interface (it enumerated us).
int usb_mass_storage_last_error (void)
 The last error recorded by the mass storage stack.
void usb_mass_storage_get_stats (struct usb_mass_storage_stats *stats)
 Copy the transfer counters out.

Detailed Description

A block device exported as a USB mass storage LUN: the host sees a disk and reads and writes the sectors of the block device behind it.

Function Documentation

◆ usb_mass_storage_configured()

bool usb_mass_storage_configured ( void )

Whether the host configured the interface (it enumerated us).

Returns
true after the host configured the interface.

◆ usb_mass_storage_force_read_only()

void usb_mass_storage_force_read_only ( bool read_only)

Export read-only whatever the device says.

For host-side read tests.

Parameters
[in]read_onlyWhether the export refuses host writes.

◆ usb_mass_storage_get_stats()

void usb_mass_storage_get_stats ( struct usb_mass_storage_stats * stats)

Copy the transfer counters out.

Parameters
[out]statsReceives the byte counts; NULL is ignored.

◆ usb_mass_storage_last_error()

int usb_mass_storage_last_error ( void )

The last error recorded by the mass storage stack.

Returns
The error, or 0 when there was none.

◆ usb_mass_storage_running()

bool usb_mass_storage_running ( void )

Whether the stack runs and a disk is exported.

Returns
true while a disk is exported.

◆ usb_mass_storage_start_device()

int usb_mass_storage_start_device ( const char * device_name)

Start the device stack and export a block device.

Parameters
[in]device_nameBlock device to export, e.g. "mmcblk0".
Returns
0 on success, -EBUSY while it already runs, -EINVAL for an empty name, or -ENODEV when the block device does not exist.

◆ usb_mass_storage_stop()

int usb_mass_storage_stop ( void )

Stop the device stack and release the exported block device.

Returns
0 on success, or -ETIMEDOUT when an in-flight transfer did not drain in time.