CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::plugin_manager::PluginStorage Class Reference

#include <PluginStorage.h>

Static Public Member Functions

static bool mount ()
 Mount the plugins partition. Auto-formats if empty.
static void unmount ()
 Unmount the plugins partition (rarely used; mostly tests).
static const char * basePath ()
 Returns the VFS path prefix, e.g. "/vfat".
static std::vector< std::string > listPluginIds ()
 Discover all installed plugin ids. A plugin is recognised by the presence of both <id>.wasm and <id>.meta files.
static std::string binaryPath (const std::string &id)
 Returns the path that should be loaded for <id>: <id>.aot if it exists on disk, otherwise <id>.wasm.
static std::string wasmPath (const std::string &id)
 Returns the full VFS path of <id>.wasm.
static std::string aotPath (const std::string &id)
 Returns the full VFS path of <id>.aot.
static std::string metaPath (const std::string &id)
 Returns the full VFS path of <id>.meta.
static std::string langPath (const std::string &id)
 Returns the full VFS path of <id>.lang (translation overlay).
static std::string disabledPath (const std::string &id)
 Returns the full VFS path of <id>.disabled.
static bool isDisabled (const std::string &id)
 True when the plugin has a persistent disabled marker.
static bool setDisabled (const std::string &id, bool disabled)
 Create or remove the persistent disabled marker for a plugin.
static bool stats (uint64_t &free_bytes, uint64_t &total_bytes)
 Returns the free and total bytes on the plugins partition.
static uint16_t blockSize ()
 Logical sector size of the vfat volume in bytes (MSC block size).
static uint64_t blockTotalBytes ()
 Total accessible size of the vfat volume in bytes.
static bool blockRead (uint32_t lba, uint32_t offset, void *buf, uint32_t len)
 Reads raw bytes from the wear-levelling logical space.
static bool blockWrite (uint32_t lba, uint32_t offset, const void *buf, uint32_t len)
 Erases and writes raw bytes to the wear-levelling logical space.
static void setHostActive (bool active)
 Marks whether a USB host currently holds the volume over MSC.
static bool hostActive ()
 Reports whether a USB host currently holds the volume over MSC.
static void remountIfPending ()
 Performs a deferred remount scheduled by setHostActive(false).
static void protectSystemDir ()
 Applies advisory read-only + hidden + system FAT attributes to the system folder so standard host file managers hide and protect it.

Detailed Description

Definition at line 19 of file PluginStorage.h.

Member Function Documentation

◆ aotPath()

std::string cdc::plugin_manager::PluginStorage::aotPath ( const std::string & id)
static

Returns the full VFS path of <id>.aot.

Definition at line 170 of file PluginStorage.cpp.

References cdc::plugin_manager::SYSTEM_DIR.

Referenced by binaryPath(), and cdc::plugin_manager::PluginManager::uninstallPlugin().

◆ basePath()

const char * cdc::plugin_manager::PluginStorage::basePath ( )
static

Returns the VFS path prefix, e.g. "/vfat".

Definition at line 109 of file PluginStorage.cpp.

References cdc::plugin_manager::MOUNT_POINT.

◆ binaryPath()

std::string cdc::plugin_manager::PluginStorage::binaryPath ( const std::string & id)
static

Returns the path that should be loaded for <id>: <id>.aot if it exists on disk, otherwise <id>.wasm.

Definition at line 153 of file PluginStorage.cpp.

References aotPath(), and wasmPath().

Referenced by cdc::plugin_manager::Plugin::load().

◆ blockRead()

bool cdc::plugin_manager::PluginStorage::blockRead ( uint32_t lba,
uint32_t offset,
void * buf,
uint32_t len )
static

Reads raw bytes from the wear-levelling logical space.

Parameters
lbaLogical block address (in blockSize() units).
offsetByte offset added inside the block.
bufDestination buffer.
lenNumber of bytes to read.
Returns
true on success (bounds-checked against the volume size).

Definition at line 229 of file PluginStorage.cpp.

References cdc::plugin_manager::s_mounted, cdc::plugin_manager::s_wl_handle, and usb_msc_range_ok().

◆ blockSize()

uint16_t cdc::plugin_manager::PluginStorage::blockSize ( )
static

Logical sector size of the vfat volume in bytes (MSC block size).

Returns
Sector size, or 0 when not mounted.

Definition at line 217 of file PluginStorage.cpp.

References cdc::plugin_manager::s_mounted, and cdc::plugin_manager::s_wl_handle.

◆ blockTotalBytes()

uint64_t cdc::plugin_manager::PluginStorage::blockTotalBytes ( )
static

Total accessible size of the vfat volume in bytes.

Returns
Volume size, or 0 when not mounted.

Definition at line 223 of file PluginStorage.cpp.

References cdc::plugin_manager::s_mounted, and cdc::plugin_manager::s_wl_handle.

◆ blockWrite()

bool cdc::plugin_manager::PluginStorage::blockWrite ( uint32_t lba,
uint32_t offset,
const void * buf,
uint32_t len )
static

Erases and writes raw bytes to the wear-levelling logical space.

offset must be 0 and len a multiple of blockSize(); the addressed range is erased then written, matching the FATFS-over-WL sector semantics.

Parameters
lbaLogical block address (in blockSize() units).
offsetByte offset inside the block (must be 0).
bufSource buffer.
lenNumber of bytes to write.
Returns
true on success (bounds-checked against the volume size).

Definition at line 238 of file PluginStorage.cpp.

References cdc::plugin_manager::s_mounted, cdc::plugin_manager::s_wl_handle, and usb_msc_range_ok().

◆ disabledPath()

std::string cdc::plugin_manager::PluginStorage::disabledPath ( const std::string & id)
static

Returns the full VFS path of <id>.disabled.

Definition at line 185 of file PluginStorage.cpp.

References cdc::plugin_manager::SYSTEM_DIR.

Referenced by isDisabled(), setDisabled(), and cdc::plugin_manager::PluginManager::uninstallPlugin().

◆ hostActive()

bool cdc::plugin_manager::PluginStorage::hostActive ( )
static

Reports whether a USB host currently holds the volume over MSC.

Returns
true while badge-side writes must be refused.

Definition at line 263 of file PluginStorage.cpp.

References cdc::plugin_manager::s_host_active.

◆ isDisabled()

bool cdc::plugin_manager::PluginStorage::isDisabled ( const std::string & id)
static

True when the plugin has a persistent disabled marker.

Definition at line 190 of file PluginStorage.cpp.

References disabledPath().

Referenced by cdc::plugin_manager::PluginManager::isPluginDisabled().

◆ langPath()

std::string cdc::plugin_manager::PluginStorage::langPath ( const std::string & id)
static

Returns the full VFS path of <id>.lang (translation overlay).

Definition at line 180 of file PluginStorage.cpp.

References cdc::plugin_manager::SYSTEM_DIR.

Referenced by cdc::plugin_manager::Plugin::loadLangOverlay(), and cdc::plugin_manager::PluginManager::uninstallPlugin().

◆ listPluginIds()

std::vector< std::string > cdc::plugin_manager::PluginStorage::listPluginIds ( )
static

Discover all installed plugin ids. A plugin is recognised by the presence of both <id>.wasm and <id>.meta files.

Definition at line 119 of file PluginStorage.cpp.

References cdc::plugin_manager::ends_with(), metaPath(), name, cdc::plugin_manager::s_mounted, and cdc::plugin_manager::SYSTEM_DIR.

Referenced by cdc::plugin_manager::PluginManager::init(), and cdc::plugin_manager::PluginManager::listInstalledIds().

◆ metaPath()

std::string cdc::plugin_manager::PluginStorage::metaPath ( const std::string & id)
static

◆ mount()

◆ protectSystemDir()

void cdc::plugin_manager::PluginStorage::protectSystemDir ( )
static

Applies advisory read-only + hidden + system FAT attributes to the system folder so standard host file managers hide and protect it.

Best-effort: skipped while hostActive(); failures are logged and ignored.

Definition at line 277 of file PluginStorage.cpp.

References LOG_I, LOG_W, cdc::plugin_manager::s_host_active, cdc::plugin_manager::s_mounted, cdc::plugin_manager::SYSTEM_DIR, cdc::plugin_manager::TAG, and cdc::plugin_manager::vfat_drive().

Referenced by mount().

◆ remountIfPending()

void cdc::plugin_manager::PluginStorage::remountIfPending ( )
static

Performs a deferred remount scheduled by setHostActive(false).

Call from a non-USB task (e.g. a module tick) so the FATFS cache is refreshed and host-written files appear in the file browser. No-op when nothing is pending or a host is still attached.

Definition at line 268 of file PluginStorage.cpp.

References LOG_I, mount(), cdc::plugin_manager::MOUNT_POINT, cdc::plugin_manager::s_host_active, cdc::plugin_manager::s_mounted, cdc::plugin_manager::s_remount_pending, cdc::plugin_manager::TAG, and unmount().

◆ setDisabled()

bool cdc::plugin_manager::PluginStorage::setDisabled ( const std::string & id,
bool disabled )
static

Create or remove the persistent disabled marker for a plugin.

Definition at line 197 of file PluginStorage.cpp.

References disabledPath(), and cdc::core::openFile().

Referenced by cdc::plugin_manager::PluginManager::setPluginDisabled().

◆ setHostActive()

void cdc::plugin_manager::PluginStorage::setHostActive ( bool active)
static

Marks whether a USB host currently holds the volume over MSC.

While active, badge-side writers MUST refuse to write (the host is the sole writer). The active->inactive edge schedules a remount (performed by remountIfPending() on a safe task) so host-written files become visible. Safe to call from the USB task.

Parameters
activetrue when a host has mounted the MSC LUN.

Definition at line 250 of file PluginStorage.cpp.

References LOG_I, cdc::plugin_manager::s_host_active, cdc::plugin_manager::s_remount_pending, cdc::plugin_manager::TAG, and usb_msc_should_remount().

◆ stats()

bool cdc::plugin_manager::PluginStorage::stats ( uint64_t & free_bytes,
uint64_t & total_bytes )
static

Returns the free and total bytes on the plugins partition.

Definition at line 211 of file PluginStorage.cpp.

References cdc::plugin_manager::MOUNT_POINT, and cdc::plugin_manager::s_mounted.

◆ unmount()

void cdc::plugin_manager::PluginStorage::unmount ( )
static

Unmount the plugins partition (rarely used; mostly tests).

Definition at line 101 of file PluginStorage.cpp.

References cdc::plugin_manager::MOUNT_POINT, cdc::plugin_manager::s_mounted, and cdc::plugin_manager::s_wl_handle.

Referenced by cdc::plugin_manager::PluginManager::deinit(), and remountIfPending().

◆ wasmPath()

std::string cdc::plugin_manager::PluginStorage::wasmPath ( const std::string & id)
static

The documentation for this class was generated from the following files: