forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwasmfs.h
More file actions
83 lines (64 loc) · 3.06 KB
/
wasmfs.h
File metadata and controls
83 lines (64 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright 2021 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#pragma once
#include <stdint.h>
#include <sys/stat.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct Backend* backend_t;
// Obtains the backend_t of a specified path.
backend_t wasmfs_get_backend_by_path(char* path __attribute__((nonnull)));
// Obtains the backend_t of a specified fd.
backend_t wasmfs_get_backend_by_fd(int fd);
// Creates and opens a new file in the new file system under a specific backend.
// Returns the file descriptor for the new file like `open`. Returns a negative
// value on error. TODO: It might be worth returning a more specialized type
// like __wasi_fd_t here.
int wasmfs_create_file(const char* pathname __attribute__((nonnull)), mode_t mode, backend_t backend);
// Creates a new directory in the new file system under a specific backend.
// Returns 0 on success like `mkdir`, or a negative value on error.
int wasmfs_create_directory(const char* path __attribute__((nonnull)), mode_t mode, backend_t backend);
// Backend creation
// Creates a JSFile Backend in the new file system.
backend_t wasmfs_create_js_file_backend(void);
// A function that receives a void* and returns a backend.
typedef backend_t (*backend_constructor_t)(void*);
backend_t wasmfs_create_memory_backend(void);
// Note: this cannot be called on the browser main thread because it might
// deadlock while waiting for its dedicated worker thread to be spawned.
//
// Note: This function blocks on the main browser thread returning to its event
// loop. Calling this function while holding a lock the main thread is waiting
// to acquire will cause a deadlock.
//
// TODO: Add an async version of this function that will work on the main
// thread.
backend_t wasmfs_create_fetch_backend(const char* base_url __attribute__((nonnull)));
backend_t wasmfs_create_node_backend(const char* root __attribute__((nonnull)));
// Note: this cannot be called on the browser main thread because it might
// deadlock while waiting for the OPFS dedicated worker thread to be spawned.
//
// Note: This function blocks on the main browser thread returning to its event
// loop. Calling this function while holding a lock the main thread is waiting
// to acquire will cause a deadlock.
//
// TODO: Add an async version of this function that will work on the main
// thread.
backend_t wasmfs_create_opfs_backend(void);
backend_t wasmfs_create_icase_backend(backend_constructor_t create_backend,
void* arg);
// Hooks
// A hook users can do to run code during WasmFS startup. This hook happens
// before file preloading, so user code could create backends and mount them,
// which would then affect in which backend the preloaded files are loaded (the
// preloaded files have paths, and so they are added to that path and whichever
// backend is present there).
void wasmfs_before_preload(void);
#ifdef __cplusplus
}
#endif