question about misc char devices, and relationship with udev
(probably a question with a very simple answer, i just don't know what it is.) i'm currently trying to document the use of the "misc" char driver to quickly and conveniently create a character driver. there's a decent explanation of misc drivers in the book "essential linux device drivers", as well as a nice example here: http://virtlog.com/2008/03/25/linux-miscdevice-sample/ but here's where i get confused. what a misc char driver does is combine a lot of what you'd normally do in creating a regular char driver in a single call. on page 160 of ELDD, it's explained that a single call to misc_register() does all of the following that you would normally have to do yourself for a regular char driver: * allocates major/minor number via alloc_chrdev_region() * creates /dev and /sys nodes via call to class_device_create() * registers itself as a char driver using cdev_init() and cdev_add() sure enough, i compiled that sample misc char driver (called "mymisc"), loaded it and got an entry for that module both under /sys and under /dev, where i now have the device file: crw------- 1 root root 10, 56 2011-04-23 08:18 /dev/mymisc but here's the confusing part. who or what created that /dev entry? i always thought that was the job of udev, but i never added any udev rule for this new driver. so how did that new /dev file come to be? is there some sort of generic udev rule that would have handled this? also, the ELDD book claims that misc_register() calls the kernel routine class_device_create(). i'm looking at the entire kernel implementation for misc drivers in drivers/char/misc.c, and what i see is a call to device_create() instead. i suspect i should start following the flow of control here, but i'm still curious as to how that /dev file came into existence without any obvious help from udev. rday -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ========================================================================
On Sat, Apr 23, 2011 at 09:45:39AM -0400, Robert P. J. Day wrote:
but here's the confusing part. who or what created that /dev entry? i always thought that was the job of udev, but i never added any udev rule for this new driver. so how did that new /dev file come to be? is there some sort of generic udev rule that would have handled this?
Yes there is, udev took the default kernel name and created the device node for it. The misc device is exported in sysfs automatically by the misc core code, as you pointed out with the call to device_create(). And, in newer versions of your distro, devtmpfs created the device node, udev just set the permissions on it. Hope this helps, greg k-h
also, the ELDD book claims that misc_register() calls the kernel routine class_device_create(). i'm looking at the entire kernel implementation for misc drivers in drivers/char/misc.c, and what i see is a call to device_create() instead. i suspect i should start following the flow of control here, but i'm still curious as to how that /dev file came into existence without any obvious help from udev.
In linux 2.6.20,kernel still use class_device_create(). After linux 2.6.22(maybe,I can't remember),kernel use device_create() instead of class_device_create().
participants (3)
-
Greg KH -
onlyfever -
Robert P. J. Day