Ubuntu: What is a character device?



Question:

I was trying to make a partition on my USB drive when I came across some files/entities in /dev/ which seemed unfamiliar (such as hidraw2). When I opened /dev in file manager and looked into their properties, it says that they are character devices. While searching about them, I came across posts that explain what 'block devices' are, but no such post for character devices so far.

I would like to know what a character device is and what it does. Also I wonder about why they are called devices.


Solution:1

This is a simple explanation:

  • A Character ('c') Device is one with which the Driver communicates by sending and receiving single characters (bytes, octets).
  • A Block ('b') Device is one with which the Driver communicates by sending entire blocks of data.
  • Examples for Character Devices: serial ports, parallel ports, sounds cards.
  • Examples for Block Devices: hard disks, USB cameras, Disk-On-Key.
  • For the user, the type of the Device (block or character) does not matter - you just care that this is a hard disk partition or a sound card.
  • Driver programmers, however, do care.

Here is more:

16.1.4.2 Block and Character Devices A block device is one that is designed to operate in terms of the block I/O supported by Digital UNIX. It is accessed through the buffer cache. A block device has an associated block device driver that performs I/O by using file system block-sized buffers from a buffer cache supplied by the kernel. Block device drivers are particularly well-suited for disk drives, the most common block devices.

A character device is any device that can have streams of characters read from or written to it. A character device has a character device driver associated with it that can be used for a device such as a line printer that handles one character at a time. However, character drivers are not limited to performing I/O a single character at a time (despite the name ``character'' driver). For example, tape drivers frequently perform I/O in 10K chunks. A character device driver can also be used where it is necessary to copy data directly to or from a user process. Because of their flexibility in handling I/O, many drivers are character drivers. Line printers, interactive terminals, and graphics displays are examples of devices that require character device drivers.

Sources:

http://haifux.org/lectures/86-sil/kernel-modules-drivers/node10.html

https://arstechnica.com/civis/viewtopic.php?t=787631


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »