In the libfuse documentation there are both readdir
and opendir
as defined operations.
From what I have found, readdir
is the one which will list out the contents of a directory. If so, what is the function of opendir
? The documentation states that this opens the directory but what does opening a directory actually mean if it is not simply listing its content?
opendir doesn't do any listing. It's purpose is to open a file handle, which is the interface on which the listing can be done using readdir. It does the checking of the existence of the directory path, whether the caller has permissions to open, etc and so it might return an error in case it's not possible to do the listing.
The handle provided by opendir serves as a listing state context - it holds the current listing offset and it can be manipulated to be rewinded or to jump ahead forward using seek.
The relation between the two corresponds to open and read. In addition, these Fuse functions implement the real OS functions:
https://www.gnu.org/software/libc/manual/html_node/Opening-a-Directory.html
https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html