Skip to content

Commit

Permalink
[#61992] Support mknod syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
GPlaczek committed Jul 5, 2024
1 parent cde96d9 commit 366db8f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions c_lib/wasi_ext_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions c_lib/wasi_ext_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<termios::termios, ExitCode> {
let mut termios_p: termios::termios = unsafe { mem::zeroed() };
let result = unsafe {
Expand Down

0 comments on commit 366db8f

Please sign in to comment.