The struct dirent structure and friends

Let's take a look at the struct dirent structure, since that's the data structure returned by the io_read() function in case of a directory read. We'll also take a quick look at the client calls that deal with directory entries, since there are some interesting relations to the struct dirent structure.

In order for a client to work with directories, the client uses the functions closedir(), opendir(), readdir(), rewinddir(), seekdir(), and telldir().

Notice the similarity to the "normal" file-type functions (and the commonality of the resource manager messages):

Directory Function File Function Message (resmgr)
closedir() close() _IO_CLOSE_DUP
opendir() open() _IO_CONNECT
readdir() read() _IO_READ
rewinddir() lseek() _IO_LSEEK
seekdir() lseek() _IO_LSEEK
telldir() tell() _IO_LSEEK

If we assume for a moment that the opendir() and closedir() functions will be handled automatically for us, we can focus on just the _IO_READ and _IO_LSEEK messages and related functions.