CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
usb_msc_bounds.h File Reference
#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Functions

static bool usb_msc_range_ok (uint64_t total_bytes, uint16_t block_size, uint32_t lba, uint32_t offset, uint32_t len, bool is_write)
 Validates an MSC block access against the volume geometry.
static bool usb_msc_should_remount (bool prev, bool cur)
 Whether a host-active transition should trigger a badge remount.

Function Documentation

◆ usb_msc_range_ok()

bool usb_msc_range_ok ( uint64_t total_bytes,
uint16_t block_size,
uint32_t lba,
uint32_t offset,
uint32_t len,
bool is_write )
inlinestatic

Validates an MSC block access against the volume geometry.

Reads may use any offset/length within bounds. Writes must be sector-aligned (offset 0 and length a whole number of blocks), matching the erase-then-write wear-levelling semantics.

Parameters
total_bytesTotal accessible volume size.
block_sizeLogical block (sector) size.
lbaLogical block address.
offsetByte offset inside the block.
lenAccess length in bytes.
is_writeTrue for a write access (stricter alignment).
Returns
true when the access is in range and (for writes) aligned.

Definition at line 26 of file usb_msc_bounds.h.

Referenced by cdc::plugin_manager::PluginStorage::blockRead(), and cdc::plugin_manager::PluginStorage::blockWrite().

◆ usb_msc_should_remount()

bool usb_msc_should_remount ( bool prev,
bool cur )
inlinestatic

Whether a host-active transition should trigger a badge remount.

Only the active->inactive edge (host detached) refreshes the FATFS view so host-written files become visible.

Parameters
prevPrevious host-active state.
curNew host-active state.
Returns
true when the volume should be remounted.

Definition at line 45 of file usb_msc_bounds.h.

Referenced by cdc::plugin_manager::PluginStorage::setHostActive().