Re: function of major/minor device number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2012/2/12 hz hanks <hankshz@xxxxxxxxx>:
> Hi, all
>
> I have a question about major/minor device number. I know that one can
> use int register_chrdev_region(dev_t from, unsigned count, const char
> *name); to register a driver with a unique pair of major/minor device
> number. But what's the difference between two drivers: in one case
> they have same major device number but different minor device number;
> on another case they have different major device number but same minor
> device number. When I searched the Internet, it said that major device
> number is to identify the driver while the minor device number is to
> identify specific hardware. But I'm still confused because it seems
> legal to share the major device number with different drivers.
>
> Please help me!Thank you!

Hello!

I would redirect you to the /dev fs to do a long listing of its
contents and notice the pattern.
Devices with the same major, are usually handled by the same device
driver. If that device driver needs to handle several devices, it uses
an array of minors.

Example:

crw-rw----   1 root  dialout   4,  64 2011-12-12 16:25 ttyS0
crw-rw----   1 root  dialout   4,  65 2011-12-12 16:25 ttyS1
crw-rw----   1 root  dialout   4,  66 2011-12-12 16:25 ttyS2
crw-rw----   1 root  dialout   4,  67 2011-12-12 16:25 ttyS3

Notice that all the Serial ports have the same major (4) but different
minors (64-67). If you do a "cat /proc/devices" you will notice that
the major 4 is registered by ttyS device driver.  "ttyS" is the name
variable in the register_chrdev_region call.

A device driver can register zero, one ore more majors. And for each
of that major, it can a number of minors (the count parameter in
register_chrdev_region).

Two devices having the same minor but different majors is just a
coincidence, they have nothing in common. It's just an obvious thing
because a major has more minors so there will be more minors  that
majors.

Hope this helps.

-- 
Alexandru Juncu

ROSEdu
http://rosedu.org

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux