tags:

views:

391

answers:

4

Hello

I'm writing a bash script which fills cf cards with an image. Since only specified cards are allowed, I'd like to check if the right type of cf card is plugged in the USB cf card writer.

I know that it is possible to read out vendor id and firmware version of the cf card somehow (I saw it on an embedded system), but I don't know how to achieve that on my linux box (openSUSE 10.3) and a usb cf card writer.

Does anyone else know how?

Many thanks, Chris

A: 

You can try to do

cat /proc/scsi/scsi

And see if you have meaningfull information. Because CF card have PID / VID does not mean it is exported by the USB card reader.

shodanex
It seems that it is not exported... it shows info on the cf card rw devices but does not change when plugging in a card.
Chris
A: 

Take a look at the output of lsusb or cat /proc/scsi/usb-storage/*

Dennis Williamson
Thanks, but this shows information on the cf card devices only, but no information on the plugged in cf cards...
Chris
+1  A: 
hdparm -i /dev/sda

can tell you about the model, firmware revision and serial number of most ATA disks (including, I presume a CF "disk").

smartctl -a /dev/sda

will also tell you a lot about a random disk, including the model, serial, firmware, capacity, as well as some statistics as to the general health of a disk.

I believe this will work well for a CF disk, as it does for a SATA or PATA disk, although I don't have one here to check with right now.

Perry Lorier
Thanks for your suggestion. I tried the commands (plus sdparm) with 3 different card readers, but none of them works... It seems that card readers do not export this info. The commands work with my fixed hdd, though.
Chris
+1  A: 

Apart from using lsusb, you can try dbus.

Here is a sample python code that should list all scsi_host parents in the hardware hierarchy.

import dbus
bus = dbus.SystemBus()
hal = bus.get_object ('org.freedesktop.Hal',
            u'/org/freedesktop/Hal/Manager')
hal_manager = dbus.Interface(hal, u'org.freedesktop.Hal.Manager')
volume_udi_list = hal_manager.FindDeviceByCapability('scsi_host')
for udi in volume_udi_list:
    # inspect all scsi_host devices
    dev = bus.get_object ( u'org.freedesktop.Hal', udi)
    volume = dbus.Interface(dev, u'org.freedesktop.Hal.Device')
    # get their parent
    parent = volume.GetProperty('info.parent')
    dev = bus.get_object ( u'org.freedesktop.Hal', parent)
    volume = dbus.Interface(dev, u'org.freedesktop.Hal.Device')
    # Here we can find vendor id for usb-storage devices
    props = volume.GetAllProperties()
    print "\n".join(("%s: %s" % (k, props[k]) for k in props))
baol
Please note that only the card reader is assigned an usb vendor-id, the CF itself is not. If you don't see it using lsbus it means it's not attached to the USB bus. Anyway using dbus you can explore the tree structure to see what kind of information is available.
baol