The Linux Concept Journey — Character Devices

Shlomi Boutnaru, Ph.D.
2 min readJun 29, 2024

--

In Unix\Linux hardware devices are accessed using device files (located in “/dev”). A character device is used in case of slow devices (like sound card/joystick/keyboard/serial ports), which usually manage a small amount of data. Operations on those devices are performed sequentially byte by byte (https://linux-kernel-labs.github.io/refs/heads/master/labs/device_drivers.html).

Moreover, as with every device also character devices have a major number and a minor number (https://medium.com/@boutnaru/the-linux-concept-journey-major-minor-numbers-56abe372482e ). We can think of the major number identifying the driver and the minor number identifying each physical device handled by the driver. Thus, we can say we have four main entities: the application, a character device file, a character device driver and a character device — as shown in the diagram below (https://sysplay.in/blog/linux-device-drivers/2013/05/linux-character-drivers/).

Lastly, in order to add a character device driver we need to register it with the kernel. This can be done by leveraging the “register_chrdev” function which is part of the “include/linux/fs.h” header file (https://elixir.bootlin.com/linux/v6.9.7/source/include/linux/fs.h#L2746). In the case of kernel version “6.9.7” there are 46 files which reference that function (https://elixir.bootlin.com/linux/v6.9.7/A/ident/register_chrdev).

See you in my next writeup ;-) You can follow me on twitter — @boutnaru (https://twitter.com/boutnaru). Also, you can read my other writeups on medium — https://medium.com/@boutnaru. You can find my free eBooks at https://TheLearningJourneyEbooks.com.

https://sysplay.in/blog/linux-device-drivers/2013/05/linux-character-drivers/

--

--