-
Notifications
You must be signed in to change notification settings - Fork 725
Open
Labels
platformcore/shared/platformcore/shared/platform
Description
OS: Zephyr v3.7.1
WAMR brance: https://github.com/bytecodealliance/wasm-micro-runtime/tree/dev/zephyr_file_socket
Hardware: NUCLEO-H563ZI
Zephyr File System: lfs/test.txt
WAMR FS interaction folder: --dir=/lfs
Runtime implement:
const char * wasi_dir = "/lfs";
/* load WASM module */
wasm_module = wasm_runtime_load(wasm_file_buf, entry.size, error_buf, sizeof(error_buf));
wasm_runtime_set_wasi_args_ex(wasm_module, &wasi_dir, 1, NULL, 0, NULL, 0, NULL, 0, 0, 1, 2);
/* instantiate the module */
wasm_module_inst =
wasm_runtime_instantiate(wasm_module, CONFIG_APP_STACK_SIZE, CONFIG_APP_HEAP_SIZE, error_buf, sizeof(error_buf));
wasm_application_execute_main(module_inst, app_argc, app_argv);
Application code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
void list_dir(const char *path)
{
struct dirent *entry;
DIR *dp;
dp = opendir(path);
if (dp == NULL) {
printf("opendir %s\r\n", strerror(errno));
return;
}
while ((entry = readdir(dp))) {
printf("%s ", entry->d_name);
if (DT_DIR == entry->d_type) {
printf("dir\n");
}
else if (DT_REG == entry->d_type) {
printf("file\n");
}
else {
printf("other\n");
}
}
closedir(dp);
}
int
main(int argc, char **argv)
{
printf("Hello world!\n");
list_dir("/lfs");
return 0;
}
Result output:
Hello world!
[00:05:57.244,000] <err> fs: file open error (-21)
opendir
elapsed: 38
Is there any problem with this usage? If the design is like this, please help correct the mistakes. Thank you.
Metadata
Metadata
Assignees
Labels
platformcore/shared/platformcore/shared/platform