Stream: wasi

Topic: seekdir/telldir


view this post on Zulip Dan Gohman (Oct 15 2020 at 19:27):

Does anyone know of an example of seekdir/telldir being used in the real world?

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:05):

@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).

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:05):

I've never seen code that tries to seek to anywhere other than the beginning.

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:06):

Awesome, thanks for the feedback.

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:06):

I think getdents64 is the directory interface we should strive to emulate, and readdir is just the compatible portable interface.

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:07):

"get many" is the right interface; "get one at a time" can easily be built atop that if needed.

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:08):

We kind of do already have that, in fd_readdir

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:10):

There's room for improvement, but it does read many entries into a buffer.

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:11):

/me nods.

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:12):

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.

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:13):

That's my guess as well.

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:13):

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.

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:13):

(rewinddir seems vaguely reasonable to provide, on the other hand)

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:13):

Cool. Yeah, the seekdir/telldir interface clearly dates to a time when a directory was just a flat table

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:17):

is getdents64 in Linux stateful? That is, does it remember its position so that the next call starts where the previous one left off?

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:18):

Yes, it updates the internal offset, and doesn't take an offset. There's no equivalent pgetdents64.

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:18):

Relatedly...

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:18):

Is anything actually using dircookie? That seems closely related to seekdir/telldir, and seems similarly hard to support.

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:19):

dircookie is just for seekdir/telldir and rewinddir

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:19):

as far as I know. Nothing else in WASI libc uses it, I've never heard of anything else using it

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:19):

So fd_readdir could drop that if WASI doesn't need to support seekdir and telldir?

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:20):

Yeah. And then maybe we add a new fd_rewinddir to implement the rewind case

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:20):

Right.

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:20):

That sounds implementable on both getdents-style hosts and readdir-style hosts

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:21):

Worst case, you can probably emulate rewinddir by reopening, modulo capabilities.

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:21):

true, though it's more POSIX-friendly if you don't have to, because maybe someone renamed it

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:22):

I meant reopening the fd, not the file path.

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:22):

Though I guess that's an operation that also doesn't exist on all systems.

view this post on Zulip Josh Triplett (Oct 26 2020 at 23:23):

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.

view this post on Zulip Dan Gohman (Oct 26 2020 at 23:24):

Yeah, there are a few details to work out, but it sounds like a reasonable plan


Last updated: Dec 23 2024 at 13:07 UTC