Skip to content

Commit bc56904

Browse files
authored
[WasmFS] Allow reading from char devices in the Node backend (#26599)
Split out from #24733, this fixes a test failure in `other.test_fs_dev_random_wasmfs_rawfs` from that PR.
1 parent 57df161 commit bc56904

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

system/lib/wasmfs/backends/node_backend.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ class NodeDirectory : public Directory {
191191
if (_wasmfs_node_get_mode(childPath.c_str(), &mode)) {
192192
return nullptr;
193193
}
194-
if (S_ISREG(mode)) {
194+
// Allow reading from character device files too (e.g. `/dev/random`,
195+
// `/dev/urandom`)
196+
if (S_ISREG(mode) || S_ISCHR(mode)) {
195197
return std::make_shared<NodeFile>(mode, getBackend(), childPath);
196198
} else if (S_ISDIR(mode)) {
197199
return std::make_shared<NodeDirectory>(mode, getBackend(), childPath);

test/fs/test_fs_dev_random.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ int main() {
1313
int nread;
1414

1515
fp = fopen("/dev/random", "r");
16-
nread = fread(&data, 1, byte_count, fp);
16+
assert(fp != NULL);
17+
nread = fread(data, 1, byte_count, fp);
1718
assert(nread == byte_count);
1819
fclose(fp);
1920

2021
fp = fopen("/dev/urandom", "r");
21-
nread = fread(&data, 1, byte_count, fp);
22+
assert(fp != NULL);
23+
nread = fread(data, 1, byte_count, fp);
2224
assert(nread == byte_count);
2325
fclose(fp);
2426

0 commit comments

Comments
 (0)