Introduction to basic device types

    Linux divides devices into three basic types, which are summarized as follows:
    1. Character device
    A character device is a device that can be accessed like a byte stream (similar to a file). This feature is implemented by the character device driver. Character device drivers typically implement at least the open, close, read, and write system calls. Character terminals (/dev/console) and serial ports (/dev/tty0 and similar devices) are two character devices that illustrate the abstraction of "streams" well. Character devices can be accessed through file system nodes, such as /dev/tty1 and /dev/lp0. The difference between device files and ordinary files is that the access of ordinary files can move the access position forward and backward, while most character devices are a data channel that can only be accessed sequentially. But there are also character devices with data area characteristics, which can be moved back and forth to access the device. For example frame grabbers, applications can use mmap or lseek to access the entire grabbed image.

    2. Block devices
    Block devices are also accessed through the file system nodes in the /dev directory. A file system can be accommodated on a block device such as a disk. On most Unix systems, block devices can only transfer one or more complete blocks per I/O operation, and each block contains 512 bytes (or a higher power of 2 bytes of data). Linux allows applications to read and write block devices like character devices, allowing any number of bytes of data to be passed at a time. Therefore, the difference between a block device and a character device is only in the way the kernel manages data internally, that is, the software interface between the kernel and the driver is different.

    3. Network interface
    Any network transaction is formed through a network interface, a device capable of exchanging data with other hosts. Typically, an interface is a hardware device, but it may also be a purely software device, such as a loopback interface. The network interface is driven by the network subsystem in the kernel and is responsible for sending and receiving packets, but it does not need to understand how each transaction maps to the actual transmitted packets. Many network connections (especially those using the TCP protocol) are stream-oriented, but a network device is designed around the transmission and reception of packets, it doesn't need to know information about each connection, it just processes the packets. Since it is not a stream-oriented device, it is difficult to map network interfaces to nodes in the file system. The Unix way of accessing network interfaces is still to assign them a unique name (like eth0), but that name has no corresponding node in the filesystem. The communication between the kernel and the network device driver is completely different from the communication between the character and block device drivers.
It calls a set of functions related to data packet transmission instead of read, write and so on.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326225110&siteId=291194637