world leader in high performance signal processing
Trace: » device_classes

Device Classes

Devices come in three “flavors”: Character, Block and Network.

  • Character:
  • Serial Access
  • (Normally) Single word (byte) at a time
  • Completes as it is called
  • Block:
  • Random Access
  • Multiple words (bytes) at a time
  • Uses Buffer Cache
  • Delayed actual completion
  • Network:
  • Interrupt Push
  • Different “device” structure
  • Manipulation Tools

Character and Block devices are accessed by device nodes. These are created using the mknod command (more later) and , by convention, are placed in a special /dev directory. They can exist anywhere and do not need the device driver

NOTE These are not real files but special files that allow user tasks to communicate with the kernel based driver. The key elements in these files are:

  • Device class (block or char)
  • Major Number
  • Minor Number

This is an example of some possible entries in this directory.

b = block
c = char           owner  grp    maj,min   date             name
brw-rw----     1   root   disk    3,0      May   5   1998   hda  
brw-rw----     1   root   disk    3,1      May   5   1998   hda1 
brw-rw----     1   root   disk    3,10     May   5   1998   hda10
brw-rw----     1   root   disk    3,64     May   5   1998   hdb  
brw-rw----     1   root   disk    3,65     May   5   1998   hdb1 
crw-rw-r       1   root   root    10,1     May   5   17:14  psaux
crw-rw-rw-     1   root   root    5,0      May   5   1998   tty  
crw-------     1   root   root    4,0      May   5   1998   tty0 
crw-------     1   root   tty     4,1      Feb   23  20:06  tty1 
crw-rw----     1   root   uucp    19,0     Apr   17  1999   ttyC0

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


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.

Complete Table of Contents/Topics