本文介绍了如何检测何时使用inotify挂载目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Linux Inotify来检测程序中的FS事件.
I'm using Linux Inotify to detect FS events on my program.
当设备安装在受监视的目录上时,如何通知我?
How could I be notified when a device is mounted on a monitored directory?
推荐答案
我认为您不能使用inotify
做到这一点.不过这是方法:
I don't think you can do it with inotify
. Here is the method though:
- 通过 Netlink 套接字,并过滤掉
"ACTION"
不是"mount"
的那些套接字. - 在获取带有
"mount"
动作. - 使用刚刚安装的设备查找安装点的记录,如果不是正在查看的目录,则将其过滤掉.
- Read uevents from kernel via a Netlink socket and filter out those where
"ACTION"
is not"mount"
. - Read and parse
"/proc/mounts"
when you get an event with a"mount"
action. - Find a record for a mount point with device that was just mounted and filter it out if it's not the directory you are watching.
这篇关于如何检测何时使用inotify挂载目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!