Character device (source code)

= Character device

A \b[character device] is a device interface accessed through a character-special <device node>. In the Linux model, the node's <file metadata> identifies character-device type and a represented <device number>; the <device driver> defines the supported read, write and control operations. The word character does not restrict the exchanged data to readable text.<Device file metadata in the Linux man-pages project>[inode(7), file types and Device ID; mknod(2), S_IFCHR]{ref}

A useful concrete example is `/dev/null`. Data written to it are discarded, and a read returns zero bytes to indicate end of file. `/dev/zero` also discards writes but supplies zero-valued bytes on reads.<Null and zero devices in the Linux man-pages project>[DESCRIPTION]{ref} These two interfaces have different behaviours even though both use character-special files.

For an original byte-level trace, suppose an application successfully writes the three bytes `41 00 42` to `/dev/null`. A later read does not return those bytes: the interface is a data sink. A read requesting three bytes from `/dev/zero`, if completed without interruption, instead supplies `00 00 00`. The embedded zero byte in the write and zero bytes in the read are ordinary binary values, not restrictions to a text alphabet.

The familiar <file descriptor> operations provide a common access framework, but their meanings depend on the device. A <video device node> can offer format negotiation and buffer controls through <Video4Linux>; another character device may expose a stream. Character-device type alone does not promise ordinary-file storage, a particular message boundary or a useful seek operation.

The distinction from a <block device> concerns the interface category. A device node is the named <file system> object, while the character device is the interface it represents. Several nodes can identify the same represented interface, and a pathname's inode identity does not by itself identify a distinct physical peripheral.