How could I detect when a directory is mounted with inotify?
c, inotify, kernel, linux
Solution
I don't think you can do it with `inotify`. Here is the method though:
- 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.
Problem
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?