Does anyone know of an example of seekdir
/telldir
being used in the real world?
@Dan Gohman The only time I've ever seen it used, it was just used to reset to the beginning of the directory (rather than reopening the directory).
I've never seen code that tries to seek to anywhere other than the beginning.
Awesome, thanks for the feedback.
I think getdents64
is the directory interface we should strive to emulate, and readdir is just the compatible portable interface.
"get many" is the right interface; "get one at a time" can easily be built atop that if needed.
We kind of do already have that, in fd_readdir
There's room for improvement, but it does read many entries into a buffer.
/me nods.
I'm guessing (and this is just a guess) that seekdir/telldir were more important when directory reading was much slower and one-at-a-time, and might need to be a pause-and-resume thing.
That's my guess as well.
May also be an artifact from systems that were more transparent that a directory was "just a file" whose contents were ABI. Either way, I really can't imagine a use case for them in WASI, and I suspect no program would break if they just weren't there.
(rewinddir seems vaguely reasonable to provide, on the other hand)
Cool. Yeah, the seekdir/telldir interface clearly dates to a time when a directory was just a flat table
is getdents64
in Linux stateful? That is, does it remember its position so that the next call starts where the previous one left off?
Yes, it updates the internal offset, and doesn't take an offset. There's no equivalent pgetdents64
.
Relatedly...
Is anything actually using dircookie
? That seems closely related to seekdir/telldir, and seems similarly hard to support.
dircookie
is just for seekdir/telldir and rewinddir
as far as I know. Nothing else in WASI libc uses it, I've never heard of anything else using it
So fd_readdir
could drop that if WASI doesn't need to support seekdir and telldir?
Yeah. And then maybe we add a new fd_rewinddir
to implement the rewind case
Right.
That sounds implementable on both getdents
-style hosts and readdir
-style hosts
Worst case, you can probably emulate rewinddir by reopening, modulo capabilities.
true, though it's more POSIX-friendly if you don't have to, because maybe someone renamed it
I meant reopening the fd, not the file path.
Though I guess that's an operation that also doesn't exist on all systems.
In any case, yeah, open/read/close/rewind seems like a sufficient set for what people do with directories, together with the various *at
operations relative to them.
Yeah, there are a few details to work out, but it sounds like a reasonable plan
Last updated: Nov 22 2024 at 16:03 UTC