Node devices are either created manually (by directly invoking mknod
) or by udevd
daemon upon receiving an uevent
message. The message consists of "action" field (ADD
, REMOVE
, etc.) and a set of key/value pairs which udevd
can peek at to decide which rule to invoke.
To emit the event you will need to get a handle on kobject ((struct cdev *)->kobj
). After your device is fully created you need to do something like this:
err = cdev_add (dev, devno, 1);
/* Fail gracefully if need be */
if (err)
printk (KERN_NOTICE "Error %d adding simple%d", err, minor);
kobject_uevent(&dev->kobj, KOBJ_ADD);
Prior to the removal of device, you need to do the opposite:
kobject_uevent(&SimpleDevs[0]->kobj, KOBJ_REMOVE);
printk("Releasing Simple Devs\r\n");
cdev_del(SimpleDevs[0]);
(by the way, your code has a major pointer handling bug involving your definition and usage of SimpleDevs
variable, which you should sort out and fix).
At this point you can use udevadm monitor
command to experiment and see if you are getting the messages from your driver and use any udev tutorial to write an appropriate rule (such as this one: https://wiki.debian.org/udev).
If you feel like adding more information to your uevent messages, you can try the more verbose kobject_uevent_env()
API. This usually looks somewhat like this:
char event[] = "DISK_RO=1";
char *envp[] = { event, NULL };
if (!ro)
event[8] = '0';
kobject_uevent_env(&disk_to_dev(gd)->kobj, KOBJ_CHANGE, envp);
http://code.metager.de/source/xref/linux/stable/block/genhd.c#1320
If you want fancier messages the usual approach is to reserve a fixed chunk of memory of appropriate size and fill it in with snprintf
prior to passing it down to uevent.