-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify the spec of fd_readdir #3
Comments
If a sequence of two directory entries are written into the buffer, how do you compute the second one's position? Are they densely packed without care for machine alignment? Or are they padded somehow to keep the wasi_dirent_t fields aligned? The getdents system calls on Linux and BSD include |
@mdempsky They appear to be tightly packed: laid out as |
@MarkMcCaskey Thanks. Does wasm allow unaligned memory accesses? I just tried looking at the wasm spec, and I see mention of alignment in memarg, but I couldn't immediately find any explanation of what happens if the address doesn't have the expected alignment. Does it affect correctness or is it just a performance hint? If unaligned memory accesses are guaranteed by wasm, then densely packing seems like a reasonable choice. That should probably be explicitly stated though. |
Yes, but they may be slower depending on the target arch. For exmple arm requires emulation for that. |
The spec states that for the result
However, I noticed in my implementation that I get another call even if bytes stored in less than the size if the read buffer. Returning 0 as the bytes stored correctly signals the end of the directory. If this is the desired behavior the spec could be simplified in a way that we don't have to fill in a truncated directory entry name. |
The readdir definition in the current wit files doesn't yet clarify or address thie issue, however it is still using the |
The readdir entry API is now updated to use a stream type: #72 |
The current specification of
fd_readdir
is too vague. While working on the new implementation offd_readdir
forwasmtime
I have noticed several issues. All of this refers to the spec offd_readdir
as found in https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md#fd_readdirOn Unix,
readdir(3p)
explicitly states that entries for.
and..
will be returned if they exist, (and I haven't ever encountered a case where they are not returned) but on Windows a similar syscall,FindNextFileW
, will not return such entries.The WASI spec is not clear if the implementation should emulate the Unix-like behavior and return
.
&..
even if the target platform's syscall doesn't explicitly return them.The validity period of cookies is not covered. For instance,
seekdir(3p)
explicitly states that:Moreover,
readdir(3p)
explicitly states that:The WASI spec doesn't say which operations (if any) invalidate the cookies, so it's natural to assume that the cookies will be valid indefinitely and that
fd_readdir
should reflect the current state of the filesystem, which is very difficult to implement efficiently (if possible at all).In particular, call to
fd_readdir
with cookie equal to__WASI_DIRCOOKIE_START
will invalidate any other cookies returned by previous calls tofd_readdir
with the natural implementation usingreaddir
.Finally, it would be worth noting that this WASI syscall is similar to
readdir
/seekdir
/telldir
on Unix and that cookies should be treated as opaque values asreaddir(3)
says. I'd also be a little more elaborate on the semantics and what kind of location does the cookie point to, because the doc was completely unclear to me at the beginning. It may also be a good idea to stress that the entry names are not null terminated, unlike in POSIXreaddir
.cc @kubkon @sunfishcode
The text was updated successfully, but these errors were encountered: