I'd like to use libudev to watch for certain devices. Specifically, I want to monitor for removable storage: USB Hard Drives, USB Keys, SD cards, etc. The libudev API lets you find a device if you know that device's parent's 'subsystem' and 'devtype'. I tried the devices out on my computer and used udevadm to find that all the storage types had device subsystem of 'block'->'scsi', but I have no idea what devtype these devices have. Is there a list of devtypes and subsystems I can use as a reference somewhere, or a better method to look up devtype?
Asked
Active
Viewed 8,450 times
1 Answers
5
You can get list of subsystems with ls /sys/class/
I'm not sure about device types though. I guess you can get this using:
ls -l /sys/class/scsi_disk/
total 0
lrwxrwxrwx 1 root root 0 2011-12-07 21:20 0:0:0:0 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0
cat /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0/device/vendor
ATA
cat /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0/device/model
ST9500325AS
You can try other files in device directory.
Actually I think you need:
cat /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/scsi_disk/0:0:0:0/device/type
0
cat /usr/include/scsi/scsi.h | grep TYPE_
#define TYPE_DISK 0x00
#define TYPE_TAPE 0x01
#define TYPE_PROCESSOR 0x03 /* HP scanners use this */
#define TYPE_WORM 0x04 /* Treated as ROM by our system */
#define TYPE_ROM 0x05
#define TYPE_SCANNER 0x06
#define TYPE_MOD 0x07 /* Magneto-optical disk -
#define TYPE_MEDIUM_CHANGER 0x08
#define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
#define TYPE_NO_LUN 0x7f
![](../../users/profiles/1084392.webp)
ILYA Khlopotov
- 687
- 3
- 5
-
Is there no global reference out there? The info you gave is really helpful but its for scsi only. My card reader is type block->mmc ... etc. I found this link, but was hoping there was something more universal: http://wiki.xfce.org/dev/thunar-volman-udev – Prismatic Dec 08 '11 at 17:40
-
As far as I know there is no consistent naming. Every subsystem is handled differently. However there are some helper programs in /lib/udev/ that you might want to look at. – ILYA Khlopotov Dec 08 '11 at 17:59