Specifications

D
evice Driver Programming
2-2
Figure 2-1. Driver Placement in the Kernel
UNIX systems see every device as a file. Even the user-level interface to the device is
called a “special file.” The device special files reside in the /dev directory, and executing
a simple ls command reveals much about the device. For example, the command ls -l
/dev/lp might yield the following information:
crw-rw-rw- 1 root root 4, 0 Jul 26 12:45 /dev/lp
This says that the lp (line printer) is a character type device (the first letter of the file
mode field is c) and that major number 4, minor number 0 is assigned to the device. One
of the sections that follows further discusses device types, and both major and minor num-
bers.
Application Programs Versus Drivers 2
Programmers write many applications and most drivers in C. Device drivers differ in
major ways from programs designed to run at the user level. This section reviews those
differences and introduces some of the system facilities used to develop drivers.
Structure 2
The most striking difference between a driver and an application is in structure. An appli-
cation compiles into a single executable image whose top-level structure is the main rou-
tine. Subordinate routines run in sequences controlled by the main routine.
A driver has no main routine, existing as a collection of routines installed as part of the
kernel. The operating system calls and executes the driver's routines in response to system
calls or other requirements.
User Level
Kernel Level
System Call Interface
File Subsystem
Process Control
Subsystem
I/O Subsystem Device Drivers
Hardware Control
Hardware Level
160970