views:

368

answers:

3

Hi,

I'm working on a utility that will auto mount an inserted USB stick on linux. I have tied into D-Bus to receive notification of when a device is inserted, and that works great. However, I need to determine which device in /dev is mapped to the inserted USB stick. I am getting the D-Bus notification and then scanning the USB system with pyUSB ( 0.4 ). I filter for USB_MASS_STORAGE_DEVICE classes, and I can see the device that's been added or removed. I need to mount this device so I can query it for available space and report that to our app so we can determine if enough free space exists so we can write our data.

I'm using python for this task. I'm not sure what our target distro will be, only that it will be at least 2.6

edit: My question is: How do I determine which device in /dev maps to the buss-device number I get from pyUSB.

A: 

Why not use "os" module to mount the file system:

os.system ("mount ... ")

Or if you want to examine output use "popen":

l = op.popen ("mount ....").readlines()
Richie
I will, once I know what to mount. i.e. the first argument of mount is the device. That's what I'm trying to find out.
Therealstubot
A: 

what about using dmesg output to find out the device name (sdc1 etc...)

use it right after dbus tells you something is was inserted in USB. you could do tail dmesg for example

dusoft
I didn't like this solution because it lacks "atomicity". This would work as a last resort, although it would never make me happy.
Therealstubot
it's not really different than listening some other way. this is also listening, just checking for strings.
dusoft
+1  A: 

You should probably ask HAL about that. You say you already get notifications from HAL by D-Bus... It maintains list of USB devices, together with their IDs and device names (block.device property).

Here's a nice example of how to get device file name together with the notification of new USB device: http://stackoverflow.com/questions/469243/how-can-i-listen-for-usb-device-inserted-events-in-linux-in-python

liori
Perfect. Exactly what I was looking for. Thanks.
Therealstubot