The _IO_LSEEK message and related function is used to “seek” (or “move”) within a file. It does the exact same thing within a directory; you can move to the “first” directory entry (by explicitly giving an offset to seekdir() or by calling rewinddir()), or any arbitrary entry (by using seekdir()), or you can find out the current location in the directory entry list (by using telldir()).

The “trick” with directories, however, is that the seek offsets are entirely up to you to define and manage. This means that you may decide to call your directory entry offsets “0,” “1,” “2” and so on, or you may instead call them “0,” “64,” “128” and so on. The only important thing here is that the offsets must be consistent in both the io_lseek() handler as well as the io_read() handler functions.

In the example below, we'll assume that we're using the simple “0,” “1,” “2,” ... approach. (You might use the “0,” “64,” “128,” ... approach if those numbers correspond to, for example, some kind of on-media offsets. Your choice.)