简体   繁体   English

使用C在Linux中挂载USB驱动器

[英]Mount USB drive in linux with C

I am looking to programatically mount a USB drive in Linux, so that I can write a text document using fprintf. 我期待以编程方式在Linux中安装USB驱动器,以便我可以使用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中没有。有人请指出我正确的方向。

man 2 mount

eg 例如

#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");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM