Currently in Wasmtime it's possible to get possibly-surprising behavior with opening files. This program:
fn main() {
let dirs = wasip2::filesystem::preopens::get_directories();
let (dir, _) = &dirs[0];
let f = dir
.open_at(
wasip2::filesystem::types::PathFlags::empty(),
"hi.txt",
wasip2::filesystem::types::OpenFlags::CREATE,
wasip2::filesystem::types::DescriptorFlags::empty(),
)
.unwrap();
dbg!(f.get_flags());
}
outputs:
[src/main.rs:12:5] f.get_flags() = Ok(
DescriptorFlags(
READ | WRITE,
),
)
Where this is an example where open_at did not request any flags, yet the descriptor is both readable and writable. This behavior is additionally part of wasi-testsuite, but my hunch is that it's mostly derivative of Wasmtime's current implementation which isn't authoritative. Wasmtime's own implementation is derivative of Rust's own OpenOptions::create method which requires that when creating files write is used as a permission.
Currently the documentation of open-flags::create is that it's similar to O_CREAT, but this doesn't mention any relationship with read/write flags/permissions. Additionally my local man page for the open syscalls says that one of O_{RDONLY,WRONLY,RDWR} must be specified, but WASI's open-at doesn't currently have the same restriction.
Overall I don't feel that there's an "obviously correct" answer here so I'm seeking guidance from the upstream specification itself here. What should the precise behavior be for all these flags when dealing with filesystem methods? For reference Wasmtime's implementation is here and this is where OpenFlags::CREATE turns into a request for writability too.
Currently in Wasmtime it's possible to get possibly-surprising behavior with opening files. This program:
outputs:
Where this is an example where
open_atdid not request any flags, yet the descriptor is both readable and writable. This behavior is additionally part of wasi-testsuite, but my hunch is that it's mostly derivative of Wasmtime's current implementation which isn't authoritative. Wasmtime's own implementation is derivative of Rust's ownOpenOptions::createmethod which requires that when creating fileswriteis used as a permission.Currently the documentation of
open-flags::createis that it's similar toO_CREAT, but this doesn't mention any relationship with read/write flags/permissions. Additionally my localmanpage for theopensyscalls says that one ofO_{RDONLY,WRONLY,RDWR}must be specified, but WASI'sopen-atdoesn't currently have the same restriction.Overall I don't feel that there's an "obviously correct" answer here so I'm seeking guidance from the upstream specification itself here. What should the precise behavior be for all these flags when dealing with filesystem methods? For reference Wasmtime's implementation is here and this is where
OpenFlags::CREATEturns into a request for writability too.