• Keine Ergebnisse gefunden

UNIX System Driver Specifics

Im Dokument INTER ACTIVE (Seite 52-55)

Types of Devices

There are two classes of devices: block and character. Block devices are addressable. As the term implies, the data on the device is formatted and addressed in "blocks." The term "character device" is a misnomer that should be "raw device," implying that the data being read is raw or unfor-matted; the device drivers and user programs assign semantics to the data, not the file system. A device could be both a block and character device in a sys-tem configuration, implying that the syssys-tem can access the device in two ways.

Although device drivers are normally associated with hardware devices, some drivers may have no hardware counterpart. These devices are often referred to as pseudo devices. For example, a trace driver may log certain classes of events. User programs write to the driver to record the events and read from the driver to recall the information. The trace driver would have internal mechanisms for formatting and storing the data. No hardware is associated with the driver, and the driver interfaces with software only.

DEVICE DRIVERS 3·13

Appendix C contains a sample trace driver as a device driver model. You may actually use this driver to help debug the driver you are developing.

Special Files

The UNIX System treats a device as if it were a file; that is, when a user program wishes to access a device, it accesses the file that is associated with that device. These special files are sometimes called nodes or device nodes.

The system calls that access regular UNIX System files (such as /etc/passwd) are therefore the same calls that access devices (such as /dev /console). The system calls are openO, closeO, readO, writeO, and ioctlO. The section "Func-tion Specifica"Func-tions (Driver Entry Points)" describes the system calls at the driver level in detail.

Major and Minor Numbers

The device major numbers are used by the system to determine which de-vice driver to execute when a user reads or writes to/from the special file.

The system maintains two tables for mapping

I/O

requests to the drivers: one table for "character special" and the other for "block special." This implies that there are two sets of major numbers, one for character devices and one for block devices. Both start at zero and are numbered up to the last used major number (with an upper limit of 64 for character devices and a limit of 32 block devices for UNIX System V /386). If you do an Is -1 /dev, you may find that two very different devices have the same major number. That's probably because one is a "block special," using the block major number, and the other is "character special," using the character major number. For those drivers that are both block and character devices (for example, the floppy driver), one major number of each type must be assigned. In this case, the actual numbers may be different and, in fact, often are different.

The minor number is entirely under control of the driver writer and usu-ally refers to "subdevices" of the device. These subdevices may be separate units attached to a controller. A disk device driver, for example, may talk to a hardware controller (the device) to which several disk drives (subdevices) may be attached. The UNIX System accesses different subdevices using the dif-ferent minor numbers.

In traditional UNIX Systems, major numbers were assigned by the driver writer or the system administrator. The mknod command was then used to create the files (or nodes) to be associated with the device. The UNIX System V /386 ID feature assigns the major number when the DSP is loaded by the user. More will be said about this later.

3·14 ISDG

The /dev Directory

The device file may exist anywhere in the file system, but by convention, all device files are contained in the directory /dev. The names of the files are generally derived from the names of the hardware, a convention that allows users to know what the device is by looking at the file name. It would be confusing if the file /dev /tty were a disk. Part of the name of the device file usually corresponds to the unit number of the device to be accessed via the file or, specifically, the minor number.

A new convention of UNIX System V /386 and other UNIX Systems is that /dev can contain subdirectories that hold the nodes for all the subdevices of a particular type. This reduces the clutter in the /dev directory. For exam-ple, / dey / dsk contains all the "block special" files for the floppy and hard disks; / dey /rdsk contains all the "character special" files.

The device file may exist in the file system even though the device is not configured in the running system. If a user attempts to access the device, or more specifically, the file, an error will result on the system call. Conversely, the device may be configured into the running operating system without the device file in the file system, in which case the device is inaccessible.

The Master and System Files

Associated with device drivers are two device configuration files: the Mas-ter file and the System file (also known as the dfile). For UNIX System V /386, the device driver portions of the traditional master file are in a file named mdevice. The device driver portions of the system files are in a file called sdevice. See Appendix A and mdevice(4) and sdevice(4) in the Programmer's Reference Manual for information describing the mdevice and sdevice file format.

The mdevice file contains the device name (8 characters or less), defini-tion of what funcdefini-tions the device supports (field 3 has an "r" if the read func-tion is implemented, has a "w" if write is implemented, etc.), definition of block and/or character major number, and other descriptive information about the driver.

The sdevice file contains information on how the device is installed in the system, that is, the number of units (sub devices), interrupt vector number (IVN) used, and other local information.

DEVICE DRIVERS 3-15

Im Dokument INTER ACTIVE (Seite 52-55)