Skip to contentSkip to conversation

Creating dev nodes from driver or via uevent?

DISCUSSION Fabiano Sidler 3 participants 3 messages Oct 15, 2008

lore
Share & tools
lore
#0 lore raw

Hi folks!

Probably a very basic question, but is it better to directly mknod from a module's init funtion or to use the uevent/udev mechanism? If the latter, are there good overviews, explanations and comprehensive code samples especially for using udev, as well as how to package the userspace program creating the nodes along with a driver?

Thank you for answering!
Greetings,
Fabiano

#1 lore raw
Quoted 6 lines · Fabiano Sidler

Hi folks!

Probably a very basic question, but is it better to directly mknod from a module's init funtion or to use the uevent/udev mechanism? If the latter, are there good overviews, explanations and comprehensive code samples especially for using udev,

You can refer to any in-tree driver that calls class_create() and device_create_drvdata() afterwards. say drivers/char/raw.c

LDD3 by Greg has some descriptions on this, but since the interface has changed..

Signature · 2 lines
Thanks,
Jike
#2 lore raw
In reply to Fabiano Sidler
Quoted 2 lines · Fabiano Sidler

Probably a very basic question, but is it better to directly mknod from a module's init funtion or to use the uevent/udev mechanism?

You better do not touch any userspace managed filesystem from inside the kernel. No driver is doing that.

Quoted 4 lines

If the latter,
are there good overviews, explanations and comprehensive code samples especially for using udev, as well as how to package the userspace program creating the nodes along with a driver?

You do not package anything along with the driver, unless you have _very_ special requirements for userspace device setup. Then you could ship a udev rules file.

There is nothing special to do, just run udev, and register a "struct device" inside the kernel's driver core, and you will see a device node in /dev/ with the name of your kernel device, and the major/minor you assigned to the struct device before registration.

Almost every Linux distro, and every driver in the kernel works that way. I suggest looking at the current kernel code and running a Linux distro and loading/unloading an existing module, to see it working.

You can also run "/sbin/udevadm monitor --env --kernel" to see the "raw" kernel events "struct device" registration causes, and which lets userspace create the device nodes.

Kay