27constexpr size_t MAX_NAME_LEN = 64;
30bool nameOk(
const char*
name)
33 size_t n = std::strlen(
name);
34 if (n > MAX_NAME_LEN ||
name[0] ==
'.')
return false;
35 for (
size_t i = 0; i < n; ++i) {
37 bool ok = (c >=
'A' && c <=
'Z') || (c >=
'a' && c <=
'z') ||
38 (c >=
'0' && c <=
'9') || c ==
'.' || c ==
'_' || c ==
'-';
39 if (!ok)
return false;
45int resolveDir(std::string& out)
51 std::string dataRoot =
53 mkdir(dataRoot.c_str(), 0755);
54 out = dataRoot +
"/" + plugin->id();
55 mkdir(out.c_str(), 0755);
60int resolvePath(
const char*
name, std::string& out)
63 int rc = resolveDir(dir);
66 out = dir +
"/" +
name;
78 int rc = resolvePath(
name, path);
83 if (len > 0 && std::fwrite(data, 1, len, f.get()) != len)
return HOST_ERR_GENERIC;
91 int rc = resolvePath(
name, path);
96 *len = std::fread(buf, 1, *len, f.get());
103 int rc = resolvePath(
name, path);
112 int rc = resolvePath(
name, path);
117 *out =
static_cast<size_t>(st.st_size);
125 int rc = resolveDir(dir);
128 DIR* d = opendir(dir.c_str());
132 const size_t max = (out ? *out_len : 0);
133 for (
struct dirent* e = readdir(d); e !=
nullptr; e = readdir(d)) {
134 if (e->d_name[0] ==
'.')
continue;
135 size_t need = std::strlen(e->d_name) + 1;
136 if (out && (written + need) <= max) {
137 std::memcpy(out + written, e->d_name, need - 1);
138 out[written + need - 1] =
'\n';
150 int rc = resolvePath(
name, path);
157 constexpr size_t VIEW_MAX = 2048;
159 content.resize(VIEW_MAX);
160 size_t n = std::fread(&content[0], 1, VIEW_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. "/plugins".
int host_ui_push_info(const char *title, const char *body)
Show a scrollable info screen with title and body.
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)
FilePtr openFile(const char *path, const char *mode) noexcept
Open a FILE* and wrap it in a FilePtr.