How to identify devices with udev

I would like to use libudev to view specific devices. In particular, I want to monitor removable storage: USB hard drives, USB keys, SD cards, etc. The libudev API allows you to find a device if you know this parent "subsystem" of the device and "devtype". I tried the devices on my computer and used udevadm to find that all types of storages have a device subsystem "block" → "scsi", but I don’t know what devtype is for these devices. Is there a list of devtypes and subsystems that I can use as a reference somewhere, or a better way to search for devtype?

+5
source share
1 answer

You can get a list of subsystems with ls /sys/class/ However, I'm not sure about the types of devices. I think 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 the 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
+5
source

All Articles