The "mount" function versus the "mount" command
In the "mount" function (http://man7.org/linux/man-pages/man2/mount.2.html), as I understand it, the programmer is required to pass a non-empty C-string for the filesystem type as the third parameter. Yet in the "mount" command (http://man7.org/linux/man-pages/man8/mount.8.html) it is optional whether or not the '-t fstype' is passed to the command.
Why design a function call which requires the programmer to figure out the filesystem type, whereas the equivalent command does not require it ? I used libblkid to pick up the filesystem type to pass to the "mount" function successfully in my code, but I do not understand why the "mount" function could not have been designed so that when a null pointer is passed as the 3rd parameter it acts like the "mount" command and figures out the filesystem type to use itself. |
Well, mount(8) program does more than just calling mount(2) system-call, for example:
Quote:
|
Quote:
|
As NevemTeve said, they are designed for different uses:
Quote:
An even better question might be, "Why should one expect the mount() library function to work like the mount program?". They are different animals, produced by different people at different times for different reasons. Only the name is the same. Why do you expect them to work the same? If the developers of the mount program had chosen a different name, fsmnt for example, would you have asked, "Why does fsmnt handle args differently than mount()"? |
Well, it is common that a system-call does simpler things than a utility-program. I think OP wishes for a 'libmount' component. Which does exist.
|
Quote:
|
Quote:
|
Quote:
There is no [inherent] reason to make a function call identical to a command. Isn't there? |
Also there might be a reason why I keep repeating the term system call
https://en.wikipedia.org/wiki/System_call |
Quote:
In this case, that is the job of the application. It can make any type of decisions it wants to decide what to do. Burying that in the system call would make it very difficult to change the policy. That was one of the reasons for the /etc/filesystems file - it specifies how the application is to respond. If missing then the application looks elsewhere. |
Quote:
Kernel introduces another aspect. ‘mount’ system call does not detect file system because that can be done in user space. Generally anything that can be done in user space without big impact on performance should be as it makes the overall system more secure. |
If you want something that works just like the mount command, and you don't care how long it takes, then just call the mount command.
Code:
system("mount foo /baz"); |
Quote:
The problem is that it depends on three things... the environment PATH to find the mount command, the shell the system uses, and the mount command itself. Any of which can redirect to some unexpected program. System (along with popen) are considered bad for these reasons. |
All times are GMT -5. The time now is 05:45 AM. |