2 Linux Device Drivers

Under Linux, there are  three driver categories:  character drivers, block drivers and network drivers.    Drivers are code units that are linked into the kernel, and run in  kernel mode. Generally,  access to  Linux drivers by  user mode applications is provided via the filesystem. In other words, devices appear to the applications as device files. To access to devices from user mode applications, you call I/O functions such as  open, close, read, write, ioctl, etc. Device drivers    are located in the kernel   as  shown below:

figure 5

The /dev/ directory is the Linux raw directory, it contains all device  files. Each of these device  files corresponds to a specific driver 

 [root@peanut /root] cd  /dev ; ls -l  | less    .On my computer, I have the following:

crw-r-----      1 root     sys       14,   7 Oct  4  2001 audioctl
brw-rw----    1 root     disk      29,   0 Oct  4  2001 aztcd
brw-rw----    1 root     disk      41,   0 Oct  4  2001 bpcd
crw-------     1 root     root      68,   0 Oct  4  2001 capi20
  
The 'c' at the beginning  indicate that the file is a char special file.  The 'b' at the beginning  indicate that the file is a block  special file.  The numbers on the fourth  and the fifth columns are the major  and minor numbers respectively. A major number correspond to a specific driver. A minor number represents an instance of a driver. This means you can  have one major number
and many minor number for  a device driver.  
 
2.1 Character Driver

Character devices can be accessed as files, and are implemented by char drivers. These drivers  usually implement the open, close, read, write and ioctl system calls. The console and the serial port are examples of devices that are implemented by char drivers. Applications access char devices through files known as device  files as explained above.  Examples of character device files are /dev/console and /dev/ttyS0.

2.2 Block Drivers:
Block devices are also accessed as device  files, and are implemented by block drivers. Block devices are generally used to represent hardware on which you can implement a file system. Typically, block devices are accessed by multiples of a block of data at a time. Block sizes are typically 512 bytes or 1 Kilobyte (1024 bytes). Block drivers interface with the kernel through a similar interface as a char driver.  

2.3 Network Drivers:

Network interfaces are used to perform network transactions between applications residing on a network.
 User applications perform network transactions through interfaces to the kernel network subsystem (usually exposed as API such as sockets and pipes). Network interfaces send and receive network packets on behalf of user applications, without regard to how each individual transaction maps to actual packets being  transmitted. Network interfaces don't easily fit into the block or char philosophy. Hence, they are not visible as device nodes in the  filesystem. They are represented by system-wide unique logical names such as eth0. Network interfaces are accessed through network API such as sockets,  pipes.

 Previous                       Index                                     Next