Stefan Steiger Stefan Steiger - 3 years ago 332
C Question

C / C++ / C#: Howto do "mount -a"

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...

Answer Source

getmntent can help you read /etc/fstab (and then use the mount function in the other answers).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download