7#include "esp_vfs_fat.h"
8#include "esp_partition.h"
19static const char*
TAG =
"PLG_STO";
30 const esp_vfs_fat_mount_config_t cfg = {
31 .format_if_mount_failed =
true,
33 .allocation_unit_size = CONFIG_WL_SECTOR_SIZE,
34 .disk_status_check_enable =
false,
38 esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(
41 LOG_E(
TAG,
"mount failed: 0x%x", err);
63static bool ends_with(
const char* s,
size_t s_len,
const char* suffix,
size_t suf_len)
65 return s_len > suf_len && std::strcmp(s + s_len - suf_len, suffix) == 0;
70 std::vector<std::string> ids;
79 while (
struct dirent* ent = readdir(dir)) {
80 const char*
name = ent->d_name;
81 size_t len = std::strlen(
name);
84 id.assign(
name, len - 4);
86 id.assign(
name, len - 5);
90 if (std::find(ids.begin(), ids.end(),
id) != ids.end())
continue;
94 if (stat(meta.c_str(), &st) == 0 && (st.st_mode & S_IFREG)) {
95 ids.push_back(std::move(
id));
105#if FEATURE_PLUGIN_AOT
108 if (stat(aot.c_str(), &st) == 0 && (st.st_mode & S_IFREG)) {
117 return std::string(
MOUNT_POINT) +
"/" +
id +
".wasm";
122 return std::string(
MOUNT_POINT) +
"/" +
id +
".aot";
127 return std::string(
MOUNT_POINT) +
"/" +
id +
".meta";
132 return std::string(
MOUNT_POINT) +
"/" +
id +
".lang";
137 return std::string(
MOUNT_POINT) +
"/" +
id +
".disabled";
144 return stat(path.c_str(), &st) == 0 && (st.st_mode & S_IFREG);
152 return std::remove(path.c_str()) == 0 || errno == ENOENT;
156 if (!fp)
return false;
157 static constexpr char kMarker[] =
"disabled\n";
158 return std::fwrite(kMarker, 1,
sizeof(kMarker) - 1, fp.get()) ==
sizeof(kMarker) - 1;
164 return esp_vfs_fat_info(
MOUNT_POINT, &total_bytes, &free_bytes) == ESP_OK;
Mounts the FAT-FS partition that holds plugin .wasm + .meta files.
char name[cdc::hal::ISecureElement::RMEM_NAME_LEN]
Shared RAII wrappers for firmware resources.
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_W(tag, fmt,...)
#define LOG_I(tag, fmt,...)
#define LOG_E(tag, fmt,...)
static bool mount()
Mount the plugins partition. Auto-formats if empty.
static const char * basePath()
Returns the VFS path prefix, e.g. "/plugins".
static std::string langPath(const std::string &id)
Returns the full VFS path of <id>.lang (translation overlay).
static void unmount()
Unmount the plugins partition (rarely used; mostly tests).
static std::string aotPath(const std::string &id)
Returns the full VFS path of <id>.aot.
static bool stats(uint64_t &free_bytes, uint64_t &total_bytes)
Returns the free and total bytes on the plugins partition.
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 std::string disabledPath(const std::string &id)
Returns the full VFS path of <id>.disabled.
static std::vector< std::string > listPluginIds()
Discover all installed plugin ids. A plugin is recognised by the presence of both <id>....
static std::string wasmPath(const std::string &id)
Returns the full VFS path of <id>.wasm.
static std::string metaPath(const std::string &id)
Returns the full VFS path of <id>.meta.
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>....
FilePtr openFile(const char *path, const char *mode) noexcept
Open a FILE* and wrap it in a FilePtr.
static const char * MOUNT_POINT
static bool ends_with(const char *s, size_t s_len, const char *suffix, size_t suf_len)
static wl_handle_t s_wl_handle
static const char * PARTITION_LABEL