LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Use kernel programs like mount from c++ (https://www.linuxquestions.org/questions/programming-9/use-kernel-programs-like-mount-from-c-642216/)

Meson 05-14-2008 05:05 PM

Use kernel programs like mount from c++
 
Is there a better way to execute commands from c++ than system("CMD")?

For example, rather than calling
Code:

system("mount -t cifs -ouid="+user+" "+share+" "+mountpoint);
Can I just call whatever functions are used by /bin/mount and pass my options as paramters?
Code:

#import <libmount>

mount("cifs", user, share, mountpoint);

Thanks.

nadroj 05-14-2008 05:51 PM

this looks like your answer: http://linux.about.com/od/commands/l/blcmdl2_mount.htm. if you have the source code for mount on your machine, you could always take a look at that.

heby 05-15-2008 08:10 AM

Mount(2)
 
from the manpage of MOUNT(2) (in case you're not familiar with that, you can look at it by typing "man 2 mount"):

SYNOPSIS
#include <sys/mount.h>

int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);

i think this is what you're looking for.


All times are GMT -5. The time now is 05:25 PM.