Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The question and answers are all missing the key "glue" between the C mkdir() function and the Linux syscall - glibc.


I get this, but why is there a declaration of the libc mkdir() function inside of a kernel header?


There isn't - <sys/stat.h> is a glibc header, not a kernel one.


True, to be more precise, the GNU C library has it in the sysdeps/unix/mkdir.c file:

[..] char *cmd = __alloca (80 + strlen (path)); (mkdir command line parsing) status = system (cmd); [..]

That's right, it just relays. I'm not sure how it gets to the kernel. I suspect with a system call somewhere.

What I know is that it arrives in the kernel, in the fs source files: namei.c for the vfs part and <fs-name>/namei.c for filesystem specific implementations (that are called by the vfs code in the end, I guess).

Ps. Feel free to correct me. I only concluded this by poking around the sources a bit, not into kernel development myself.


That's a fallback mechanism, used by glibc on any "unix" system that doesn't have a more specific implementation deeper in the sysdeps/ hierarchy (there's a Linux one that defers to the syscall somewhere in there).


mkdir is fairly mild in that respect though, compared to say fopen or fwrite.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: