Re: Minor Numbers

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

 



> On Thu, 20 Jan 2005 04:55:20 -0800, Can Sar
> <csar@xxxxxxxxxxxx> wrote:
> > Hi,
> > 
> > I wrote my own block device called sbd (using code
> from
> > http://lwn.net/Articles/58719/) and have currently
> only been using one
> > device at /dev/sbd0. I get one major number and 16
> minor numbers. From
> > my understanding the number of minor numbers is
> only important for
> > partitions. 


Minor numbers are NOT used to differentiate or
recognize partitions, as you said. Actually there are
two device numbers, Major and Minor Numbers for each
device file. These numbers are associated with each
device file and they have a place in device file's
inode. Major number is only important to the kernel.
Actually each device driver can handle more than one
device of same type or even of different types
(normally its of same type, for instance you normally
wont find a driver handling HDD, FDD and CD-ROM at the
same time, but its possible to write such drivers). As
you know system have number of devices and kernel have
number of drivers to recognize those devices. When
application request some action on device by using a
reffernce to device file, kernel reads the major
number from the inode of the device file and
identifies the corresponding driver to be invoked for
it. So major number are used by kernel (not device
drivers) to identify which driver it need to invoke to
put the device in action.

Now coming to minor number of device file. once the
driver functions are activated by kernel, its drivers
responsibilty to manupulate the right device. As i
told one driver can handle more that one device, so
driver needs some mechanisum to know which device it
needs to manupulate and that it comes to know by using
minor number. So its two level identification, one is
at kernel level (using major number to identify which
driver needs to be invoked) and another at driver
level (using minor number which tells which physical
devices needs to be manupulated bu driver)


> I also want to have other devices
> like /dev/sbd1,
> > /dev/sbd2, ... be supported will I need another
> major number or is
> there some way around this?

You need not to have a seperate major number allocated
for other device files. You can have one major number
and different minor numbers for these different device
files, as all these devices can be controlled by same
driver.

Note: Major numbers are limited as they are global
thru out the kernel and need to be unique for each
driver in kernel. This is the reason that major
numbers are registered and allocated globally by linux
community guys. You can see the "devices.txt" file in
kernel sources Documentation directory to know the
already allocated major numbers of different drivers.
On other hand minor numbers are local to driver, so u
can use them as per your wish in your driver code.

cheers !!
--gd



		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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