如何检测何时使用inotify挂载目录? [英] How could I detect when a directory is mounted with inotify?

查看:123
本文介绍了如何检测何时使用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:

  1. 通过不是"mount"的那些套接字.
  2. 在获取带有"mount"动作.
  3. 使用刚刚安装的设备查找安装点的记录,如果不是正在查看的目录,则将其过滤掉.
  1. Read uevents from kernel via a Netlink socket and filter out those where "ACTION" is not "mount".
  2. Read and parse "/proc/mounts" when you get an event with a "mount" action.
  3. 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挂载目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆