Книга: Real-Time Concepts for Embedded Systems
12.2.2 Character-Mode vs. Block-Mode Devices
12.2.2 Character-Mode vs. Block-Mode Devices
I/O devices are classified as either character-mode devices or block-mode devices. The classification refers to how the device handles data transfer with the system.
Character-mode devices allow for unstructured data transfers. The data transfers typically take place in serial fashion, one byte at a time. Character-mode devices are usually simple devices, such as the serial interface or the keypad. The driver buffers the data in cases where the transfer rate from system to the device is faster than what the device can handle.
Block-mode devices transfer data one block at time, for example, 1,024 bytes per data transfer. The underlying hardware imposes the block size. Some structure must be imposed on the data or some transfer protocol enforced. Otherwise an error is likely to occur. Therefore, sometimes it is necessary for the block-mode device driver to perform additional work for each read or write operation, as shown in Figure 12.5.
Figure 12.5: Servicing a write operation for a block-mode device.
As illustrated in Figure 12.5, when servicing a write operation with large amounts of data, the device driver must first divide the input data into multiple blocks, each with a device-specific block size. In this example, the input data is divided into four blocks, of which all but the last block is of the required block size. In practice, the last partition often is smaller than the normal device block size.
Each block is transferred to the device in separate write requests. The first three are straightforward write operations. The device driver must handle the last block differently from the first three because the last block has a different size. The method used to process this last block is device specific. In some cases, the driver pads the block to the required size. The example in Figure 12.5 is based on a hard-disk drive. In this case, the device driver first performs a read operation of the affected block and replaces the affected region of the block with the new data. The modified block is then written back.
Another strategy used by block-mode device drivers for small write operations is to accumulate the data in the driver cache and to perform the actual write after enough data has accumulated for a required block size. This technique also minimizes the number of device accesses. Some disadvantages occur with this approach. First, the device driver is more complex. For example, the block-mode device driver for a hard disk must know if the cached data can satisfy a read operation. The delayed write associated with caching can also cause data loss if a failure occurs and if the driver is shut down and unloaded ungracefully. Data caching in this case implies data copying that can result in lower I/O performance.
- Introduction to Serial Devices
- IP characteristics
- TCP characteristics
- UDP characteristics
- ICMP characteristics
- SCTP Characteristics
- 1.1.4. Model Explorer - навигатор модели
- Session Message Block Printing
- Листинг 14.2. Использование параметра XMLWriteMode при сохранении объекта ADO.NET DataSet
- Entering and Exiting PHP Mode
- Devices
- The badblocks Command