Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the types of linux device files

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what are the types of linux device files". In daily operation, I believe many people have doubts about the types of linux device files. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what are the types of linux device files?" Next, please follow the editor to study!

Linux device files have two types: 1, character devices, can be accessed like a byte stream of device files, when the character device issued a read and write request, the corresponding IO operation occurs immediately, common character terminals, keyboards, etc.; 2, block devices, TO operations must be carried out in blocks as a unit to access the device files, block devices can install the file system.

The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

Overview of device Fil

In a Unix-like operating system, a device file or special file is the interface to a device driver and appears in the file system as if it were a normal file. There are also special files in MS-DOS,OS / 2 and Microsoft Windows. These special files allow applications to interact with devices using their device drivers through standard input / output system calls. The use of standard system calls simplifies many programming tasks and enables a consistent user-space I / O mechanism regardless of the characteristics and functions of the device.

Device files usually provide a simple interface to standard devices, such as printers and serial ports, but can also be used to access specific unique resources on these devices, such as disk partitions. In addition, device files are useful for accessing system resources that are independent of any actual device, such as data receivers and random number generators.

On Linux, there are seven types of file types:

Ordinary file (-)

Directory (d)

Soft link (character link L)

Socket file (S)

Character device (S)

Block device (B)

Pipe file (named pipe P)

Therefore, there are two types of device files: character devices and block devices.

(1) character equipment

A character device is a device that can be accessed like a byte stream. When a read-write request is made to the character device, the corresponding IO operation occurs immediately. Many devices in Linux system are character devices, such as character terminal, serial port, keyboard, mouse and so on. In the development of embedded Linux, the most contacts are character devices and drivers.

(2) Block equipment

Block devices are the devices that must be accessed on a block-by-block basis when performing TO operations in Linux systems, and block devices can install file systems. The block device driver uses a block of system memory as a buffer, so issuing read and write access to the block device does not necessarily result in hardware Ihand O operations immediately. The common block devices in Linux system are hard disk, floppy drive and so on.

Distinguish between block devices and character devices

Block devices are hardware devices that are distinguished by random (not necessarily sequential) access to fixed-size blocks (chunk). A fixed-size chunk is called a block. The most common block devices are hard drives, but there are also many other block devices, such as floppy disk drives, Blu-ray readers, and flash memory. Note that these are devices that mount the file system, which is like the lingua franca of block devices.

Character devices are accessed through continuous stream data, byte after byte. Typical character devices are terminals (terminals are divided into multiple, physical and virtual ones) and keyboards.

The easiest way to distinguish between block devices and character devices is to look at the way data is accessed. It is the block device that can randomly access the data, and the character device that must be accessed in byte order.

If you can read a little data here, read a little data there, and finally string into a whole piece of continuous data, then this is a block device, just like the data on the hard disk is discontinuous, and you may need to obtain a piece of data by random access. For example, for a slightly larger file on disk, the first 10k data may be continuous data blocks or in continuous sectors, and the next 10k data may be far away from it or even on different cylinders.

If each byte in a piece of data is the same as the byte order at the time of access, that is, the byte order is exactly the same from the time of access acquisition to the final processing of the data, then this is a character device. In other words, a character device can be thought of as a streaming device. Just like keyboard input data, two word keys are tapped successively, and the byte data corresponding to these two keys must be typed first in front and then in the back when being received. In the same way, the terminal equipment is the same. When the program outputs the data to the terminal, the program outputs the letter a first and then the number 3, so it must be a before and 3 after when displayed on the terminal.

At this point, the study on "what are the types of linux device files" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report