Skip to content

Commit

Permalink
[#47550] Add umount syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
GPlaczek committed Aug 18, 2023
1 parent d8ffb3a commit 4d890ce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions c_lib/wasi_ext_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions c_lib/wasi_ext_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 4d890ce

Please sign in to comment.