您的位置:首页 > 其它

The three classes of devices and modules

2010-05-13 08:44 375 查看
Character
devices

A
character (char) device is one that can be
accessed as a stream of bytes (like a file); a
char
driver is in charge of implementing this
behavior. Such a driver usually implements at least the open
, close
, read
, and write
system
calls. The text console (/dev/console
) and the serial ports
(/dev/ttyS0
and friends) are examples of char devices, as they are well
represented by the stream abstraction. Char devices are accessed by means of
filesystem nodes, such as /dev/tty1
and /dev/lp0
. The only relevant difference between a char
device and a regular file is that you can always move back and forth in the
regular file, whereas most char devices are just data channels, which you can
only access sequentially. There exist, nonetheless, char devices that look like
data areas, and you can move back and forth in them; for instance, this usually
applies to frame grabbers, where the applications can access the whole acquired
image using mmap
or lseek
.

Block devices

Like char devices,
block devices are accessed by filesystem
nodes in the /dev
directory. A block device is a device (e.g., a disk)
that can host a filesystem. In most Unix systems, a block device can only handle
I/O operations that transfer one or more whole blocks, which are usually 512
bytes (or a larger power of two) bytes in length. Linux, instead, allows the
application to read and write a block device like a char device
—it permits the
transfer of any number of bytes at a time. As a result, block and char devices
differ only in the way data is managed internally by the kernel, and thus in the
kernel/driver software interface. L
ike a char device, each block device is
accessed through a filesystem node, and the difference between them is
transparent to the user. Block drivers have a completely different interface to
the kernel than char drivers.

Network
interfaces

Any network transaction is

made through an interface, that is, a
device that is able to exchange data with other hosts. Usually, an
interface
is a hardware device, but it might also be a pure software
device, like the loopback interface. A network interface is in charge of sending
and receiving data packets, driven by the network subsystem of the kernel,
without knowing how individual transactions map to the actual packets being
transmitted. Many network connections (especially those using TCP) are
stream-oriented, but network devices are, usually, designed around the
transmission and receipt of packets.
A network driver knows nothing about
individual connections; it only handles packets.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐