I/O operations involve many concerns: buffering, error handling, device-specific commands, interrupt processing. Putting all this in one place creates unmaintainable code and makes the OS dependent on hardware details.
I/O software is organized into four layers, each handling a specific abstraction level — from user-facing system calls down to hardware interrupt handling.
The four layers (top to bottom):
- User-Level I/O Software: System calls (
read(),write(),fopen()), buffering in user space - Device-Independent OS Software: Naming, protection, buffering, caching, error reporting
- Device Drivers: Translate generic requests to device-specific commands
- Interrupt Handlers: Process device interrupts and signal completion
- Each layer only communicates with adjacent layers
- Device-independent layer makes all devices look uniform to applications
- Drivers can be loaded/unloaded without changing the OS
- Modularity enables portability across hardware platforms
- Built from: O System, O Software
- Builds into: O Request to Hardware Operation
- Related: Device Driver, Interrupt Handler, O Software
- Contrasts with: Device Controller (hardware, not software)
- Too many layers can impact performance due to context switches
- Device-independent layer must know enough about devices to do buffering correctly
- Error handling must propagate correctly up through all layers
- Some devices bypass layers (e.g., memory-mapped I/O)