A Remote Disk Driver
For my purpose holds ... To strive, to seek, to find,
and not to yield.
— Alfred, Lord Tennyson
Earlier chapters explain I/O devices and the structure of a device driver. Chapter
16 describes how block-oriented devices use DMA, and shows an example Ethernet
This chapter considers the design of a device driver for secondary storage devices
known as disks or hard drives. The chapter focuses on basic data transfer operations.
The next chapter describes how higher levels of the system use disk hardware to pro-
vide files and directories.
18.2 The Disk Abstraction
Disk hardware provides a basic abstraction in which a disk is a storage mechanism
that has the following properties.
Nonvolatile: data persists even if power is removed.
Block-oriented: the interface provides the ability to
read or write fixed-size blocks of data.
Multi-use: a block can be read and written many
Random-access: blocks can be accessed in any order.
372 A Remote Disk Driver Chap. 18
Like the Ethernet hardware described in Chapter 16, disk hardware typically uses
Direct-Memory-Access (DMA) to allow the disk to transfer an entire block before inter-
rupting the CPU. Also like the Ethernet driver, a disk driver does not understand or ex-
amine the contents of data blocks. Instead, the driver merely treats the entire disk as an
array of data blocks.
18.3 Operations A Disk Driver Supports
At the device driver level, a disk consists of fixed-size data blocks that can be ac-
cessed randomly using three basic operations:
Fetch: Copy the contents of a specified block from the disk to a
designated location in memory.
Store: Copy the contents of memory to a specified block on the
Seek: Move to a specified block on the disk. The seek option is
most important for electro-mechanical devices (i.e., a magnetic
disk) because it can be used as an optimization that positions the
disk head where it will be needed in the future. Thus, as solid state
disks become widely used, seek may become less important.
The block size of a disk is derived from the size of a sector on magnetic disks.
The industry has settled on a de facto standard block size of 512 bytes; throughout the
chapter, we will assume 512-byte blocks.†
18.4 Block Transfer And High-Level I/O Functions
Because the hardware provides block transfer, it makes sense to design an interface
that allows read and write to transfer an entire block. The question becomes how to in-
clude a block specification in the existing high-level I/O operations. We might use
seek: require a programmer to call seek to move to a specific block before calling read
or write to access data in the block. Unfortunately, requiring a user to call seek before
each data transfer is clumsy and error prone. Therefore, to keep the interface simple,
we will stretch the usual meaning of arguments to read and write: instead of interpret-
ing the third argument as a buffer size, we will assume the buffer is large enough to
hold a disk block, and use the third argument to specify a block number. For example,
read ( DISK0, buff, 5 )
requests the driver to read block five from the disk into memory starting at location
†Although modern disks often use an underlying block size of 4K bytes, the hardware presents an inter-
face that uses 512-byte blocks.