Reference Address: http://blog.chinaunix.net/uid-26322998-id-2981874.html
1, Block equipment
Devices in the system that can randomly (and do not need to sequentially) access fixed-size data slices (chunks) are called block devices, which are called blocks. The most common block devices are hard disks, and in addition, there are many other block devices, such as floppy drives, CD-ROM drives, flash memory, and so on. Note that they are all used in a way that installs the file system -a common way for block devices to access them. The General access unit is an integer multiple of 512k .
2. Character devices
Another basic device type is the character device. Character devices are ordered to be accessed in a character stream , such as a serial and keyboard. If a hardware device is accessed in a character stream, it should be attributed to a character device, and conversely, if a device is randomly (unordered) accessed, it belongs to the block device. The access unit is in bytes .
3. Difference between the two
The fundamental difference is whether they can be randomly accessed-that is, the ability to randomly jump from one location to another while accessing the device.
For example, the keyboard provides a data stream, and when you type the string "Fox," the keyboard driver returns the three-character sequence in exactly the same order as the input.Data Flow。 It makes no sense to have the keyboard driver scramble the sequence to read a string, or read other characters. So the keyboard is a typical character device that provides a stream of characters that the user enters from the keyboard. Reading a keyboard results in a stream of characters, first "F", then "O", and finally "X", ultimately the end of the file (EOF). When no one knocks on the keyboard, the character stream is empty. The hard disk device is not the same. The drive of the hard drive may require reading the contents of any block on the disk, and then go back to reading the contents of the other blocks,the blocks that are read are not necessarily contiguous on disk, so that the hard drive can be accessed randomly instead of being accessed in a stream, obviously it is a block device.
Kernel management block devices are much more nuanced than managing character devices, and the issues to consider and the work done are much more complex than character devices. This is becausethe character device needs to control only one location —--the current position, and the location of the block device must be able to move around the different intervals of the media。 So in fact the kernel doesn't have to provide a specialized subsystem to manage character devices, butthe management of block devices must have a dedicated subsystem to provide services。 Not only because the complexity of the block device is much higher than the character device, the more important reason is that the block device has a high performance requirement, and the performance of the whole system is improved by the use of every single part of the hard disk, the effect is much larger 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.
Block devices are read through the system cache, not directly to the physical disk.
A character device can read directly from a physical disk. Does not go through the system cache. (such as keyboard, directly corresponding interrupt)
The character device is a bare device by viewing the contents of the Ll/dev/vg00/if the character device starts with a C character
a block device is a file device by viewing the contents of the ll/dev/vg00/if the B character is at the beginning of the block device
4. Application
in use, you need to consider whether to choose a block device or a character device for your database application. General Database manufacturers will recommend that you build a library using bare devices (character devices), space management is completely managed by the database engine, so that all data and log directly write disk, when a system failure, the system security is strong, do not lose data . However, it is also said that the use of block devices to facilitate the management of maintenance personnel system management, because the use of bare devices after the first allocation, the space of the device can not do any other purposes, but the block device is not, you want to use how much space to allocate how much, you can expand freely, without the need to allocate all at once. So I recommend using bare devices while creating the database Master Library, while the business database and tempdb use block devices.
"Original"--Linux character device, block device, network device