Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/wasmfs/backends/opfs_backend.h
6175 views
1
#include <vector>
2
3
#include <emscripten/proxying.h>
4
5
#include "backend.h"
6
7
using namespace wasmfs;
8
9
extern "C" {
10
11
// Ensure that the root OPFS directory is initialized with ID 0.
12
void _wasmfs_opfs_init_root_directory(em_proxying_ctx* ctx);
13
14
// Look up the child under `parent` with `name`. Write 1 to `child_type` if it's
15
// a regular file or 2 if it's a directory. Write the child's file or directory
16
// ID to `child_id`, or -1 if the child does not exist, or -2 if the child
17
// exists but cannot be opened.
18
void _wasmfs_opfs_get_child(em_proxying_ctx* ctx,
19
int parent,
20
const char* name,
21
int* child_type,
22
int* child_id);
23
24
// Create a file under `parent` with `name` and store its ID in `child_id`.
25
void _wasmfs_opfs_insert_file(em_proxying_ctx* ctx,
26
int parent,
27
const char* name,
28
int* child_id);
29
30
// Create a directory under `parent` with `name` and store its ID in `child_id`.
31
void _wasmfs_opfs_insert_directory(em_proxying_ctx* ctx,
32
int parent,
33
const char* name,
34
int* child_id);
35
36
void _wasmfs_opfs_move_file(em_proxying_ctx* ctx,
37
int file_id,
38
int new_parent_id,
39
const char* name,
40
int* err);
41
42
void _wasmfs_opfs_remove_child(em_proxying_ctx* ctx,
43
int dir_id,
44
const char* name,
45
int* err);
46
47
void _wasmfs_opfs_get_entries(em_proxying_ctx* ctx,
48
int dirID,
49
std::vector<Directory::Entry>* entries,
50
int* err);
51
52
void _wasmfs_opfs_open_access(em_proxying_ctx* ctx,
53
int file_id,
54
int* access_id);
55
56
void _wasmfs_opfs_open_blob(em_proxying_ctx* ctx, int file_id, int* blob_id);
57
58
void _wasmfs_opfs_close_access(em_proxying_ctx* ctx, int access_id, int* err);
59
60
void _wasmfs_opfs_close_blob(int blob_id);
61
62
void _wasmfs_opfs_free_file(int file_id);
63
64
void _wasmfs_opfs_free_directory(int dir_id);
65
66
// Synchronous read. Return the number of bytes read.
67
int _wasmfs_opfs_read_access(int access_id,
68
uint8_t* buf,
69
uint32_t len,
70
off_t pos);
71
72
int _wasmfs_opfs_read_blob(em_proxying_ctx* ctx,
73
int blob_id,
74
uint8_t* buf,
75
uint32_t len,
76
off_t pos,
77
int32_t* nread);
78
79
// Synchronous write. Return the number of bytes written.
80
int _wasmfs_opfs_write_access(int access_id,
81
const uint8_t* buf,
82
uint32_t len,
83
off_t pos);
84
85
// Get the size via an AccessHandle.
86
void _wasmfs_opfs_get_size_access(em_proxying_ctx* ctx,
87
int access_id,
88
off_t* size);
89
90
off_t _wasmfs_opfs_get_size_blob(int blob_id);
91
92
// Get the size of a file handle via a File Blob.
93
void _wasmfs_opfs_get_size_file(em_proxying_ctx* ctx, int file_id, off_t* size);
94
95
void _wasmfs_opfs_set_size_access(em_proxying_ctx* ctx,
96
int access_id,
97
off_t size,
98
int* err);
99
100
void _wasmfs_opfs_set_size_file(em_proxying_ctx* ctx,
101
int file_id,
102
off_t size,
103
int* err);
104
105
void _wasmfs_opfs_flush_access(em_proxying_ctx* ctx, int access_id, int* err);
106
107
} // extern "C"
108
109