Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/virtual-fs/src/mem_fs/file_opener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ impl FileSystem {
file: Mutex::new(file),
metadata: {
let time = time();
let is_char_device = path.starts_with("/dev");
Metadata {
ft: FileType {
file: true,
file: !is_char_device,
char_device: is_char_device,
..Default::default()
},
accessed: time,
Expand Down
9 changes: 8 additions & 1 deletion lib/wasix/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2434,11 +2434,18 @@ impl FileSystem for FallbackFileSystem {
}

pub fn virtual_file_type_to_wasi_file_type(file_type: virtual_fs::FileType) -> Filetype {
// TODO: handle other file types
if file_type.is_dir() {
Filetype::Directory
} else if file_type.is_file() {
Filetype::RegularFile
} else if file_type.is_char_device() {
Filetype::CharacterDevice
} else if file_type.is_block_device() {
Filetype::BlockDevice
} else if file_type.is_socket() {
Filetype::SocketStream
} else if file_type.is_fifo() {
Filetype::Unknown
} else if file_type.is_symlink() {
Filetype::SymbolicLink
} else {
Expand Down
41 changes: 41 additions & 0 deletions tests/wasix/dev-null-stat/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

static void fail(const char* msg) {
perror(msg);
exit(1);
}

int main(void) {
struct stat st;

if (stat("/dev/null", &st) != 0) {
fail("stat /dev/null");
}
if (!S_ISCHR(st.st_mode)) {
fprintf(stderr, "stat(/dev/null) mode %#o is not char device\n",
st.st_mode);
return 1;
}

int fd = open("/dev/null", O_RDWR);
if (fd < 0) {
fail("open /dev/null");
}
if (fstat(fd, &st) != 0) {
fail("fstat /dev/null");
}
if (!S_ISCHR(st.st_mode)) {
fprintf(stderr, "fstat(/dev/null) mode %#o is not char device\n",
st.st_mode);
close(fd);
return 1;
}

close(fd);
printf("0");
return 0;
}
6 changes: 6 additions & 0 deletions tests/wasix/dev-null-stat/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

$WASMER_RUN ./main.wasm > output

printf "0" | diff -u output - 1>/dev/null
Loading