How could I detect when a directory is mounted with inotify?

后端 未结 5 1812
栀梦
栀梦 2021-02-06 01:58

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?

5条回答
  •  轮回少年
    2021-02-06 03:03

    EDIT: Update to be less than 5 years obsolete

    If you're on anything but the most ancient of systems, libudev is what you want for the first step.

    If you're on something from this decade, udisks will do all of this for you, too. You'd need to watch the org.Freedesktop.DBus.ObjectManager interface on /org/freedesktop/UDisks2 to see when new filesystems turn up.

提交回复
热议问题