The difference between Linux character devices and block devices

1. Character device
A character device means that when a device is operated, the device is read in bytes. The operation of the character device is completed by directly calling the driver program through the linux system, and the file system is not used in the upper layer of the driver program. Therefore, the characteristics of character devices are as follows:
1. Read and write in the form of byte streams, read and write devices byte by byte (there is a sequence).
2. Without the file system, the reading speed is fast.
3. Each character device has a device file under the /dev directory.
2. Block device
Block devices operate on data in the form of data blocks. When operating block devices, in addition to operating character device interfaces, there are also interfaces dedicated to operating block devices. These dedicated interfaces for block devices enable file systems to be built on block devices , and applications often use file systems when operating block devices. Some characteristics of block devices:
1. Block devices operate in the form of data blocks.
2. The data of the block device can be accessed randomly.
3. The operation of block devices often communicates with the device through the file system rather than directly.
The I/O operation mode of block devices is quite different from that of character devices, and a series of data structures such as request_queue, request, and bio are introduced. In the I/O operation of the entire block device, the "request" is throughout and always, the I/O operation of the character device is directly performed without detours, and the I/O operation of the block device will be queued and integrated.

Some personal understanding:
when the file system on the block device is mounted:

mount -t ext4 /mnt /dev/mmcblk0p2

The above command mounts the second partition of mmcblk0 to the /mnt directory and specifies the file system format as ext4.
During the mount process, a series of operations of the block device driver of mmcblk0 and ext4 file operations of /mnt have been bound.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44698673/article/details/128826956