IO software is frequently organized in the following layers
- User Level Libraries: This offers simple interface to the user program to perform input and output. stdiois an example of library provided by C and C++ programming languages.
- Kernel Level Modules: This offers device driver to cooperate with the device controller and device self-governing I/O modules used by the device drivers.
- Hardware: This layer consists of actual hardware and hardware controller that interact with the device drivers and makes hardware active.
A key conception in the design of I/O software is that it must be device-independent where it must be conceivable to write programs that can access any I/O device without taking to identify the device in advance.
Example: A program which reads a file as input must be able to read a file on a floppy disk, on a CD-ROM, or on a hard disk without having to vary the program for each different device.
These are software modules that can be plugged into an OS to handle a specific device. Operating System takes assistance from device drivers to handle all I/O devices. Device drivers condense device-dependent code and implement a standard interface in a way that code comprises device-specific register reads/writes. Device driver, is usually written by the device’s manufacturer and provided along with the device on a CD-ROM.
A device driver performs the following given jobs:
- To admit request from the device independent software overhead to it.
- Cooperate with the device controller to take and give I/O and perform essential error handling
- Making sure that the request is executed effectively
Assume a request comes to read a block n. If the driver is idle at the time a request enters, it starts carrying out the request instantly. Else, if the driver is now busy with some other request, it put the new request in the queue of pending-requests.
Interrupt Service Routine
An as an interrupt service routine also called as interrupt handler or ISR, is a segment of software or more precisely a call-back function in an operating system whose execution is triggered by the response of an interrupt. When an interrupt arises, the interrupt process does whatsoever it has to in order to handle the interrupt, updates data-structures and come around process that was waiting for an interrupt to occur.
IO Software Device Independent
The elementary function of the device-independent software is to attain the I/O functions that are common to all devices and to deliver a constant interface to the user-level software. However, it is hard to write entirely device independent software but, can write some modules which are mutual among all the devices. A list of functions of device-independent I/O Software is given as:
- Uniform-interfacing for device drivers.
- Device naming – Prompt names mapped to Major and Minor device numbers.
- Device protection.
- Offering a device-independent block size.
- Buffering as data coming off a device cannot be stored in ultimate destination.
- Storage allocation on block devices.
- Allocation and deallocating dedicated devices
- Error Reporting
User-Space I/O Software
These are the libraries which deliver richer and easy interface to access the functionality of the kernel or interactive with the device drivers. Most of the user-level I/O software contains library processes with some exception like spooling system that is a way of dealing with dedicated I/O devices in a multi-programming system. I/O Libraries e.g., stdio are in user-space to deliver an interface to the OS resident device-independent I/O software. getchar(), putchar(), scanf() and printf() are example of user level I/O.
Kernel I/O Subsystem
Kernel I/O Sub-system is accountable to provide several services related to I/O. some of the services provided are given as:
- Scheduling: Kernel schedules a set of I/O requests to define a good order in which to execute them. Whenever an application issues a blocking I/O system call, the request is put into the queue for that device. The Kernel I/O scheduler reorganizes the order of the queue to expand the overall system efficiency and the average response-time experienced by the applications.
- Buffering: Kernel I/O sub-system reserves a memory zone known as bufferthat stores data while they are moved b/w two devices or b/w a device with an application operation. Buffering is done to cope with a speed disparity between the producer and consumer of a data stream or to adjust between devices that have different data transfer sizes.
- Caching: Kernel keeps cache memory which is area of fast memory that holds copies of data. Access to the cached copy is much more effective than access to the original.
- Spooling and Device Reservation: A spool is a buffer that contains output for a device, such as a printer, that cannot accept inserted data streams.
- Error Handling: An OS that uses secure memory can guard against many kinds of hardware and application errors.