[EdCert previous] [EdCert next] [EdCert top]

Introduction to device drivers and device nodes

This section provides an overview of the way in which peripheral components use the Unix Input/Output (I/O) subsystem.

Physical devices, such as disk drives and modems, have a varied command interface and command interpretation. For this reason the Unix operating system defines a standard method of I/O that is used on any type of device that is attached to the system. As we discussed earlier in the course, for the Unix operating system "everything is a file", so devices have special files.

Adding hardware to a Unix system is essentially a two part problem. The first is a hardware problem; "How do I attach this to the system?" and the second is a software problem "How do I make use of this new hardware from my application?"

Hardware connectivity

To connect new hardware to Unix systems, the architecture of the Unix system must be considered. Most Unix systems are manufactured with standard interfaces, such as a serial port, a parallel port and an external SCSI bus. These allow many peripherals to be installed without adding additional hardware (or software). However, some peripherals devices will require the addition of an interface card or a controller.

Interface cards are manufactured for specific bus types. Therefore, when preparing to purchase them, it is good to know the type of bus that is supported by the target Unix system.

Here are the I/O bus types supported by each vendor's workstations. More specific information about the bus type and other hardware options is distributed by the vendors.

Sun Microsystems- SparcStations   SBUS, MBUS, and XDBUS
Silicon Graphics- Indy           GIO
Silicon Graphics- Indigo2,Onyx   GIO and EISA
Silicon Graphics- Challenge      HIO and VME64
Hewlett-Packard 9000 series-    EISA
Intel-based systems (Linux)     ISA, EISA, VESA Local Bus,PCI
Digital Equipment Corp.-         PCI, TurboChannel
For more optional information about hardware please refer to this Introduction to PC Hardware article which reviews computer hardware in a general way. Contact Unix system vendors for more specific information about hardware support.

Most systems have a keyboard, mouse and video (framebuffer) interface, but these are not commonly used to add peripherals to the system and will not be considered standard. Some systems have built-in audio and video jacks available but most do not; we will not be covering audio and video peripherals at this time.

Standard Unix system interfaces:

Software connectivity

A device driver is required as the first step in connecting with a new hardware device.
The device driver is the software that operates the controller. This software must be available to the kernel if you wish to use the device. The device drivers must match the device that you wish to use.

When a program attempts to access a device, via the device file, the kernel looks up the appropriate information in its tables, and transfers control to the device driver. The device driver then performs the access request for the device and returns control back to the kernel.

For more recommend information on device drivers review the following reference.
Linux Kernel Hackers Guide

Basics of device drivers

There are two main types of devices and therefore device nodes, character and block.
A block device is one that stores information in fixed size blocks. Common block sizes are between 128 bytes and 1k bytes. Each block may be read independently of the others, so the device allows random access to each block.
Character devices deliver or accept a stream of characters (bytes) without regard to any other structure. Some character devices are keyboards and terminals.

Character devices are read from and written to with the functions: mydev_read() and mydev_write(). The read() and write() calls do not return until the operation has been completed. By contrast, block devices do not implement the read() and write() functions; instead they have a strategy function. The strategy function is used to both read and write blocks to the device.

Common device file naming conventions

In order for the operating system to recognize the hardware device, the device must have a software name, usually referred to as a device special file or device node. The node number on the special file connects it to a specific device driver in the Unix kernel. A device node is created with the command mknod

The device nodes are stored in or have links to the /dev directory. When the ls -l command is used to list these files, their major and minor numbers are displayed. The major number instructs the kernel to call the device specific code associated with the device, and the minor number is passed by the kernel to the device driver to further control the action of the device driver.

Special File Names

The standard devices for each system and a semi-standard names. For example, in Unix systems:

/dev/tty*       terminals
/dev/fd*        floppy disk
/dev/mt*        magnetic tape
/dev/st*        streaming tape
/dev/mouse      mouse

A block device can be accessed through an associated "raw" device special file. This allows diagnostics and checks to be performed on the data the device is offering. For example here are a block and character device special file under HP-UX.

brw-r-----   1 root     sys       31 0x002000 Apr  4 08:23 /dev/dsk/c0t2d0
crw-r-----   1 root     sys      188 0x002000 Apr  4 08:23 /dev/rdsk/c0t2d0

Examples of device special files for disk drives for common Unix systems are:

Where: A = SCSI address, 
       C = SCSI Controller number, 
       K = DOS primary/extended partition, 
       L = drive letter "a" through "h", 
       N = 8 * controller # + SCSI address, 
       P = BSD-style partition: (a,b,c,d,e,f,g), 
       S = System V-style slice (0,1,2,3,4,5,6).

[Note: Linux device names  and partitioning is quite different 
       from other flavors of Unix. Partition 0, or no partition 
       number, refers to the whole drive. 
       Partitions 1-4 are DOS primary partitions, while partitions 
       5-8 are extended DOS partitions.]


Terms used: bus, controller, device driver.



[EdCert previous] [EdCert next] [EdCert top]