Device Files are divided into two types: block device driver and character device drive. Character Device
Drive is also known as a character device or raw devices for bare devices. Block device driver is usually a block device. Block Device
The driver transmits the transferred data with a fixed length. The character device driver transmits the data with an indefinite length of characters.
. The connected devices are also different. Block devices are generally able to access random
Data devices, such as hard drives or optical drives. The character device is the opposite. devices that access data in sequence, such as printers and terminals, are the same.
/Dev/DSK corresponds to a block device, which is used for file system operations, such as Mount. /Dev/rdsk corresponds to the character device (bare device, rdsk R is
Raw), fsck
Newfs and so on will be involved. Generally, our operating systems and various software read and write hard disks in block mode. The block here is a logical block. You can choose to create a file system, which is called a cluster in windows. Visible
Newfs or mkfs manual. Oracle is a common character-based hard disk read/write method.
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. Driver Under the device access layerProgram, As long as the driver provides the way, you can.
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, such as the hard disk type.
Bare devices, both of which support Block devices
Device): It is a random access device with a certain structure. The read and write operations on such devices are performed by block. It uses a buffer to store temporary data, write Data from the cache to the device at a time
Or read data from the device to the buffer zone at a time, such as a character device (character) such as a disk or a file system.
Device): This is an ordered data stream device. The read/write operations on such devices are performed by character, and these characters form a continuous data stream. He does not have a buffer, so he reads this device
Write operations are real-time, such as terminals and tape drives.
System
Devices that can access chunks of a fixed size are called Block devices. The most common block device is the hard disk. In addition, there is also a floppy disk drive.
Drivers, CD-ROM drives and flash memory among many other Block devices. 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 accessed randomly (unordered, it belongs to a block device.
This
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
Is a data stream. When you input the "Fox" string, the keyboard driver returns the data stream consisting of three characters in exactly the same order as the input. If you disrupt the keyboard driver
Reading strings in sequence or reading other characters is meaningless. Therefore, the keyboard is a typical character device, which provides the character stream input from the keyboard. Read the keyboard to get a character.
Stream, first "F", then "O", finally "X", and finally 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. Hard Disk Device
The driver 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 is not necessarily continuous, therefore, the hard disk can be accessed randomly, rather than in the stream mode.
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-current location-while
Block Device Access must be able to move before and after different intervals of the media. Therefore, in fact, the kernel does not have to provide a special subsystem to manage character devices, but the management of Block devices must have a special mention.
Subsystem for service. It is not only because the complexity of Block devices is much higher than that of character devices, but also because the Block devices have high requirements on the performance of the system. The performance of the entire system is brought by every single point of exploitation of the hard disk.
The improvement is far greater than the speed of the keyboard throughput. In addition, we will see that the complexity of Block devices will leave a lot of room for this optimization.
Three differences between character devices and Block devices in Linux drivers
1. Character devices can only be accessed in bytes, while Block devices can access data in blocks, such as 512 bytes and 1024 bytes.
2. Random Access from Block devices, but not from character Devices
3. There is no access limit on characters and blocks. blocks can also be accessed in bytes.