question about misc char devices, and relationship with udev

Robert P. J. Day rpjday at crashcourse.ca
Sat Apr 23 09:45:39 EDT 2011


  (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
========================================================================



More information about the Kernelnewbies mailing list