-
Notifications
You must be signed in to change notification settings - Fork 23
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
readdir seeking #7
Comments
Beware, that file-like (or other including DB-like etc.) APIs might in the end not be part of WASI namespace - see WebAssembly/WASI#56 (comment) and WebAssembly/WASI#38 (comment) . |
They would still be part of the WASI namespace. The idea behind the discussions you reference is that no APIs would be required. In spec terms, everything would be "normative optional": it's not required to exist, but if it exists it has to follow the specified behavior. That has no bearing on which namespace an API would be in, however. |
Another issue with this approach is that there's no way for the application to free any dirents the WASI implementation is buffering short of closing the FD. |
On Windows, is the order of elements returned by
and this stackoverflow post |
To add to this, on the POSIX side there are several issues as well. POSIX unfortunately requires The behavior of The cookie values potentially leak implementation details about the underlying filesystem. It also happens that Does anyone know of places where |
Here are some more links describing how seekdir/telldir are rarely used, tricky to use correctly, and burdensome to implement:
Also, |
I've gotten more informal feedback from people saying they aren't aware of seekdir/telldir being needed, and no one responding with places they're needed. So I'm picturing the following plan:
|
[bookkeeping] Added to the Moving wasi-filesystem to Phase 3 project. |
This makes a number of changes, to make use of interface-types features such as `expected`, variant types, and resources. The change to use resources in particular means that filesystem functions are now methods of the `descriptor` resource. Since this means renaming everything, take this opportunity to introduce a new naming conventions, with `_at` being used for functions that take dirfd+path arguments. This also eliminates the `rights` concept what was present in earlier versions of WASI, has has discussed in WebAssembly#31. This required adding new flags to `open_at`, so while here, this also adds basic `chmod`-like support, as discussed in WebAssembly#33. And, this removes support for readdir seeking (seekdir/telldir), as discussed in WebAssembly#7. And it adds a fifo file type and a more general socket type, as discussed in
This makes a number of changes, to make use of interface-types features such as `expected`, variant types, and resources. The change to use resources in particular means that filesystem functions are now methods of the `descriptor` resource. Since this means renaming everything, take this opportunity to introduce a new naming conventions, with `_at` being used for functions that take dirfd+path arguments. This also eliminates the `rights` concept what was present in earlier versions of WASI, has has discussed in WebAssembly#31. This required adding new flags to `open_at`, so while here, this also adds basic `chmod`-like support, as discussed in WebAssembly#33. And, this removes support for readdir seeking (seekdir/telldir), as discussed in WebAssembly#7. And it adds a fifo file type and a more general socket type, as discussed in
This makes a number of changes, to make use of interface-types features such as `expected`, variant types, and resources. The change to use resources in particular means that filesystem functions are now methods of the `descriptor` resource. Since this means renaming everything, take this opportunity to introduce a new naming conventions, with `_at` being used for functions that take dirfd+path arguments. This also eliminates the `rights` concept what was present in earlier versions of WASI, has has discussed in WebAssembly#31. This required adding new flags to `open_at`, so while here, this also adds basic `chmod`-like support, as discussed in WebAssembly#33. And, this removes support for readdir seeking (seekdir/telldir), as discussed in WebAssembly#7. And it adds a fifo file type and a more general socket type, as discussed in
This makes a number of changes, to make use of interface-types features such as expected, variant types, and resources. The change to use resources in particular means that filesystem functions are now methods of the descriptor resource. Since this means renaming everything, take this opportunity to introduce a new naming conventions, with _at being used for functions that take dirfd+path arguments. This also eliminates the rights concept what was present in earlier versions of WASI, has has discussed in WebAssembly#31. This required adding new flags to open_at, so while here, this also adds basic chmod-like support, as discussed in WebAssembly#33. And, this removes support for readdir seeking (seekdir/telldir), as discussed in WebAssembly#7. And it adds a fifo file type and a more general socket type, as discussed in WebAssembly#4.
This makes a number of changes, to make use of interface-types features such as expected, variant types, and resources. The change to use resources in particular means that filesystem functions are now methods of the descriptor resource. Since this means renaming everything, take this opportunity to introduce a new naming conventions, with _at being used for functions that take dirfd+path arguments. This also eliminates the rights concept what was present in earlier versions of WASI, has has discussed in #31. This required adding new flags to open_at, so while here, this also adds basic chmod-like support, as discussed in #33. And, this removes support for readdir seeking (seekdir/telldir), as discussed in #7. And it adds a fifo file type and a more general socket type, as discussed in #4.
As an update here:
|
The preview2 wasi-filesystem API now has a |
POSIX API:
Note that the locations returned by
telldir
are invalidated byrewinddir
. It's also unspecified whether changes to the directory sinceopendir
orrewinddir
were called will be reflected.Windows API:
Windows Vista+ also has
GetFileInformationByHandleEx
that works with an open file handle instead of a search path, and can be called withFileIdBothDirectoryInfo
to readdirent
info into a buffer.Neither Windows API supports anything like
seekdir
. There's a way to reset the internal pointer inGetFileInformationByHandleEx
to the beginning, and you can always callFindClose
+FindFirstFileW
again to implementrewinddir
.WASI's API:
To map this to the stateful POSIX or Win32 APIs, a WASI implementation needs to mirror the host API's positional state, and determine whether a seek is implied by the cookie argument.
On Windows, that may imply restarting the enumeration from the beginning, and enumerating flies until it reaches whatever file it associates with cookie. Restarting the enumeration could lead to some WASI applications that run in
O(numDirEnts^2)
time on Windows directories despite running inO(numDirEnts)
time on other directories, so it's not practical IMO.Alternatively, the WASI implementation may buffer the previously read dirents, and just move the buffer pointer back to the direct with the specified cookie. I think this is undesirable because there's already buffering at the host API level, and likely also in the WASI application itself (e.g. in the WASI libc).
Finally, WASI could remove seeking from the current API, so it just streams dirents sequentially, and has an argument or an additional entry point to restart from the beginning. That wouldn't require WASI implementations to do any extra buffering on Windows, but it does mean that WASI applications that need to seek must buffer the dirents themselves.
The text was updated successfully, but these errors were encountered: