Mknod-Make block or character special files
Mknod [Option]... name type [major minor]
Option is-M.
Name Customization
Type has B, c, and P
Master device number
Device No.
The master device number is defined by/usr/src/Linux/include/Linux/major. h. A doc device is defined as follows:
# Define igel_flash_major 62
Assume that there is a command mknod Doc B 62 0:
Here, Doc is the defined name, B refers to the block device, and 0 refers to the entire Doc. If 0 is changed to 1, 1 indicates the first partition of the doc. 2 is 2nd, and so on.
As for mknod console C 5 1, the meaning is similar:
The console is the device name.
C Indicates a character device.
5 is the identifier defined by the device in major. h.
1 is the first sub-Device
Mknod console C 5 1
The console is the name of the device file and can be retrieved by yourself.
C is a block device (B)
5. The master device number/dev/devices records the existing devices.
Find a useless one.
1 indicates the device number. If you want to attach a driver to two identical devices, the device number will be split. The device number starts from 0 and 1 indicates the second device number.
Device Files
For each hardware device, the system kernel has a device driver responsible for processing it. In UNIX, device files are used to represent hardware devices. Each device driver is abstracted as a device file. In this way, a consistent file interface is provided for applications, it facilitates communication between applications and operating systems.
Traditionally, all device files are stored in the/dev directory.
$ LS-L/dev/rfd0/dev/fd0
BRW-r ----- 9 root operator 2, 0 Nov 12 13:32/dev/fd0
CrW-r ----- 9 root operator 9, 0 Nov 12 13:32/dev/rfd0
In the above list, we can see the original file size. Now we will display two numbers separated by commas. This is two important serial numbers used by the system to indicate the device. The first is the major number, which indicates the serial number of the hardware driver used by the device in the system; the second is from the device number (minor number), which is used by the hardware driver to distinguish different devices and determine how to handle them. The master device number under FreeBSD is represented by 8 bits, while the device number is represented by 24 bits. In fact, the name of the device file is not important. What matters is the two device numbers. The operating system uses it to determine the hardware driver and communicate with the hardware driver.
1) disk and block Device Files
In UNIX, devices are divided into two types: Block devices and character devices. Block devices are mainly used for Random Access, and disks represent these devices, character devices are used for sequential access, such as tapes or terminal devices.
As mentioned in the previous chapter, disk devices are represented by the disk name, disk serial number, partition serial number, And FreeBSD subpartition serial number, for example, in wd0s1a, WD is the driver, followed by the device serial number. 0 indicates the first device of the driver, and UNIX is counted from 0, the partition number in the third part is S1. Note that this is the first partition, because S1 is arranged downward from 1, which is different from the general UNIX habit, this is because the concept of partition is a DOS concept, so the order corresponding to DOS is also used here, And the last a is the order of FreeBSD subpartitions, each basic UFS partition can have eight subpartitions. These eight partitions are used for different purposes as expected. For example, wd0s1a is used for the root file system and wd0s1b is used as the swap partition, wd0s1c indicates the entire hard disk partition wd0s1. Therefore, the fd0c can be used to access the entire floppy disk fd0, And the wcd0c can be used to access the entire Disc wcd0.
A traditional name, such as wd0a, can be used to represent a subpartition on the first UFS partition, such as wd0s1a. Generally, a hard disk has only one UFS partition, so you can use a traditional name to identify the disk partition.
When using the LS command list, the system uses C (character) to identify a character device file, and B (Block) to identify the block device file.
$ LS-L/dev/* wd0s1
CrW-r ----- 1 root operator 3, 131072 Oct 31 :59/dev/rwd0s1
BRW-r ----- 1 root operator 0, 131072 Oct 31 :59/dev/wd0s1
Although the hard disk device is a block device, it is used for random access. But it can also be accessed sequentially. This method is called raw method. To access the hard disk in RAW mode, you need a device file of the corresponding character type. The character type hard disk device of wd0s1 is rwd0s1, the first letter in the device name uses R to indicate sequential access to the hard disk in RAW mode.
Because the device file represents the entire device, you can use FreeBSD's standard command to directly operate the device file in RAW mode to directly access the hardware device. This method can be used to accomplish a lot of useful work, but it is also very dangerous. For example, misoperations on the hard disk device files may damage the data of the entire hard disk. Fortunately, most of the operations that directly access the device are to read the corresponding data, without the need to write data to the disk device.
When a device is unavailable, the corresponding device file cannot be accessed. Therefore, you can directly access the device file to determine whether the corresponding device is actually normal. For example, to determine whether the mouse on ttyd0 works properly when connected to the first serial port, run the "cat
Previous: usage of the NM command
Next article: usage of the SED command