LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   How to poll for USB devices available to mount (with auto-mounting disabled)? (https://www.linuxquestions.org/questions/linux-hardware-18/how-to-poll-for-usb-devices-available-to-mount-with-auto-mounting-disabled-700758/)

tl3462 01-29-2009 05:15 AM

How to poll for USB devices available to mount (with auto-mounting disabled)?
 
I don't want any old USB thumb drive mounting to my system therefore I'm trying to create a script that controls the mounting of USB devices and the permissions given to them. These permissions depend on other variables (eg. am I connected to a network?) therefore I don't think I can just add a device to a list of approved devices for mounting and block everything else. I need some dynamic way of doing it.

I've disabled the auto-mounting of removable/hot-pluggable drives, I now need some way of polling for the insertion of a USB device. Any ideas what I need to poll?

Tom

jschiwal 01-29-2009 05:26 AM

Whether a local user or remote user can mount a usb drive is usually handled by PolicyKit.

Since you disabled automounting, you might consider manually mounting usb drives instead with entries in /etc/fstab determining the permissions and ownership. The first field in /etc/fstab can use UUID=<filesystem_uid> instead of the device node. This is recommended anyway for removable drives because you can't depend on which device node it will be assigned to.

Also, for removable drives, be sure to use the "noauto" option.

For fat32 filesystems, which is the most common for pendrives, you determine the permissions and ownership in the mount command. So you can have an /etc/fstab entry for each pendrive you own and use different permissions or ownership. Using the "user" or "users" option, you can even mount the pendrive as a normal user. The permissions you use could mean that only you have permission to enter the mounted directory.

tl3462 01-29-2009 05:41 AM

I'd really like to be able to run the polling and mounting automatically using a daemon. I think that fdisk -l will give me a list of all devices connected (but not necessarily mounted) so I could run that every few seconds from a script to check if anything has been inserted into a USB socket, but this seems a bit clumsy.

I suppose I could dig through the source for fdisk and find out what it uses but I thought there might perhaps be an easier way?

jschiwal 01-29-2009 06:33 AM

If you don't want to use HAL, look at "ivman".

Didier Spaier 01-29-2009 07:19 AM

Poll for output of 'lsusb' or the file /proc/bus/usb/devices

tl3462 01-29-2009 08:49 AM

Brilliant, ivman looks to be exactly what I was after.

I tried working with HAL - I found a python script that supposedly interacts with HAL 0.4 at http://people.redhat.com/davidz/hal-...c.html#AEN2152 but I have 0.5 I think so this wasn't giving me any joy.

ivman seems to be controlled by a configuration file so this might possibly be the answer but I haven't dug around for any documentation yet

... if not lsusb will do as my clumsy backup option!

Thank you both!


All times are GMT -5. The time now is 02:21 AM.