world leader in high performance signal processing
Trace:

Differences

This shows you the differences between two versions of the page.

device_classes [2005/08/12 21:21]
philwil created
device_classes [2006/12/08 01:02] (current)
Line 54: Line 54:
                                                                                                                                        
                                                                                                                                        
 +
 +
 +====Major Numbers====
 +
 +To look at the drivers installed on your system use the command:
 +
 +                   
 +                   
 +  cat /proc/devices
 +                   
 +
 +You should get an output of a number followed by a name like this:
 +
 +                              
 +                              
 +  (Major Number/ Device Name )
 +                              
 +  Character devices:          
 +    1 mem                     
 +    2 pty                     
 +    3 ttyp                    
 +    4 ttyS                    
 +    5 cua                     
 +    7 vcs                     
 +   10 misc                    
 +   14 sound                   
 +  128 ptm                     
 +  136 pts                     
 +  254 pcmcia                  
 +                              
 +  Block devices:              
 +    1 ramdisk                 
 +    2 fd                      
 +    3 ide0                    
 +   22 ide1                    
 +                              
 +                              
 +
 +The same major number can be used by both a char and a block driver.
 +
 +The major number provides the main link between the device, the kernel driver,
 +and the user software. The user opens a device represented by a device node
 +file (created by mknod). This special file was given a class (b-block or c-
 +char) and a major number when it was created.
 +
 +The major number refers to a device driver that was registered within the
 +kernel as servicing that particular class of device.
 +
 +Looking at
 +
 +   /proc/devices
 +
 +you can see all the currently registered major numbers for both char and block
 +devices.
 +
 +
 +=====Minor Numbers=====
 +
 +The minor number is also specified by the special file (created by mknod). The
 +main driver is referenced by the major number, but the minor number can be used
 +to pick a particular instance of the device controlled by the driver.
 +
 +A serial driver may control several serial ports; in this the minor number may
 +direct the driver to a particular port.
 +
 +In some cases the minor number can refer to a completely different set of read/
 +write operations.
 +
 +
 +                                                                    
 +                                                                    
 +  [root@train /root]# ls -l /dev/random                             
 +  crw-r--r--   1 root     root       1,   8 May  5  1998 /dev/random
 +  [root@train /root]# ls -l /dev/zero                               
 +  crw-rw-rw-   1 root     root       1,   5 May  5  1998 /dev/zero  
 +                                                                    
 +
 +The random and zero devices both have the same major number, but the different
 +minor numbers result in different responses to read/write operations.
 +
 +
 +                                                                   
 +                                                                   
 +                                                                   
 +  [root@train /root]# ls -l /dev/ttyS*                             
 +  crw-------   1 root     tty        4,  64 May 28 13:08 /dev/ttyS0
 +  crw-rw-rw-   1 root     tty        4,  65 Jun  7 23:08 /dev/ttyS1
 +  crw-------   1 root     tty        4,  66 Apr 28 09:47 /dev/ttyS2
 +  crw-------   1 root     tty        4,  67 May  5  1998 /dev/ttyS3
 +                                                                   
 +                                                                   
 +                                                                   
 +
 +The serial driver uses the same software for each serial port. The minor number
 +is used to change the actual physical address of the device being referenced.
 +
 +
 +====Major number allocation====
 +
 +The main document used to determine the pre allocated device major numbers is
 +
 +  * linux-2.6.x/Documentation/devices.txt
 +
 +
 +There is a move in more recent system to move away from a fixed allocation
 +scheme and use dynamic device allocation for newer systems. This has some
 +drawbacks for embedded systems since extra code is needed, as the device driver
 +is set up, to determine the correct major numbers for a dynamically allocated
 +driver.
 +
 +The **devfs** system was used in embedded systems to provide a means of automatically creating the
 +entries in the **/dev** directory as each device was registered.
 +
 +This approach is being deprecated in the 2.6 kernels in favor of the kernel object filesystem **sysfs**.