Linux block device, character device

Source: Internet
Author: User

The character device or block device definition belongs to the device access layer of the operating system, which is not necessarily related to the characteristics of the actual physical device.

The driver is under the device access layer, so you only need to provide the driver. That is to say, if the driver supports the stream method, you can access it in this way. If the driver also supports the block method, you can access it in any way, A typical type is a hard-disk bare device. Both devices support block devices. The block device is a random access device with a certain structure. read/write operations on such devices are performed by block, it uses a buffer to store temporary data. when conditions are ripe, it is written to the device from the cache or read from the device to the buffer, such as disks and file systems.

Character device): It is a sequential data stream device that reads and writes data by Character and these characters form a continuous data stream. It does not have a buffer, so the read and write operations on such devices are real-time, such as terminals and tape drives.
A device that can randomly access chunks of a fixed size data disk without the need for sequential access is called a block device, which is called a block. The most common block device is the hard disk, in addition to many other Block devices, such as floppy drives, CD-ROM drives, and Flash. Note that they are all used to install the file system-this is also a common access method for Block devices.

Another basic device type is character devices. Character devices are accessed sequentially in the form of character streams, such as serial ports and keyboards. If a hardware device is accessed in the form of a forward stream, it should be attributed to a character device. In turn, if a device is randomly and unordered, it belongs to a block device.

The fundamental difference between the two types of devices is whether they can be randomly accessed-in other words, whether they can jump from one location to another freely when accessing the device. For example, a keyboard device provides a data stream. When you press the string "fox, the keyboard driver returns the data stream consisting of three characters in exactly the same order as the input. It makes no sense to disturb the keyboard driver to read strings or read other characters. Therefore, the keyboard is a typical character device, which provides the character stream input from the keyboard. When you perform a read operation on the keyboard, you will get a compaction stream, namely "f", "o", and "x". The final result is the end of the file (EOF ). When no one knocks on the keyboard, the seek stream is empty. Hard Disk devices are not the same. The drive of the hard disk device may need to read the content of any block on the disk, and then switch to read the content of another block. The read block location on the disk may not be consecutive, therefore, a hard disk can be accessed randomly, rather than in a stream. It is obviously a block device.

The kernel management block device is much more detailed than the character management device, and the problems to consider and the work to be done are much more complicated than the character device. This is because the character device only needs to control one location-the current location-and the access location of the block device must be able to move before and after different intervals of the media. Therefore, in fact, the kernel does not have to provide a dedicated subsystem to manage character devices, but the management of Block devices must have a dedicated subsystem to provide services. Not only is the complexity of Block devices far higher than that of character devices, but more importantly, Block devices require high execution performance. The performance of the entire system is improved when multiple hard disks are used, the effect is much higher than the keyboard throughput speed. In addition, we will see that the complexity of Block devices will leave a lot of room for this optimization.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.