Question:
In C/C++/C#. (I need it for C#, but C and C++ is also fine).
How can I do a mount -a on Linux. I mean programmatically, without starting a process like
system("mount -a");
Edit:
Note the "-a".
My question is not actually about how to mount A mountpoint.
It's about how to mount ALL mountpoints in /etc/fstab.
That means parsing the file, extracting the mountpoints, check if already mounted, and only if not already mounted, mount...
getmntent
can help you read/etc/fstab
(and then use the mount function in the other answers).Check out the man page by typing
man 2 mount
. It talks about a system call that can avoid the actual use of system():@Ignacio Vazquez-Abrams: About your "no way to perform this in C#" ...
Proof that you're wrong by contradiction:
The bellow code is capable of doing the same as
Code:
To perma-mount it in fstab, you need to get the partition uuid (blkid)