how to see the minor numbers allocated to a driver?

Robert P. J. Day rpjday at crashcourse.ca
Wed May 4 09:40:52 EDT 2011


  something i was curious about way back when -- given that
register_chrdev_region() and alloc_chrdev_region() allow one to
specify a range of minor numbers desired that doesn't necessarily have
to start at zero, is there a way from user space to see what those
numbers are after the device registration is complete?

  obviously, looking at /proc/devices will always give you the major
number, that part's easy.  and if you look at fs/char_dev.c, it's the
chrdev_show() routine that prints each major number and its registered
name:

===

void chrdev_show(struct seq_file *f, off_t offset)
{
        struct char_device_struct *cd;

        if (offset < CHRDEV_MAJOR_HASH_SIZE) {
                mutex_lock(&chrdevs_lock);
                for (cd = chrdevs[offset]; cd; cd = cd->next)
                        seq_printf(f, "%3d %s\n", cd->major, cd->name);
                mutex_unlock(&chrdevs_lock);
        }
}

===

  if it's a "misc" driver, then you already know that it's major
number is 10, and the contents of /proc/misc will give you the single
minor number allocated for it.  but if, for some (bizarre) reason, you
don't know what minor numbers the driver will try to allocate, is
there a way to tell what they are after the fact?  or is this just a
silly question?

rday

p.s.  for fun, a while back, i extended the chrdev_show() routine to
append to each line the range of minor numbers that had been
allocated, so that each line would read:

####  name    [a-b]

i didn't have a compelling reason for that, i was just curious.  and
it occurred to me that if userspace programs parse that file for the
first two fields, then having extra info at the end of each line might
not be that disruptive, especially if adding it was a kernel config
option.  or maybe i'm making too much of this.

-- 

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