Therealstubot
Therealstubot

Reputation: 757

Linux USB Mapping Question

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.

Upvotes: 2

Views: 2169

Answers (3)

liori
liori

Reputation: 42367

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: How can I listen for 'usb device inserted' events in Linux, in Python?

Upvotes: 2

dusoft
dusoft

Reputation: 11469

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

Upvotes: 0

Richie
Richie

Reputation: 535

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()

Upvotes: 0

Related Questions