'Where does mount API implemented in Linux source code?

I am newbie for Linux kernel, I cloned the Linux source from its repo on GitHub. I cannot find the file sys/mount.h nor the mount function.

Do you know where is this file located in source code? Where can I find its implementation?



Solution 1:[1]

If you don't know where a system call is implemented in the kernel, there's a general sequence of steps you can use to find it. You will need to download the kernel source to your machine.

Begin by finding the number of parameters the syscall requires. eg. mount(2) requires five parameters.

Since mount(2) requires 5 parameters, search for SYSCALL_DEFINE5(mount in the kernel source:

grep -nr 'SYSCALL_DEFINE5(mount'

This will take a while to run, but it will eventually find:

./fs/compat.c:92:COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
./fs/namespace.c:3026:SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,

So, the syscall you're looking for is located at in ./fs/namespace.c on line 3026. (I'm using Linux 4.19.99, so the line number will probably be different on your kernel.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sagar