【发布时间】:2021-01-27 17:06:21
【问题描述】:
我搜索了类似的帖子,但没有找到。我正在寻找一些建议或正确方向的观点,因为我找不到关于这个主题的太多信息。
我正在尝试在运行来自 buildroot 的自定义 linux 构建的树莓派 4 上编写一个守护进程。守护进程使用 udev (libudev.h) 和 epoll (sys/epoll.h) 检测新插入的笔式驱动器,创建目录并安装设备。它还检测所述设备的删除,卸载然后删除目录。
在移除笔式驱动器之前,它运行良好,尽管卸载正在执行(没有任何错误返回),但当我重新插入笔式驱动器时,我总是收到此消息“FAT-fs (sda1) Volume was not正确卸载。某些数据可能已损坏。请运行 fsck"。 我究竟做错了什么?如何正确卸载它?
//pen removed
if(!action.compare("remove") && !partition.compare("partition")){
//if directory exists
dir = opendir(path.c_str());
if(dir){
//close directory to be able to unmount
close(dir);
//unmount
status = umount(path.c_str());
if(status != 0)
syslog(LOG_ERR, "%m\n");
//remove the directory
status = rmdir(path.c_str());
if(status != 0)
syslog(LOG_ERR, "%m\n");
}
}
//pen inserted
else if(!action.compare("add") && !partition.compare("partition")){
//if directory doesn't exist
dir = opendir(path.c_str());
if(!dir){
//create the directory
status = mkdir(path.c_str(), 777);
if(status != 0)
syslog(LOG_ERR, "%m\n");
}
//mount
status = mount(devicenode.c_str(), path.c_str(), "vfat", MS_NOATIME, NULL);
if(status != 0)
syslog(LOG_ERR, "%m\n");
}
}
【问题讨论】:
标签: linux daemon buildroot raspberry-pi4