问题描述
我搜索了类似的帖子,但没有找到。我正在寻找一些建议或正确方向的观点,因为我找不到关于此主题的太多信息。
我正在尝试在从 buildroot 运行自定义 linux 构建的 raspBerry pi 4 上编写守护进程。守护进程使用 udev (libudev.h) 和 epoll (sys/epoll.h),检测新插入的笔式驱动器,创建目录并安装设备。它还检测所述设备的移除,卸载然后移除目录。
它运行良好,直到移除笔式驱动器,尽管正在执行卸载(没有任何错误返回),但当我重新插入笔式驱动器时,我总是收到此消息“FAT-fs(sda1)卷不是正确卸载。某些数据可能已损坏。请运行 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");
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)