In Ubuntu, we find numerous special files in the directory /dev. These are basically device files. There are mainly two most common types of device files -
Device files acts as an interface between applications and the device driver. And, the device drivers can access the system hardware. In other words, we can say device files interact with device drivers when a request is received. We would like to add here that, device files should not be confused with device drivers. These device files appear as regular files in our system but are used specifically for accessing the systems' hardware.
Device files in Ubuntu
So, we start with Block device files first. Block devices are mainly storage devices like hard drives, flash drives etc. So, we use Block devices files to access such devices. What happens when we read or write from/to a block device? It stores data in the memory for faster access, until the data is no longer required. This speeds up the entire read and write access to the block device.
Whereas, Character devices files are used to transfer data between devices without buffering. We can't mount filesystems through character device files. And, data is transferred bytewise.
As already covered, device files are located in /dev directory. Issue the following in terminal to identify character or block device files -
ls -l /dev
You would notice that, all character files would begin with "c" and block device files with "b". For instance,
crw------- 1 root root 10, 126 Nov 22 03:32 ecryptfs brw-rw---- 1 root disk 8, 1 Nov 22 03:32 sda1
From the above output, we can also identify major and minor numbers. Like (10, 126) or (8, 1). The assigned major number (the one which appears first in the output) basically identifies the associated device driver with the device. So, a driver could be managing different devices at the same time. And, that is where minor numbers becomes crucial. It helps the device driver to distinguish between different devices.
In conclusion, we have covered here two types of devices files - Character & Block device files. We also saw how to identify such device files and what role does assigned major & minor number play in scheme of things.