4

What I think happens

From my understanding this is what happens when I connect a USB device to my computer:

  1. Kernel recognizes that I plugged in a USB device
  2. Kernel setups the very low-level things for the new device like drivers etc.
  3. Kernel sends a uevent to the udev daemon.
  4. Udev daemon uses the information sent, to populate the appropriate files in /dev.

What I want to do

I was thinking that maybe I could jump directly to step 3 by manually sending a uevent to udev. Since the uevent is sent via netlink and netlink is based on sockets, theoretically this should be possible since I just need to know which socket to write to. Anyone who has any idea if this can work and how?

  • 1
    udevadm trigger may do what you want. An example from wiki.archlinux.org/index.php/udev : udevadm trigger -v -t subsystems -c remove -s usb -a "idVendor=abcd" . – Mark Plotnick Jan 23 '15 at 15:04
  • @MarkPlotnick thanks for the link. However I am not sure to use that. I tried the command given and run udevadm monitor but nothing seems to happen.. – Pithikos Jan 23 '15 at 16:38
  • Why do you want to skip step 2? – Nils Jan 24 '15 at 21:42
  • @Nils because I create a virtual device. What I want is udev to think that it's an actual device. – Pithikos Jan 25 '15 at 10:39
  • So blacklisting the driver will not help you here. – Nils Jan 25 '15 at 21:53
2

udevadm trigger

1. try it

sudo udevadm trigger --verbose --action=remove --property-match='DEVNAME=/dev/sdd'

will trigger a /dev/sdd remove uevent, content as

remove@/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/host13/target13:0:0/13:0:0:0/block/sdd
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/host13/target13:0:0/13:0:0:0/block/sdd
SUBSYSTEM=block
MAJOR=8
MINOR=48
DEVNAME=sdd
DEVTYPE=disk
SEQNUM=12589

2. strace it

see what he dose:

sudo strace udevadm trigger --verbose --action=remove --property-match='DEVNAME=/dev/sdd'
...
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 37), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0596a7000
write(1, "/sys/devices/pci0000:00/0000:00:"..., 101/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/host13/target13:0:0/13:0:0:0/block/sdd
) = 101
open("/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.2/1-1.2:1.0/host13/target13:0:0/13:0:0:0/block/sdd/uevent", O_WRONLY) = 3
write(3, "remove", 6)                   = 6
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

3. summarize

actually, it only does

echo 'remove' | sudo tee /sys/block/sdd/uevent

this way still depend on sysfs:

  • device sysfs must exist
  • can't totally custom uevent message body

the sysfs uevent file:

cat /sys/block/sdd/uevent
MAJOR=8
MINOR=48
DEVNAME=sdd
DEVTYPE=disk

refs:
http://fibrevillage.com/sysadmin/93-udevadm-useage-examples http://arakilab.media.eng.hokudai.ac.jp/~msylw/2013/07/using-udev-to-trigger-events-in-example/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.