Skip to content

Commit

Permalink
[#47550] Add mount syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
GPlaczek committed Aug 14, 2023
1 parent 548a2f6 commit b1b0239
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
36 changes: 36 additions & 0 deletions c_lib/wasi_ext_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,42 @@ int __syscall(const char *command, char *args, uint8_t *output_buf,
return err;
}

int wasi_ext_mount(int source_fd, const char *source_path, int target_fd,
const char *target_path, const char *filesystem_type,
uint64_t mount_flags, const char *data) {
JsonNode *root = json_mkobject();

json_append_member(root, "source_fd", json_mknumber((double)source_fd));
json_append_member(root, "source",
json_mknumber((double)(size_t)source_path));
json_append_member(root, "source_len",
json_mknumber((double)strlen(source_path)));

json_append_member(root, "target_fd", json_mknumber((double)target_fd));
json_append_member(root, "target",
json_mknumber((double)(size_t)target_path));
json_append_member(root, "target_len",
json_mknumber((double)strlen(target_path)));

json_append_member(root, "filesystemtype",
json_mknumber((double)(size_t)filesystem_type));
json_append_member(root, "filesystemtype_len",
json_mknumber((double)strlen(filesystem_type)));

json_append_member(root, "mountflags", json_mknumber((double)mount_flags));

json_append_member(root, "data", json_mknumber((double)(size_t)data));
json_append_member(root, "data_len", json_mknumber((double)strlen(data)));

char *serialized = json_stringify(0, root, " ");
json_delete(root);

int err = __syscall("mount", serialized, NULL, 0);
free(serialized);

return err;
}

int wasi_ext_chdir(const char *path) {
// wasi lib doesn't support realpath, so the given path must be
// canonicalized
Expand Down
3 changes: 2 additions & 1 deletion c_lib/wasi_ext_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@ int wasi_ext_spawn(const char *, const char *const *, size_t,
int wasi_ext_kill(int, int);
int wasi_ext_ioctl(int, unsigned int, void *);
int wasi_ext_fcntl(int, enum FcntlCommand, void *);

int wasi_ext_mount(int, const char *, int, const char *, const char *, uint64_t,
const char *);
#endif
34 changes: 34 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,37 @@ pub fn fcntl(fd: wasi::Fd, cmd: FcntlCommand) -> Result<i32, ExitCode> {
Ok(result)
}
}

pub fn mount(
source_fd: RawFd,
source_path: &str,
target_fd: RawFd,
target_path: &str,
filesystem_type: &str,
opts: u64,
data: &str,
) -> Result<(), ExitCode> {
let c_source_path = CString::new(source_path).unwrap();
let c_target_path = CString::new(target_path).unwrap();

let c_filesystem_type = CString::new(filesystem_type).unwrap();
let c_data = CString::new(data).unwrap();

let result = unsafe {
wasi_ext_lib_generated::wasi_ext_mount(
source_fd,
c_source_path.as_ptr() as *const i8,
target_fd,
c_target_path.as_ptr() as *const i8,
c_filesystem_type.as_ptr() as *const i8,
opts,
c_data.as_ptr() as *const i8,
)
};

if result == 0 {
Ok(())
} else {
Err(result)
}
}

0 comments on commit b1b0239

Please sign in to comment.