Reputation: 11996
I'm trying to find the Linux 3.2.21 x86_64 implementation of the sync(2)
Unix function declared in the unistd.h header. Looking at the Linux unistd.h yields this prototype:
/* Make all changes done to all files actually appear on disk. */
extern void sync (void) __THROW;
So I take that to mean that sync
is defined outside of the Linux kernel and looking inside glibc 2.7, which gives me me this definition in glibc-2.17/misc/sync.c:
/* Make all changes done to all files actually appear on disk. */
void
sync ()
{
__set_errno (ENOSYS);
}
So that means sync
does nothing other than set the value of errno
.
However, when I disassemble /usr/lib/x86_64-linux-gnu/libc.a on system, I find that the sync section makes a system call, passing the value 162
(so it is doing something).
Looking at the Linux source again at arch/x86/include/asm/unistd_64.h, I see:
#define __NR_sync 162
__SYSCALL(__NR_sync, sys_sync)
Now I'm really confused.
If sync(2)
is defined outside of Linux, why is there a system call for it? Where is the definition of sync
for the x86_64 architecture?
P.S.: I did find the preprocessor definition of __SYSCALL
at arch/x86/kernel/syscall_64.c, but this seems to imply that the sync
system call just calls an external function declared as void sys_sync(void)
. Where is the definition for this function?
Upvotes: 3
Views: 2082
Reputation: 182744
You are looking for fs/sync.c
. See:
SYSCALL_DEFINE0(sync)
{
...
The glibc
version you posted is likely what's compiled in the very awkward case where the kernel doesn't expose a sync
syscall. In other words it's a stub that's virtually never used.
Upvotes: 7