30constexpr size_t MAX_NAME_LEN = 64;
33bool nameOk(
const char*
name)
36 size_t n = std::strlen(
name);
37 if (n > MAX_NAME_LEN ||
name[0] ==
'.')
return false;
38 for (
size_t i = 0; i < n; ++i) {
40 bool ok = (c >=
'A' && c <=
'Z') || (c >=
'a' && c <=
'z') ||
41 (c >=
'0' && c <=
'9') || c ==
'.' || c ==
'_' || c ==
'-';
42 if (!ok)
return false;
48int resolveDir(std::string& out)
54 std::string dataRoot =
56 mkdir(dataRoot.c_str(), 0755);
57 out = dataRoot +
"/" + plugin->id();
58 mkdir(out.c_str(), 0755);
63int resolvePath(
const char*
name, std::string& out)
66 int rc = resolveDir(dir);
69 out = dir +
"/" +
name;
81 int rc = resolvePath(
name, path);
86 if (len > 0 && std::fwrite(data, 1, len, f.get()) != len)
return HOST_ERR_GENERIC;
94 int rc = resolvePath(
name, path);
99 *len = std::fread(buf, 1, *len, f.get());
106 int rc = resolvePath(
name, path);
115 int rc = resolvePath(
name, path);
120 *out =
static_cast<size_t>(st.st_size);
128 int rc = resolveDir(dir);
131 DIR* d = opendir(dir.c_str());
135 const size_t max = (out ? *out_len : 0);
136 for (
struct dirent* e = readdir(d); e !=
nullptr; e = readdir(d)) {
137 if (e->d_name[0] ==
'.')
continue;
138 size_t need = std::strlen(e->d_name) + 1;
139 if (out && (written + need) <= max) {
140 std::memcpy(out + written, e->d_name, need - 1);
141 out[written + need - 1] =
'\n';
153 int rc = resolvePath(
name, path);
160 constexpr size_t VIEW_MAX = 2048;
162 content.resize(VIEW_MAX);
163 size_t n = std::fread(&content[0], 1, VIEW_MAX - 1, f.get());
172 int rc = resolvePath(
name, path);
178 constexpr size_t IMG_MAX = 512 * 1024;
181 size_t n = std::fread(&buf[0], 1, IMG_MAX, f.get());
186 reinterpret_cast<const uint8_t*
>(buf.data()), buf.size());
193 int rc = resolvePath(
name, path);
199 constexpr size_t MD_MAX = 64 * 1024;
201 content.resize(MD_MAX);
202 size_t n = std::fread(&content[0], 1, MD_MAX - 1, f.get());
Mounts the FAT-FS partition that holds plugin .wasm + .meta files.
Owned WAMR module instance + per-plugin state.
char name[cdc::hal::ISecureElement::RMEM_NAME_LEN]
Shared RAII wrappers for firmware resources.
static const char * basePath()
Returns the VFS path prefix, e.g. "/vfat".
int host_ui_push_info(const char *title, const char *body)
Show a scrollable info screen with title and body.
int host_fs_view_markdown(const char *name)
Render and show one of the plugin's own Markdown files in the scrollable text viewer.
int host_fs_view_image(const char *name)
Decode and show one of the plugin's own image files (PNG/JPEG) on the e-paper, dithered and scaled to...
int host_fs_view(const char *name)
Open one of the plugin's own files in a scrollable on-screen text viewer (same as opening the file in...
int host_fs_size(const char *name, size_t *out)
Write the byte size of name to *out.
int host_fs_read(const char *name, uint8_t *buf, size_t *len)
Read name into buf.
int host_fs_remove(const char *name)
Delete name.
int host_fs_write(const char *name, const uint8_t *data, size_t len)
Create or overwrite name with len bytes.
int host_fs_list(char *out, size_t *out_len)
Enumerate the plugin's own files.
CDC Badge OS plugin host API - canonical C ABI contract.
#define HOST_ERR_NO_CAPABILITY
#define HOST_ERR_INVALID_ARG
#define HOST_ERR_NOT_FOUND
void * plg_get_active_plugin(void)
Internal UTF-8 <-> CP437 helpers for the plugin host API boundary.
FilePtr openFile(const char *path, const char *mode) noexcept
Open a FILE* and wrap it in a FilePtr.
std::string toDisplay(const char *utf8)
Decode a UTF-8 (with optional HTML entities) string into CP437 bytes.
MarkdownView * showMarkdown(const char *title, const char *src, size_t len)
Parses and shows a Markdown source on the view stack.
ImageView * showImage(const char *title, const uint8_t *data, size_t len)
Decodes and shows an image on the view stack.