User-Space I/O Software

User-Space I/O Software

Though most of the I/O software is within the operating system, a small portion of it comprises libraries linked together with user programs, and even whole programs running outside the kernel. System calls, including the I/O system calls, are usually made by library procedures. When a C program includes the call

the library procedure write will be linked with the program and contained in the binary program present in memory at run time. The collection of all these library procedures is clearly part of the I/O system.

Although these procedures do little more than put their parameters in the appropriate place for the system call, there are other I/O procedures that in fact do real work. Particularly, formatting of input and output is done by library procedures. One example from C is printf, which takes a format string and possibly some variables as input, builds an ASCII string, and then calls write to output the string. As an example of printf, look at the statement

It formats a string consisting of the 14-character string "The square of" followed by the value i as a 3-character string, then the 4-character string "is", then i2 as six characters, and lastly a line feed.

An example of a similar procedure for input is scanf which reads input and stores it into variables explained in a format string using the same syntax as printf. The standard I/O library includes a number of procedures that involve I/O and all run as part of user programs.

Not all user-level I/O software consists of library procedures. Another important category is the spooling system. Spooling is a way of dealing with dedicated I/O devices in a multiprogramming system. Consider a typical spooled device: a printer. Though it would be technically easy to let any user process open the character special file for the printer, suppose a process opened it and then did nothing for hours. No other process could print anything.

Instead what is done is to create a special process, called a daemon, and a special directory, called a spooling directory. To print a file, a process first generates the entire file to be printed and puts it in the spooling directory. It is up to the daemon, which is the only process having permission to use the printer's special file, to print the files in the directory. By protecting the special file against direct use by users, the problem of having someone keeping it open unnecessarily long is removed.

Spooling is not only used for printers. It is also used in other I/O situations. For instance, file transfer over a network frequently uses a network daemon. To send a file somewhere, a user puts it in a network spooling directory. Later on, the network daemon takes it out and transmits it. One specific use of spooled file transmission is the USENET News system. This network comprises millions of machines around the world communicating using the Internet. Thousands of news groups exist on many topics. To post a news message, the user invokes a news program, which accepts the message to be posted and then deposits it in a spooling directory for transmission to other machines later. The entire news system runs outside the operating system.

Figure 1 summarizes the I/O system, showing all the layers and the principal functions of each layer. Starting at the bottom, the layers are the hardware, interrupt handlers, device drivers, device-independent software, and lastly the user processes.

Layers of the IO system and the main functions of each layer

The arrows in Figure 1 illustrate the flow of control. When a user program tries to read a block from a file, for instance, the operating system is invoked to execute the call. The device-independent software looks for it in the buffer cache, for example. If the required block is not there, it calls the device driver to issue the request to the hardware to go get it from the disk. The process is then blocked until the disk operation has been completed.

When the disk is finished, the hardware generates an interrupt. The interrupt handler is run to discover what has happened, that is, which device wants attention right now. It then extracts the status from the device and wakes up the sleeping process to finish off the I/O request and let the user process continue.


system call, daemon, spooling directory, operating system, interrupt handler