I am looking to programatically mount a USB drive in Linux, so that I can write a text document using fprintf. I am having trouble finding out how to mount the drive. I have been searching the web for an answer, and I found many tutorials of how to do it via the command line, but none in C. Can someone please point me in the right direction with this.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
man 2 mount
e.g.
#include <sys/mount.h>
if (mount("/dev/mmcblk0p1", "/mnt/sd", "vfat", MS_NOATIME, NULL)) {
if (errno == EBUSY) {
printf("Mountpoint busy");
} else {
printf("Mount error: %s", strerror(errno));
}
} else {
printf("Mount successful");
}