Hi. I'm writing a python module for a device that interacts with a user supplied USB memory stick. The user can insert a USB memory stick in the device USB slot, and the device will dump data onto the memory stick without user intervention. If the device is running when the user inserts the USB stick, I have hooked into D-Bus and have an auto mount routine all worked out. The new issue is, what if the stick is inserted while the device is powered off? I get no D-Bus insertion event, or any the associated nuggets of information about the memory stick after the device is powered on.
I have worked out a way to derive the device node ( /dev/sd? ) from scanning the USB devices in /proc, by calling:
ls /proc/scsi/usb-storage
this gives the scsi device info if you cat each of the files in that folder.
I then take the Vendor, Product, and Serial Number fields from the usb-storage records, generate an identifier string that I then use in
ll /dev/disc/by-id/usb_[vendor]
_[product]
_[serial_number]-0:0
So I can parse through the result to get the relative path
../../sdc
Then, I can mount the USB stick.
This is a cumbersome procedure, pretty much all text based, and ready for bugs when someone introduces a weird character, or non-standard serial number string. It works with all 2 of the USB memory sticks I own. I have tried to map output from /var/log/messages but that ends up being text comparisons as well. Output from lsusb, fdisk, udevinfo, lsmod, and others only show half of the required data.
My question: how do I determine, in the absence of a D-Bus message, the /dev device assigned to a USB memory stick without user intervention, or knowing in advance the specifics of the inserted device?
Thanks, sorry about the novel.