Page 441 - DCAP103_Principle of operating system
P. 441
Principles of Operating Systems
Notes The last two calls in the list are for setting and reading back all the special characters used for
erasing characters and lines, interrupting processes, and so on. In addition, they enable and
disable echoing, handle flow control, and other related functions. Additional I/O function calls
also exist, but they are somewhat specialized so we will not discuss them further. In addition,
ioctl is still available.
14.5.4 Implementation of Input/Output in Linux
I/O in Linux is implemented by a collection of device drivers, one per device type.
The function of the drivers is to isolate the rest of the system from the idiosyncracies of
the hardware. By providing standard interfaces between the drivers and the rest of the
operating system, most of the I/O system can be put into the machine-independent part
of the kernel. When the user accesses a special file, the file system determines the major
and minor device numbers belonging to it, whether it is a block special file or a character
special file. The major device number is used to index into one of two internal hash
tables containing data structures for character or block devices. Thus the located structure
contains pointer to the procedures to call to open the device, read the device, write the device, and
so on. The minor device number is passed as a parameter. Adding a new device type to Linux
means adding a new entry to one of these tables and supplying the corresponding procedures
to handle the various operations on the device.
Some of the operations which may be associated with different character devices are shown in
Figure 14.21. Each row refers to a single I/O device (i.e., a single driver). The columns represent
the functions that all character drivers must support. Several other functions also exist. When
an operation is performed on a character special file, the system indexes into hash table of
character devices to select the proper structure, then calls the corresponding function to have
the work performed. Thus each of the file operation contains a pointer to a function contained
in the corresponding driver.
Figure 14.21: Some of the File Operations Supported for Typical Character Devices
Device Open Close Read Write loctl Other
Null null null null null null ...
Memory null null mem_read mem_write nul ...
Keyboard k_open k_close k_read error k_ioctl ...
Tty tty_open tty_close tty_read tty_write tty_iocti ...
Printer lp_open lp_close error lp_write lp_iocti ...
Each driver is split into two parts, both of which are part of the Linux kernel that run in kernel
mode. The top half runs in the context of the caller and interfaces to the rest of Linux. The
bottom half runs in kernel context and interacts with the device. Drivers are allowed to make
calls to kernel procedures for memory allocation, timer management, DMA control, and other
things. The set of kernel functions that may be called is defined in a document called the Driver-
Kernel Interface. Writing device drivers for Linux is covered in detail in (Egan and Teixeira,
1992; Rubini and Corbert, 2005).
The I/O system is split into two major components: the handling of block special files and the
handling of character special files. We will now look at each of these components in turn. The
goal of the part of the system that does I/O on block special files (e.g., disks) is to minimize
the number of actual transfers that must be done. To accomplish this goal, Linux systems have
a cache between the disk drivers and the file system, as illustrated in Figure 14.22. Prior to
434 LOVELY PROFESSIONAL UNIVERSITY