In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to describe the device nodes in linux, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
When I saw it on the Internet, I excerpted it when I thought it was practical.
There are two types of devices in Linux:
Character devices (unbuffered and can only be accessed sequentially), block devices (buffered and randomly accessible).
Each character device and block device must have primary and secondary device numbers, and devices with the same primary number are similar devices (using the same driver). Some of these devices are abstractions of actual physical hardware, while others are functions provided by the kernel itself (independent of specific physical hardware, also known as "virtual devices"). Each device has a corresponding file (node) in the / dev directory. You can view the major number of the currently loaded device driver through the cat / proc/devices command. All devices that the kernel can recognize are recorded in the Documentation/devices.txt file under the source tree.
In the / dev directory, in addition to character devices and block device nodes, there are usually FIFO pipes, Socket, soft / hard connections, directories. These things do not have a primary / secondary device number.
The most basic requirement to understand these devices is to know the meaning of each device file like the back of your hand. The following list lists common device files and their corresponding meanings (omitted from the more remote ones):
Primary device number device type
Secondary number = brief description of file name
0 unnamed devices (for example, mounted non-devices)
0 = not empty device number reserved
1 char memory device
1 = / dev/mem direct access to physical memory
2 = / dev/kmem accesses memory after kernel virtualization
3 = / dev/null empty device. Any writes will be discarded directly, and any reads will get EOF.
4 = / dev/port access to the Ibank O port
5 = / dev/zero zero-byte source, which can only read an infinite number of zero bytes.
7 = / dev/full full device. Any writes will fail and set errno to ENOSPC to indicate that there is no space left.
8 = / dev/random random number generator. Random numbers are generated entirely from the user's input.
If the user stops all actions, stop generating new random numbers.
9 = / dev/urandom is a faster but less secure random number generator. Generate random numbers from the user's input as much as possible
If the user stops all actions, the random number already generated is used as a seed to generate a new random number.
10 = / dev/aio Asynchronous IBO Notification Interface
11 = / dev/kmsg any writes to the file will be output as printk
1 block RAM disk
0 = / dev/ram0 1st RAM disk (initrd can only use ram0)
1 = / dev/ram1 2nd RAM disk
...
200 = / dev/ram200 200th RAM disk
4 char TTY (terminal) equipment
0 = / dev/tty0 current virtual console
1 = / dev/tty1 1st virtual console
...
63 = / dev/tty63 63rd virtual console
4 block if the root file system is mounted read-only, it is not possible to create a real device node
The device is now used as an alias for the dynamically assigned primary (major) device
0 = / dev/root
5 char other TTY Devic
0 = / dev/tty current TTY device
1 = / dev/console system console
2 = / dev/ptmx Multiplexer for all PTY master
7 char virtual console capture devices (these devices allow both reading and writing)
0 = / text content of the current virtual console (vc) of dev/vcs
1 = text content of / dev/vcs1 tty1
...
63 = text content of / dev/vcs63 tty63
/ dev/vcsa text / attribute content of the current virtual console (vc)
129text / attribute content of / dev/vcsa1 tty1
...
Text / attribute content of / dev/vcsa63 tty63
7 block loopback device (uses a normal disk file to simulate a block device)
Binding to loopback devices is handled by mount (8) or losetup (8)
0 = / dev/loop0 first loopback device
1 = / dev/loop1 2nd loopback device
...
8 block SCSI disks (0-15)
0 = / dev/sda 1st SCSI disk (entire disk)
16 = / dev/sdb 2nd SCSI disk (entire disk)
32 = / dev/sdc 3rd SCSI disk (entire disk)
...
240C / dev/sdp 16th SCSI disk (entire disk)
The partition representation is as follows (take the third SCSI disk as an example)
33 = / dev/sdc1 1st partition
34 = / dev/sdc2 2nd partition
...
47 = / dev/sdc15 15th partition
For Linux/i386, partitions 1-4 are primary partitions and 5-15 are logical partitions.
9 block Metadisk (RAID) equipment
0 = / dev/md0 Group 1 metadisk
1 = / dev/md1 Group 2 metadisk
...
The metadisk driver is used to split the same file system into multiple physical disks.
10 char non-serial mouse, various miscellaneous devices and features
1 = / dev/psaux PS/2 mouse
131C / dev/temperature machine internal temperature
/ dev/apm_bios APM (Advanced Power Management) BIOS
135 = / dev/rtc Real time clock (Real Time Clock)
144 = / dev/nvram non-volatile configuration RAM
/ dev/smbus system Management bus (System Management Bus)
164Intelligent platform Management (Intelligent Platform Management) interface for dev/ipmo Intel
/ dev/ipmikcs Intelligent platform Management (Intelligent Platform Management) interface
/ dev/agpgart AGP graphic address remap table (Graphics Address Remapping Table)
182 = / dev/perfctr performance monitoring counter
/ dev/hwrng universal hardware random number generator
/ dev/cpu/microcode CPU microcode update interface
186 = / Atomic snapshot of dev/atomicps process state data
188 = / dev/smbusbios SMBus (system Management bus) BIOS
200 = / dev/net/tun TAP/TUN network devices (TAP/TUN implements network devices in a software way)
TAP simulates Ethernet frames (layer 2) and TUN simulates IP packets (layer 3).
/ dev/emd/ctl enhanced Metadisk RAID (EMD) controller
220 = / dev/mptctl Message passing technology (MPT) control
223 = / dev/input/uinput user layer input device driver support
227 = / dev/mcelog X861664 Machine Check Exception driver
228 = / dev/hpet HPET driver
229 = / dev/fuse Fuse (virtual file system in user space)
231 = / dev/snapshot system memory snapshot
/ dev/kvm kernel-based virtual machine (based on AMD SVM and Intel VT hardware virtual technology)
11 block SCSI CD-ROM Devic
0 = / dev/scd0 1st SCSI CD-ROM
1 = / dev/scd1 2nd SCSI CD-ROM
...
13 char core input device
32 = / dev/input/mouse0 1st mouse
33 = / dev/input/mouse1 2nd mouse
...
62 = / dev/input/mouse30 31st mouse
63 = / dev/input/mice Unification of all Mouse
64 = / dev/input/event0 1st event queue
65 = / dev/input/event1 2nd event queue
...
95 = / dev/input/event1 32nd event queue
21 char general purpose SCSI device (usually SCSI optical drive)
0 = / dev/sg0 1st generic SCSI device
1 = / dev/sg1 2nd generic SCSI device
...
29 char Universal frame buffer (frame buffer) device
0 = / dev/fb0 1st frame buffer device
1 = / dev/fb1 2nd frame buffer device
...
31 = / dev/fb31 32nd frame buffer device
30 char iBCS-2 compatible devices
0 = / dev/socksys socket provider
1 = / dev/spx SVR3 local X interface
32 = / dev/inet/ip network 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, iBCS-2 requires that the following connections must exist
/ dev/ip-> / dev/inet/ip
/ dev/icmp-> / dev/inet/icmp
/ dev/ggp-> / dev/inet/ggp
/ dev/ipip-> / dev/inet/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 char Netlink support
0 = / dev/route routing, device updates, kernel to user
3 = / dev/fwmonitor Firewall packet replication
59 char sf Firewall Modul
0 = / dev/firewall communicates with sf kernel module
65 block SCSI disks (16-31)
0 = / dev/sdq 17th SCSI disk (entire disk)
16 = / dev/sdr 18th SCSI disk (entire disk)
32 = / dev/sds 19th SCSI disk (entire disk)
...
240th / dev/sdaf 32nd SCSI disk (entire disk)
66 block SCSI disks (32-47)
0 = / dev/sdag 33rd SCSI disk (entire disk)
16 = / dev/sdah 34th SCSI disk (entire disk)
32 = / dev/sdai 35th SCSI disk (entire disk)
...
240th / dev/sdav 48th SCSI disk (entire disk)
89 char I2C bus interface
0 = / dev/i2c-0 1st I2C adapter
1 = / dev/i2c-1 2nd I2C adapter
...
Virtual block devices in 98 block user mode (partitioned in the same way as SCSI disks)
0 = / dev/ubda 1st user mode block device
16 = / dev/udbb 2nd user mode block device
...
103 block Audit (Audit) equipment
0 = / dev/audit audit (Audit) device
128135 char Unix98 PTY master
These devices should not exist in the device node, but should be accessed through the / dev/ptmx interface.
136143 char Unix98 PTY slave
These device nodes are automatically generated (with appropriate permissions and modes) and cannot be created manually.
The method is by using the appropriate mount option (usually: mode=0620,gid=)
Mount the devpts file system to the / dev/pts directory.
0 = / dev/pts/0 1st Unix98 PTY slave
1 = / dev/pts/1 2nd Unix98 PTY slave
...
153 block Enhanced Metadisk RAID (EMD) storage unit (partitioned in the same way as SCSI disks)
0 = / dev/emd/0 first storage unit
1 = / dev/emd/0p1 first partition of the first storage unit
2 = / dev/emd/0p2 the second partition of the first storage unit
...
15 = / 15th partition of the first storage unit of dev/emd/0p15
16 = / dev/emd/1 2nd storage unit
32 = / dev/emd/2 3rd storage unit
...
240C / dev/emd/15 16th storage unit
180 char USB character device
96 = / dev/usb/hiddev0 the first USB man-machine interface device (mouse / keyboard / joystick / handwritten version, etc.)
...
/ dev/usb/hiddev15 16th USB human-machine interface device
180 block USB block devices (USB disk, etc.)
0 = / dev/uba 1st USB block device
8 = / dev/ubb 2nd USB block device
16 = / dev/ubc 3rd USB block device
...
192 char kernel profiling interface
0 = / dev/profile Profiling control device
Profiling device for 1 = / dev/profile0 CPU 0
Profiling device for 2 = / dev/profile1 CPU 1
...
193 char kernel event tracking interface
0 = / dev/trace tracking control device
Tracking device for 1 = / dev/trace0 CPU 0
Tracking device for 2 = / dev/trace1 CPU 1
...
195 char Nvidia graphics devices (such as graphics cards)
0 = / dev/nvidia0 1st Nvidia card
1 = / dev/nvidia1 2nd Nvidia card
...
/ dev/nvidiactl Nvidia card control device
202 char registers specific to CPU mode (model-specific register,MSR)
0 = / MSRs of dev/cpu/0/msr CPU 0
1 = / MSRs of dev/cpu/1/msr CPU 1
...
203 char CPU CPUID information
0 = / CPUID of dev/cpu/0/cpuid CPU 0
1 = / CPUID of dev/cpu/1/cpuid CPU 1
...
=
This section details some files that should or may exist outside the / dev directory.
It is best to use exactly the same format as here (absolute path or relative path).
Whether to use hard link (hard) or soft connection (symbolic) depends on different devices.
Required links
These connections must exist on all systems:
Brief description of link destination link type
/ dev/fd / proc/self/fd symbolic file description
/ dev/stdin fd/0 symbolic standard input file description
/ dev/stdout fd/1 symbolic standard output file descriptor
/ dev/stderr fd/2 symbolic standard error file descriptor
/ dev/nfsd socksys symbolic is only required for iBCS-2
/ dev/X0R null symbolic is only required for iBCS-2
[note] / dev/X0R is--
Recommended links
It is recommended that these connections exist on all systems:
Brief description of link destination link type
/ dev/core / proc/kcore symbolic for backward compatibility
/ dev/ramdisk ram0 symbolic for backward compatibility
/ dev/ftape qft0 symbolic for backward compatibility
/ dev/bttv0 video0 symbolic for backward compatibility
/ dev/radio radio0 symbolic for backward compatibility
/ dev/i2o* / dev/i2o/* symbolic for backward compatibility
/ dev/scd? Sr? Hard replaces the name of SCSI CD-ROM
Locally defined links
The links below are likely to create some or all of them based on the actual hardware configuration of the machine.
These links are only intended to cater to idioms, and they are neither necessary nor recommended.
Brief description of link destination link type
/ dev/mouse mouse port symbolic current mouse
/ dev/tape tape device symbolic current tape
/ dev/cdrom CD-ROM device symbolic current CD-ROM
/ dev/cdwriter CD-writer symbolic current CD-writer
/ dev/scanner scanner symbolic current scanner
/ dev/modem modem port symbolic current modem
/ dev/root root device symbolic the device where the current root file system resides
/ dev/swap swap device symbolic the device where the current swap resides
/ dev/modem should not be used for modem that can support both inbound and outbound calls, as it often leads to file lock problems.
If / dev/modem exists, it should point to an appropriate primary TTY device.
For SCSI Devic
/ dev/tape and / dev/cdrom should point to "cooked" devices / dev/st* and / dev/sr*, respectively
And / dev/cdwriter and / dev/scanner should point to the appropriate / dev/sg*, respectively.
/ dev/mouse can point to a main serial TTY device, a hardware mouse,
Or a socket corresponding to the mouse driver (for example, / dev/gpmdata).
Sockets and pipes
Persistent sockets and named pipes can exist in / dev. Common ones are:
/ dev/printer socket lpd local socket
/ dev/log socket syslog local socket
/ dev/gpmdata socket gpm mouse multiplexer (multiplexer)
/ dev/gpmctl socket (appears in LFS-LiveCD)
/ dev/initctl fifo pipe init listens to it and gets information from it (the channel through which users interact with the init process)
Mounting point
The following names are reserved for mounting special file systems.
These special file systems provide only the kernel interface and not standard device nodes.
/ dev/pts devpts PTY slave file system
/ dev/shm tmpfs provides direct access to POSIX shared memory
=
Terminal (or TTY) device is a special character device. An end device is any device that can play the role of a control terminal in a session
Including: virtual console, serial interface (obsolete), pseudo terminal (PTY).
All end devices share a common set of functions: line discipline
It contains both general terminal line discipline as well as SLIP and PPP modes.
The names of all end devices are similar. This section explains naming conventions and the use of various types of TTY (terminals).
It should be noted that these naming habits contain several historical baggage.
Some of them are unique to Linux, while others are inherited from other systems.
Others reflect that Linux abandoned some of the habits that it borrowed from other systems when it was growing up.
The pound sign (#) represents a decimal number without leading zeros in the device name.
Virtual console (Virtual console) and console device (console device)
The virtual console is a terminal that displays full screen on the system video monitor.
The virtual console is named / dev/tty# with the number starting with / dev/tty1.
/ dev/tty0 is the current virtual console.
/ dev/tty0 is used to access system video cards on machines that cannot use frame buffers (/ dev/fb*)
Be careful not to use / dev/console for this purpose.
/ dev/console is managed by the kernel, and system messages will be sent here.
Login must be allowed to use / dev/console in single-user mode.
Serial interface (obsolete)
By "serial interface" I mean the RS-232 serial interface and any device that simulates it.
Whether it is simulated in hardware (such as a modem) or in software (such as an ISDN driver).
Each serial interface in linux has two device names:
Main device or inbound (callin) device, alternating device, or outbound (callout) device.
Use the case of letters to distinguish between device types.
For example, for any letter X, the "tty" device name is / dev/ttyX# and the "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.
For example, arbitrary data generation is handled through TTY line discipline (including SLIP or PPP functions).
Each PTY has a master terminal and a slave terminal. According to System V/Unix98 's PTY naming scheme
All master sides share the same / dev/ptmx device node (turn it on and the kernel will automatically give you an unassigned PTY)
All slave sides are located in the / dev/pts directory, called / dev/pts/# (the kernel automatically generates and deletes them as needed).
Once the master side is opened, the corresponding slave device can be used in exactly the same way as the TTY device.
The connection between master devices and slave devices through the kernel is equivalent to a two-way pipeline (pipe) with TTY function.
= =
You may wonder why there is no device like / dev/hda, isn't it common?
The reason is that since 2.6.19, the kernel has introduced a new ATA driver, and the SATA/IDE hard disk has been agreed to use / dev/sd? To express, so / dev/hd? There's no need to exist.
= about sound card equipment =
Alsa is a late audio processing library in LINUX, which is mainly improved on the original OSS library. Better performance, support for multiple sources and so on. But correspondingly, the complexity of programming increases.
The old oss adopts the standard file IO interface, the device opens with open, the sound recording uses the data IO interface (read/write), and the parameters of the equipment are controlled by ioctl. All are system calls, so there is no need for additional libraries and configuration files to operate the device. But alsa also finally adopts open/read/write/ioctl, but there are more operation nodes. It's more complicated. Therefore, additional libraries are used to operate in programming.
[Linux ALSA driver Test]
Here are the results of my test of ALSA on debian 9, similar to that on ARM or MIPS development boards
If you install ALSA, you will see the appropriate device at / proc:
Use cat / proc/asound/devices
Root@debian:/lib# cat / proc/asound/devices
2: [0]: control
0-0: digital audio playback
0-0: digital audio capture
0-2: digital audio capture
0-3: digital audio playback
0-7: digital audio playback
0-8: digital audio playback
0-0: hardware dependent
0-2: hardware dependent
33:: timer
Normally, you will see the following device node in your / dev/snd (with an exception, the kernel driver has adjusted the node position)
Use ls-l / dev/snd
[root@hxy alsa-lib-1.0.22] # ls-l / dev/snd
Total 0
Crw- 1 root root 116, 8 Mar 2 02:41 controlC0
Crw- 1 root root 116, 4 Mar 2 02:41 midiC0D0
Crw- 1 root root 116, 7 Mar 2 02:41 pcmC0D0c
Crw- 1 root root 116, 6 Mar 2 02:41 pcmC0D0p
Crw- 1 root root 116, 5 Mar 2 02:41 pcmC0D1p
Crw- 1 root root 116, 3 Mar 2 02:41 seq
Crw- 1 root root 116, 2 Mar 2 02:41 timer
Usually the desktop version has already installed alsa-utils. You can execute aplay-h to test the output. If you can broadcast the wav file to test whether the whole environment is working properly.
Here are some examples of testing with alsa-utils
Play the wave file
Aplay / mnt/nfs/test.wav
Frequency conversion playback, (so play audio at 44 KHz)
Aplay-r 44000 / mnt/nfs/test.wav # test, the frequency has not changed
Recording, recording Wave format audio at 20 second intervals (- d 20), stereo (- c 2) at 8000Hz frequency
Arecord-d 20-c 2-t wav-r 8000-f "Signed 16 bit Little Endian" / mnt/nfs/test.wav
Test mix playback (first play test1.wav, then play test2.wav at the same time)
Aplay-D plug:dmix_44k / mnt/nfs/test1.wav &
Aplay-D plug:dmix_44k / mnt/nfs/test2.wav
Set playback gain (0 to 3)
Amixer set Master 1
Set recording volume (0-31)
Amixer set Line 10
The above is how the device nodes in linux describe, have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.