Why do other UNIX systems need character devices for storage devices when Linux does not?

Other UNIX OSes (AIX, HPUX, Solaris and macOS) use something like '/dev/rdisk#' and '/dev/disk#' for storage devices.


I think this wikipedia article https://en.wikipedia.org/wiki/Raw_device explains it very good :

In computing, specifically in Unix and Unix-like operating systems, a raw device is a special kind of logical device associated with a character device file that allows a storage device such as a hard disk drive to be accessed directly, bypassing the operating system's caches and buffers (although the hardware caches might still be used). Applications like a database management system can use raw devices directly, enabling them to manage how data is cached, rather than deferring this task to the operating system.

In FreeBSD, all device files are in fact raw devices. Support for non-raw devices was removed in FreeBSD 4.0 in order to simplify buffer management and increase scalability and performance.1

In Linux kernel, raw devices were deprecated and scheduled for removal at one point, because the O_DIRECT flag can be used instead.

  • I never did understand WTF raw devices were character instead of block. You certainly can't access them one character at a time. – psusi Apr 21 '17 at 13:16
  • Wikipedia to the rescue, again! "Character special files or character devices provide unbuffered, direct access to the hardware device. They do not necessarily allow programs to read or write single characters at a time; that is up to the device in question. The character device for a hard disk, for example, will normally require that all reads and writes are aligned to block boundaries and most certainly will not allow reading a single byte." -- en.wikipedia.org/wiki/Device_file#Character_devices – schaiba Apr 21 '17 at 13:17
  • 2
    Right, but then why is it a character device? It should just be a block device that behaves like O_DIRECT all the time. – psusi Apr 21 '17 at 13:21

The reason why one might want to use the raw interface when the block device interface is that the raw interface is usually faster. The operating system performs buffer caching only for block-special files.

When a very large file is read from or written to a medium such as magnetic tape, buffer caching by the operating system provides no benefit because no block will be read more than once. Using the raw device interface avoids this excess system activity.

Another reason to use the raw device interface when processing very large stream files on magnetic media is that the raw interface may support very large block sizes, allowing very high data transfer rates to be achieved. When a device is accessed with the block device interface, all reads and writes must be passed through the system buffers, and are therefore limited to the file system block size (typically 1K or 2K bytes). When using the raw device, block sizes of 32K or larger may be used. --John J. Valley, UNIX Programmer's Reference; 1991 ed.

Apart from performance gains, there was (is?) a requirement that file systems accessed through the block interface be dismounted for reasons of cache consistency. Blocks cached by the system may clobber changes made through the block device when they're written back to the disk. Dismounting prior to fschk is a minor annoyance; if the application needing direct access is the primary use for the system it's much worse.

In answer to your original question many of the issues are largely historical. It's uncommon in contemporary systems for device buffers to be larger than system buffers. (When's the last time you used a workstation connected to a high-speed printer with a larger buffer than the workstations memory?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.