implementation of opendir and readdir

Li, Yang YLi@ballytech.com
Wed Sep 4 17:30:00 GMT 2013


Hi,

I am in the process of implementing some customized file system.  I am wondering how the call stack works when a user calls opendir and readdir.

When I exam the source code:
glibc-2.18/dirent/readdir.c

I see the following:
----------------------------------------
struct dirent *
__readdir (DIR *dirp)
{
  __set_errno (ENOSYS);
  return NULL;
}
weak_alias (__readdir, readdir)
-------------------------------------------

Basically, the implementation just returned NULL>

There is a file under the linux kernel:
linux3.11/fs/readdir.c, which has some functions defined.  The implementation varies according to the versions.

So my first question is, when a user called "readdir", which function is it actually linked to?   How does the linker know not to link against "glibc" and link to some kernel provided library?

Now to the second question, "opendir" doesn't seem to be a linux system call at all.  It is said to be using the "open" system call.
Similar, glibc-2.18/dirent/opendir.c just returned NULL.
So where are the actual source code for processing "opendir"?

Thanks

Yang Li
Senior Software Developer 
Bally Technologies




More information about the Libc-help mailing list