Path: blob/main/system/lib/wasmfs/backends/node_backend.h
6175 views
// Copyright 2022 The Emscripten Authors. All rights reserved.1// Emscripten is available under two separate licenses, the MIT license and the2// University of Illinois/NCSA Open Source License. Both these licenses can be3// found in the LICENSE file.45#include <sys/stat.h> // for mode_t67extern "C" {89// These helper functions are defined in library_wasmfs_node.js.1011// Fill `entries` and return 0 or an error code.12int _wasmfs_node_readdir(const char* path, void* entries13/* std::vector<Directory::Entry>*/);14// Write `mode` and return 0 or an error code.15int _wasmfs_node_get_mode(const char* path, mode_t* mode);1617// Write `size` and return 0 or an error code.18int _wasmfs_node_stat_size(const char* path, uint32_t* size);19int _wasmfs_node_fstat_size(int fd, uint32_t* size);2021// Create a new file system entry and return 0 or an error code.22int _wasmfs_node_insert_file(const char* path, mode_t mode);23int _wasmfs_node_insert_directory(const char* path, mode_t mode);2425// Unlink the given file and return 0 or an error code.26int _wasmfs_node_unlink(const char* path);27int _wasmfs_node_rmdir(const char* path);2829int _wasmfs_node_truncate(const char* path, off_t len);30int _wasmfs_node_ftruncate(int fd, off_t len);3132int _wasmfs_node_rename(const char* oldpath, const char* newpath);3334int _wasmfs_node_symlink(const char *target, const char *linkpath);3536int _wasmfs_node_readlink(const char *path, const char *buf, int bufsize);3738// Open the file and return the underlying file descriptor.39[[nodiscard]] int _wasmfs_node_open(const char* path, const char* mode);4041// Close the underlying file descriptor.42[[nodiscard]] int _wasmfs_node_close(int fd);4344// Read up to `size` bytes into `buf` from position `pos` in the file, writing45// the number of bytes read to `nread`. Return 0 on success or an error code.46int _wasmfs_node_read(47int fd, void* buf, uint32_t len, uint32_t pos, uint32_t* nread);4849// Write up to `size` bytes from `buf` at position `pos` in the file, writing50// the number of bytes written to `nread`. Return 0 on success or an error code.51int _wasmfs_node_write(52int fd, const void* buf, uint32_t len, uint32_t pos, uint32_t* nwritten);5354} // extern "C"555657