3 ms·
The question and answers are all missing the key "glue" between the C mkdir() function and the Linux syscall - glibc.
by drv 16y ago
The question and answers are all missing the key "glue" between the C mkdir() function and the Linux syscall - glibc.
- jacquesm 16y agomkdir is fairly mild in that respect though, compared to say fopen or fwrite.
- meastham 16y agoI get this, but why is there a declaration of the libc mkdir() function inside of a kernel header?
- caf 16y agoThere isn't - <sys/stat.h> is a glibc header, not a kernel one.
- Seth_Kriticos 16y agoTrue, 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.
- caf 16y agoThat'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).