Skip to main content
6 of 6
Add tag system-calls, show kernel version to users.

How can I find the implementations of Linux kernel system calls?

I am trying to understand how a function, say mkdir, works by looking at the kernel source. This is an attempt to understand the kernel internals and navigate between various functions. I know mkdir is defined in sys/stat.h. I found the prototype:

/* Create a new directory named PATH, with permission bits MODE.  */
extern int mkdir (__const char *__path, __mode_t __mode)
     __THROW __nonnull ((1));

Now I need to see in which C file this function is implemented. From the source directory, I tried

ack "int mkdir"

which displayed

security/inode.c
103:static int mkdir(struct inode *dir, struct dentry *dentry, int mode)

tools/perf/util/util.c
4:int mkdir_p(char *path, mode_t mode)

tools/perf/util/util.h
259:int mkdir_p(char *path, mode_t mode);

But none of them matches the definition in sys/stat.h.

Questions

  1. Which file has the mkdir implementation?
  2. With a function definition like the above, how can I find out which file has the implementation? Is there any pattern which the kernel follows in defining and implementing methods?

NOTE: I am using kernel 2.6.36-rc1.

Navaneeth K N
  • 4k
  • 3
  • 19
  • 13