diff --git a/c_lib/wasi_ext_lib.c b/c_lib/wasi_ext_lib.c index 5093816..2cdb169 100644 --- a/c_lib/wasi_ext_lib.c +++ b/c_lib/wasi_ext_lib.c @@ -343,3 +343,17 @@ int wasi_ext_fcntl(int fd, enum FcntlCommand cmd, void *arg) { return -EINVAL; } + +int wasi_ext_mknod(const char *path, int dev) { + JsonNode *root = json_mkobject(); + json_append_member(root, "path", json_mkstring(path)); + json_append_member(root, "dev", json_mknumber(dev)); + + char *serialized = json_stringify(0, root, " "); + json_delete(root); + + int err = __syscall("mknod", serialized, NULL, 0); + free(serialized); + + return err; +} diff --git a/c_lib/wasi_ext_lib.h b/c_lib/wasi_ext_lib.h index 83c1523..24a9cd1 100644 --- a/c_lib/wasi_ext_lib.h +++ b/c_lib/wasi_ext_lib.h @@ -48,6 +48,8 @@ #define WASI_EXT_FDFLAG_MASK ((__wasi_fdflags_t)0xffc0) #define WASI_EXT_FDFLAG_CLOEXEC ((__wasi_fdflags_t)0x0040) +#define MKDEV(maj, min) ((maj << 20) | min) + // Fnctl commands enum FcntlCommand { F_MVFD, F_GETFD, F_SETFD }; @@ -108,5 +110,6 @@ 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 *); +int wasi_ext_mknod(const char *, int); #endif diff --git a/src/lib.rs b/src/lib.rs index dd81a6a..3173489 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -419,6 +419,22 @@ pub fn umount(path: &str) -> Result<(), ExitCode> { } } +pub fn mkdev(maj: i32, min: i32) -> i32 { + (maj << 20) | min +} + +pub fn mknod(path: &str, dev: i32) -> Result<(), ExitCode> { + let c_path = CString::new(path).unwrap(); + + let result = unsafe { wasi_ext_lib_generated::wasi_ext_mknod(c_path.as_ptr(), dev) }; + + if result == 0 { + Ok(()) + } else { + Err(result) + } +} + pub fn tcgetattr(fd: Fd) -> Result { let mut termios_p: termios::termios = unsafe { mem::zeroed() }; let result = unsafe {