I/O Systems & Device Management

block vs character devices

Devices come in two broad personalities, and the OS treats them differently. One personality is a bookshelf of fixed-size, individually numbered drawers you can open in any order — that is a block device. The other is a one-way pipe through which things flow past as a stream, one item at a time, that you cannot rewind — that is a character device. Disks are the classic block devices; keyboards, mice, and serial lines are classic character devices.

Concretely, a block device stores data in fixed-size blocks (say 512 bytes or 4 KB) that can be read or written in any order — it is randomly addressable, so you can ask for block number 90000 directly without touching the others. Disks, SSDs, and USB drives are block devices, and file systems are built on top of them; the kernel typically buffers and caches block devices heavily and may reorder requests for efficiency. A character device, by contrast, delivers or accepts a stream of bytes in sequence, character by character, with no notion of addressable blocks and usually no seeking — you read what comes next. Keyboards, mice, terminals, audio, and serial ports are character devices. On Unix-like systems both kinds appear as special files (for example /dev/sda for a disk block device, /dev/tty for a terminal character device), and a single 'b' or 'c' in a directory listing marks which is which.

Why it matters: this split shapes the whole I/O software stack. Block devices get the block layer, the buffer cache, request scheduling, and file systems on top; character devices get a simpler byte-stream path. The categories are a useful default rather than an absolute law — some devices fit awkwardly (a network interface is neither, and is handled by its own subsystem), and the same physical disk can sometimes be accessed through a raw character interface that bypasses the block buffering. But block-versus-character is the first question the kernel asks of any storage-or-stream device, because it decides which machinery applies.

ls -l /dev shows entries beginning with 'b' or 'c': /dev/sda (b) is a disk block device you can address by block; /dev/ttyS0 (c) is a serial-port character device you read as a byte stream. The single letter tells the kernel which I/O path to use.

Block = randomly addressable fixed-size blocks; character = a sequential byte stream.

The block-versus-character split is the kernel's default classification, not an iron law: a network card fits neither and has its own path, and a disk can also be opened as a raw character device that skips the block cache.

Also called
block devicecharacter deviceraw device區塊裝置/字元裝置