From 4d890cee2d0af8089e4378ed44da54b1d56e1b2b Mon Sep 17 00:00:00 2001 From: Grzegorz Placzek Date: Fri, 18 Aug 2023 10:16:03 +0200 Subject: [PATCH] [#47550] Add umount syscall --- c_lib/wasi_ext_lib.c | 15 +++++++++++++++ c_lib/wasi_ext_lib.h | 1 + src/lib.rs | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/c_lib/wasi_ext_lib.c b/c_lib/wasi_ext_lib.c index 8a4ff41..7018c9e 100644 --- a/c_lib/wasi_ext_lib.c +++ b/c_lib/wasi_ext_lib.c @@ -75,6 +75,21 @@ int wasi_ext_mount(int source_fd, const char *source_path, int target_fd, return err; } +int wasi_ext_umount(const char *path) { + JsonNode *root = json_mkobject(); + + json_append_member(root, "path", json_mknumber((double)(size_t)path)); + json_append_member(root, "path_len", json_mknumber(strlen(path))); + + char *serialized = json_stringify(0, root, " "); + json_delete(root); + + int err = __syscall("umount", 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 diff --git a/c_lib/wasi_ext_lib.h b/c_lib/wasi_ext_lib.h index f3792ac..eb37c48 100644 --- a/c_lib/wasi_ext_lib.h +++ b/c_lib/wasi_ext_lib.h @@ -106,4 +106,5 @@ 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 *); +int wasi_ext_umount(const char *); #endif diff --git a/src/lib.rs b/src/lib.rs index c06f38e..d238a74 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -369,3 +369,15 @@ pub fn mount( Err(result) } } + +pub fn umount(path: &str) -> Result<(), ExitCode> { + let c_path = CString::new(path).unwrap(); + + let result = unsafe { wasi_ext_lib_generated::wasi_ext_umount(c_path.as_ptr() as *const i8) }; + + if result == 0 { + Ok(()) + } else { + Err(result) + } +}