How to reliably control mount / umount drives on linux?

I found several similar questions, but none of them work now.

Monitoring (inotify) /etc/mtab does not work, because now it symbolizes /proc/mounts . Monitoring through udisks does not allow you to manually connect / mount drives. Netlink sockets also do not work (no mount / umount actions).

So what really works for monitoring mounts and umounts?

PS I don't care about mounted names, just global ones.

+4
source share
2 answers

I believe udev can probably be used to monitor mounts.

+3
source

You can control / proc / mounts without polling. Put it on the exceptfds list to select, and then start searching for the file each time. Here is a quick demo in python, but it should be easily translatable in C:

 f = open("/proc/mounts") while True: r,w,x = select.select([],[],[f]) f.seek(0) print f.read() 
+2
source

Source: https://habr.com/ru/post/1389899/


All Articles