Mount USB drive in linux with C

2020-06-06 05:34发布

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.

标签: c linux usb
1条回答
对你真心纯属浪费
2楼-- · 2020-06-06 05:55
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");
}
查看更多
登录 后发表回答