WebAssembly / WebAssembly/WASI
How exactly should wasi:filesystem `open-flags` and `descriptor-flags` interact with native open modes/flags?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.8k
- Forks
- 333
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with proposals/filesystem/wit/types.wit, especially the open-flags::create documentation, then compare the Wasmtime filesystem implementation and the linked wasi-testsuite case. Determine the normative interaction between open-flags, descriptor-flags, and native modes, and document the agreed behavior in the specification and relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- documentation, operating-systems
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100