Introduction to Linux File System

Source: Internet
Author: User
ArticleDirectory
    • Copyright Notice
    • Other works
    • Bug report, discussion and discussion
    • Required links
    • Recommended links
    • Locally defined link
    • Sockets and Pipelines
    • Mount point
    • Virtual console and console device)
    • Serial Interface
    • Pseudo Terminal (Pty)

Original article link

Introduction to Linux Device Files

Introduction to Linux device files: Jin Bu Guo Copyright Notice

The author of this article is a free software enthusiast, so although this article is not software, it is released in the spirit of GPL. No one can use, repost, copy, or re-distribute the statement freely. However, the author's signature must be retained and no clauses in the statement can be modified in any form or attached. You can freely link, download, and disseminate this document, provided that the full text is fully reproduced, including the complete copyright information and the translator's statement.

Other works

The author of this article is very willing to share the fruits of work with others. If you are interested in other translated works or technical articles, you can view the list of existing works in the following position:

    • Jin Bu's work list
Bug report, discussion and discussion

Due to the limited level of the author, the accuracy of the work cannot be ensured. Please identify the content yourself in reading. If you find any errors in your work, please send a letter stating that, even if it is a mistake, I will be willing to accept any suggestions to improve the quality of your work. If you are willing to further discuss the content in your work with me, you are also welcome to contact me. Contact: Email: csfrank@citiz.net; QQ: 70171448; MSN: csfrank122@hotmail.com

Overview

Device management is a basic concept in Linux. However, due to the increasing intelligence in Linux, udev is widely used, as a result, more and more new Linux users are no longer familiar with things in the/dev directory. Sometimes it gets crazy when you encounter problems.

There are two types of devices in Linux: character devices (unbuffered and sequential access only) and block devices (with buffering and random access ). Each character device and block device must have the primary and secondary device numbers. devices with the same primary device numbers are similar devices (using the same driver ).Program). Among these devices, some devices are abstract to the physical hardware that actually exists, while some devices are functions provided by the kernel itself (not dependent on specific physical hardware, it is also called "Virtual Device "). Each device has a corresponding file (node) under the/dev directory ). You can run the CAT/proc/devices command to view the master device Number of the currently loaded device driver. All devices recognized by the kernel are recorded in the documentation/devices.txt file under the original code tree. In addition to character devices and block device nodes, the/dev directory usually contains FIFO pipelines, sockets, soft/hard connections, and directories. These items do not have the primary/secondary device number.

Device Files

All devices that can be identified by the Linux kernel are recorded in
Http://www.lanana.org/docs/device-list/
The documentation/devices.txt in the kernel source code tree may not be the latest version.

The most basic requirement for understanding these devices is to understand the meaning of each device file. The following lists common device files and their meanings (which are omitted when the device is remote ).

---------------------------------------------------------------------- Main device number device type device number = Brief description of file name -------------------------------------------------------------------- 0 untitled device (for example: mounted non-device) 0 = NULL device number reserved 1 char memory device 1 =/dev/MEM direct access to physical memory 2 =/dev/kmem access to memory 3 after kernel virtualization =/dev/null empty device. Any write will be discarded directly, and any read will get an EOF. 4 =/dev/port access I/O port 5 =/dev/zero byte source, can only read an infinite number of zero bytes. 7 =/dev/full device. Any write operation will fail, and errno is set to enospc to indicate no space left. 8 =/dev/random number generator. Random numbers are generated completely by user input. If you stop all actions, a new random number is generated. 9 =/dev/urandom is faster, but it is not safe enough for random number generators. Try to generate a random number by user input. If the user stops all actions, use the generated random number as the seed to generate a new random number. 10 =/dev/AIO asynchronous I/O notification interface 11 =/dev/kmsg any write to this file will be used as printk output 1 blockram disk 0 =/dev/ram0 1st RAM disks (initrd can only use ram0) 1 =/dev/ram1 2nd RAM disks... 200 =/dev/ram200 200th RAM disk 4 chartty (terminal) device 0 =/dev/tty0 current virtual console 1 =/dev/tty1 1st virtual consoles... 63 =/dev/tty63 63rd virtual console 4 blocks if the root file system is mounted in read-only mode, it is impossible to create a real device node, in this case, the device is used as the alias of the dynamically allocated master (Major) device 0 =/dev/root 5 char other tty devices 0 =/dev/tty current tty device 1 =/d EV/Console System Console (usually/dev/tty0) 2 =/dev/ptmx all Pty master's mutex 7 char virtual console capturing devices (these devices allow both read and write) 0 =/dev/VCs text content of the current virtual console (VC) 1 =/dev/vcs1tty1... 63 =/dev/vcs63tty63 text content 128 =/dev/vcsa text/attribute content of the current virtual console (VC) 129 =/dev/vcsa1tty1 text/attribute content... 191 =/dev/vcsa63tty63 text/attribute content 7 block loopback devices (using a common disk file to simulate a block device) bind the loopback device by Mount (8) or losetup (8) processes 0 =/dev/loop0 1st loopback devices 1 =/dev/loop1 2nd loopback devices... 8 blockscsi Disk (0-15) 0 =/dev/SDA 1st SCSI disks (entire disk) 16 =/dev/SDB 2nd SCSI disks (entire disk) 32 =/dev/SDC 3rd SCSI disks (entire disk )... 240 =/dev/SDP 16th SCSI disks (the entire disk) Partition representation method is as follows (Take 3rd SCSI disks as an example) 33 =/dev/sdc1 1st partitions 34 =/dev/sdc2 2nd partitions... 47 =/dev/sdc15 15th partitions for Linux/i386, partition 1-4 is the primary partition, and partition 5-15 is the logical partition. 9 blockmetadisk (RAID) device 0 =/dev/md0 group 1st metadisk 1 =/dev/md1 Group 2nd metadisk... the metadisk driver is used to split a file system into multiple physical disks. 10 char non-serial mouse, various miscellaneous devices and features 1 =/dev/psauxps/2 mouse 131 =/dev/temperature machine internal temperature 134 =/dev/apm_biosapm (Advanced Power Management) bios135 =/dev/RTC real-time clock (real time clock) 144 =/dev/NVRAM non-easy configuration ram162 =/dev/SMBus System Management bus (System Management Bus) 164 =/dev/ipmointel intelligent platform management (Intelligent platform management) interface 173 =/dev/ipmikcs intelligent platform management (Intelligent platform management) interface 175 =/dev/agpgartagp graphical address re ing table) 182 =/dev/perfctr performance monitoring counter 183 =/dev/hwrng general hardware random number generator 184 =/dev/CPU/microcode CPU Code Update interface 186 =/dev/atomicps atomic snapshot of Process status data 188 =/dev/smbusbiossmbus (System Management Bus) bios200 =/dev/NET/tuntap/TUN network device (TAP/TUN implements network devices in software mode) tap simulates Ethernet frames (Layer 2 ), tun simulates the IP package (Layer 3 ). 202 =/dev/EMD/CTL enhanced metadisk RAID (EMD) controller 220 =/dev/mptctlmessage passing Technology (MPT) control223 =/dev/input/uinput user-layer input device drivers support 227 =/dev/mcelogx86_64 machine check exception driver228 =/dev/hpethpet driver229 =/dev/fusefuse (virtual user space) file System) 231 =/dev/Snapshot System memory snapshot 232 =/dev/KVM kernel-based fictitious machine (based on amd svm and Intel VT hardware Virtual Technology) 11 blockscsi CD-ROM device 0 =/dev/MCM 0 1st SCSI CD-ROM 1 =/dev/scd1 2nd SCSI CD-RO M... 13 char core input device 32 =/dev/input/mouse0 1st cursor 33 =/dev/input/mouse1 2nd mouse... 62 =/dev/input/mouse30 31st mouse 63 =/dev/input/mice all mouse unification 64 =/dev/input/event0 1st event queues 65 =/dev/ input/event1 2nd event queues... 95 =/dev/input/event1 32nd event queues 21 char General SCSI device (usually SCSI optical drive) 0 =/dev/sg0 1st General SCSI devices 1 =/dev/SG1 2nd General SCSI devices... 29 char universal frame buffer device 0 =/dev/fb0 1st frame buffer device 1 =/dev/Fb1 2nd frame buffer devices... 31 =/d EV/fb31 32nd frame buffer device 30 chariBCS-2 compatible device 0 =/dev/socksys socket access interface 1 =/dev/spxsvr3 local X interface 32 =/dev/inet/IP address access interface 33 =/dev/inet/ICMP 34 =/dev/inet/GGP 35 =/dev/inet/ipip 36 =/dev/inet/tcp 37 =/dev/inet/EGP 38 =/dev/inet/pup 39 =/dev/inet/udp 40 =/dev/inet/IDP 41 =/dev/inet/rawip In addition, the iBCS-2 also requires that the following connection must exist/dev/IP->/dev/inet/IP/dev/ICMP->/dev/inet/ICMP/dev/GGP->/dev /inet/GGP/dev/ipip->/dev/in ET/ipip/dev/TCP->/dev/inet/tcp/dev/EGP->/dev/inet/EGP/dev/Pup->/dev/inet/pup/ dev/UDP->/dev/inet/udp/dev/IDP->/dev/inet/IDP/dev/rawip->/dev/inet/rawip/dev/inet/ ARP->/dev/inet/udp/dev/inet/rip->/dev/inet/udp/dev/nfsd->/dev/socksys/dev/x0r->/ dev/null 36 charnetlink supports 0 =/dev/route routing, device update, kernel to user 3 =/dev/fwmonitorfirewall packet copy 59 charsf firewall Module 0 =/dev/firewall and SF Kernel module communication 65 blockscsi disk (16-31) 0 =/dev/SDQ 17th SCSI disks (entire disk) 16 =/dev/SDR 18th SCSI disks (entire disk) 32 =/dev/SDS 19th SCSI disks (entire disk )... 240 =/dev/sdaf 32nd SCSI disks (entire disk) 66 blockscsi disks (32-47) 0 =/dev/sdag 33rd SCSI disks (entire disk) 16 =/dev/sdah 34th SCSI disks (entire disk) 32 =/dev/SDAI 35th SCSI disks (entire disk )... 240 =/dev/sdav 48th SCSI disks (entire disk) 89 chari2c bus interface 0 =/dev/i2c-0 1st I2C adapters 1 =/dev/i2c-1 2nd I2C adapters... 98 Block Virtual Block devices in user mode (the partitioning method is the same as that of SCSI disks) 0 =/dev/ubda 1st user mode Block devices 16 =/dev/udbb 2nd user mode Block devices... 103 block audit (Audit) device 0 =/dev/Audit audit (Audit) device 128-135 charunix98 Pty master these devices should not have device nodes, instead, it should be accessed through the/dev/ptmx interface. 136-143 charunix98 Pty slave these device nodes are automatically generated (with appropriate permissions and modes) and cannot be created manually. You can mount the devpts File System to the/dev/PTS directory by using the appropriate mount option (usually mode = 0620, gid = <"tty" group GID>. 0 =/dev/pts/0 1st unix98 Pty slave 1 =/dev/pts/1 2nd unix98 Pty slave... 153 blockenhanced metadisk RAID (EMD) storage unit (same partitioning method as SCSI disk) 0 =/dev/EMD/0 1st storage units 1 =/dev/EMD/0p1 1st storage units 1st partitions 2 =/dev/EMD/0p2 1st storage units 2nd partitions... 15 =/dev/EMD/0p15 1st 15th storage units 16 =/dev/EMD/1 2nd storage units 32 =/dev/EMD/2 3rd storage units... 240 =/dev/EMD/15 16th storage units 180 charusb character devices 96 =/dev/USB/hiddev0 1st USB man-machine interface devices (mouse/keyboard/Game lever/handwritten edition and others operating computers) device )... 111 =/dev/USB/hiddev15 16th USB man-machine interface devices 180 blockusb Block devices (USB flash drives and others) 0 =/dev/UBA 1st USB Block devices 8 =/dev/UBB 2nd USB Block devices 16 =/dev/UBC 3rd USB Block devices... 192 char kernel profiling interface 0 =/dev/profileprofiling profiling device 1 =/dev/profile0cpu 0 profiling device 2 =/dev/profile1cpu 1 profiling device... 193 char kernel event tracking interface 0 =/dev/trace control device 1 =/dev/trace0cpu 0 tracking device 2 =/dev/trace1cpu 1 tracking device... 195 charnvidia graphics devices (such as graphics cards) 0 =/dev/nvidia0 1st NVIDIA cards 1 =/dev/nvidia1 2nd NVIDIA cards... 255 =/dev/nvidiactlnvidia card control device 202 char-Specific CPU mode register (model-specific register, MSR) 0 =/dev/CPU/0/msrcpu 0 MSRs 1 =/dev/CPU/1/msrcpu 1 MSRs... 203 charcpu cpuid Information 0 =/dev/CPU/0/cpuidcpu 0 cpuid 1 =/dev/CPU/1/cpuidcpu 1 cpuid...

Are you surprised? Why are there no devices such as/dev/hda not commonly used? The reason is that, starting from version 2.6.19, the kernel has introduced a new ata driver to uniformly use the SATA/PATA hard drive with/dev/sd? So/dev/HD? There is no need to exist. Specifically, you should not use the driver below "ATA/atapi/MFM/rll support" when compiling the kernel, instead, the updated "Serial ATA and parallel ata drivers" driver is used.

Links, sockets, pipelines, and mount points

This section details some files that should or may exist outside the/dev directory. It is best to use the same format (absolute path or relative path) as the link here ). Whether a hard or symbolic connection is used depends on different devices.

Required links

These connections must exist on all systems:

 
Brief description of the target link type/dev/FD/proc/self/fdsymbolic file description/dev/stdinfd/0symbolic standard input file description/dev/stdoutfd/1symbolic standard output file descriptor /dev/stderrfd/2symbolic standard error file descriptor/dev/nfsdsocksyssymbolic is only required by the iBCS-2/dev/x0rnullsymbolic only for the iBCS-2. [note]/dev/x0r is <letter X>-< number 0>-<Letter R>
Recommended links

We recommend that these connections exist on all systems:

Brief description of Link Target link types/dev/CORE/proc/kcoresymbolic for backward compatibility/dev/ramdiskram0symbolic for backward compatibility/dev/ftapeqft0symbolic for backward compatibility/dev/bttv0video0symbolic for backward compatibility/dev /radioradio0symbolic for backward compatibility with/dev/i2o */dev/i2o/* symbolic for backward compatibility with/dev/SCD? Sr? Hard replaces the name of the SCSI CD-ROM
Locally defined link

The following links may need to create some or even all of them based on the actual hardware configuration of the machine. These links are only intended to cater to usage, and they are neither necessary nor recommended.

 
Link Target link type brief description/dev/mousemouse portsymbolic current mouse/dev/tapetape devicesymbolic current tape/dev/cdromcd-Rom devicesymbolic current CD-ROM/dev/cdwritercd-writersymbolic current CD-writer/ dev/scannerscannersymbolic current scanner/dev/modemmodem portsymbolic current modem/dev/rootroot devicesymbolic current root file system device/dev/swapswap devicesymbolic current swap Device

/Dev/MODEM should not be used for modem that supports both incoming and outgoing calls, because it often causes file lock problems. If/dev/MODEM exists, it should point to an appropriate master tty device.

For SCSI devices,/dev/tape and/dev/CDROM should point to the "cooked" device/dev/St * And/dev/SR * respectively *; /dev/cdwriter and/dev/example should point to the appropriate/dev/SG * respectively *.

/Dev/mouse can point to a master serial tty device, a hardware mouse, or a socket corresponding to the mouse driver (for example,/dev/gpmdata ).

Sockets and Pipelines

Persistent sockets and named pipelines can exist in/dev. Common examples include:

 
/Dev/printersocketlpd local socket/dev/logsocketsyslog local socket/dev/gpmdatasocketgpm mouse multiplexing (Multiplexer)/dev/gpmctlsocket (appearing in LFS-livecd) /dev/initctlfifo pipeinit listens to it and obtains information from it (the channel through which the user interacts with the INIT process)
Mount point

The following names are retained for mounting a special file system. These special file systems only provide the kernel interface instead of standard device nodes.

 
/Dev/ptsdevptspty slave File System/dev/shmtmpfs provides direct access to POSIX shared memory
Terminal Devices

A terminal (or TTY) device is a special character device. A terminal device is any device that can assume the role of a control terminal in a session, including the virtual console, serial interface (obsolete), and Pseudo Terminal (Pty ).

All terminal devices share a set of common functions: Line discipline, which includes both general terminal line discipline and slip and PPP modes. The names of all terminal devices are similar. This part explains naming rules and various types of tty (terminal) usage. It should be noted that these naming conventions contain several historical burdens. Some of them are exclusive to Linux, others are inherited from other systems, and others reflect that Linux has abandoned the habits of borrowing from other systems during its growth. The pound sign (#) indicates a decimal number without leading zero in the device name.

Virtual console and console device)

The virtual console is a terminal that is displayed in full screen on the system video monitor. The virtual console is named/dev/tty # Starting from/dev/tty1 #. /Dev/tty0 is the current virtual console. /Dev/tty0 is used to access the system video card on a machine that cannot use the frame buffer device (/dev/FB *). Do not use/dev/console for this purpose. /Dev/console is managed by the kernel and system messages will be sent here. In single-user mode, login must be allowed to use/dev/console.

Serial Interface

The "Serial Interface" here refers to the RS-232 serial interface and any device simulating this interface, whether in hardware (such as a modem) or in software (such as ISDN driver) simulation. Each serial interface in Linux has two device names: the master device or the callin device, the alternate device, or the callout device. The device types are differentiated by uppercase and lowercase letters. For example, for any letter X, "tty" device name/dev/ttyx #, and "Cu" device name is/dev/cux #. For historical reasons,/dev/TTYs # And/dev/ttyc # are equivalent to/dev/CUA # And/dev/CUB # respectively #. The names/dev/ttyq # And/dev/cuq # are reserved for local use.

Pseudo Terminal (Pty)

Pseudo terminals are used to create login sessions or provide other functions, such as using tty line discipline (including slip or PPP) to process arbitrary data generation. Each Pty has a master and a slave. According to the Pty naming scheme of System V/unix98, all master nodes share the same/dev/ptmx device node (an unallocated Pty is automatically provided when the kernel is enabled ), all slave terminals are located in the/dev/PTS directory named/dev/pts/# (the kernel will automatically generate and delete them as needed ).

Once the master is enabled, the corresponding slave device can be used in the same way as the tty device. The master and slave devices are connected through the kernel, which is equivalent to two-way pipelines with tty functions (PIPE ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.