## Introduction
command mknod, which generates a block device file or thecharacter device (computing)file in the format:
mknod [OPTION] NAME TYPE [MAJOR MINOR]
OPTION is the option, the more useful one is -m, which indicates the permissions of the generated device file;
NAME is the name of the generated device
TYPE is the device type, b for block devices, c for character devices, p for pipes
MAJOR is the primary device number, MINOR is the secondary device number, and the primary device number is defined by the file /usr/include/linux/defined. The extracted code snippet is as follows:
#ifndef _LINUX_MAJOR_H
#define _LINUX_MAJOR_H
/*
* This file has definitions for major device numbers.
* For the device number assignments, see Documentation/.
*/
#define UNNAMED_MAJOR 0
#define MEM_MAJOR 1
#define RAMDISK_MAJOR 1
#define FLOPPY_MAJOR 2
#define PTY_MASTER_MAJOR 2
#define IDE0_MAJOR 3
#define HD_MAJOR IDE0_MAJOR
#define PTY_SLAVE_MAJOR 3
#define TTY_MAJOR 4
#define TTYAUX_MAJOR 5
#define LP_MAJOR 6
#define VCS_MAJOR 7
#define LOOP_MAJOR 7
#define SCSI_DISK0_MAJOR 8
#define SCSI_TAPE_MAJOR 9
#define MD_MAJOR 9
#define MISC_MAJOR 10
#define SCSI_CDROM_MAJOR 11
#define MUX_MAJOR 11 /* PA-RISC only */
#define XT_DISK_MAJOR 13
#define INPUT_MAJOR 13
#define SOUND_MAJOR 14
#define CDU31A_CDROM_MAJOR 15
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
(for) instance
mknod -m 0660 /dev/loop2 b 7 2
- 1
Indicates the creation of a loop device, -m sets the permissions of the device file, according to the definition of the file, the primary device number of the loop device is 7, this device number is customized to 2.
Equipment documentation
For each hardware device, the system kernel has a corresponding device driver responsible for handling it. In Linux, a device file is used to represent a hardware device, and each device driver is abstracted as a device file, which gives applications a consistent file interface and facilitates communication between applications and the operating system.
Generally all device files are placed in the /dev directory:
[jamza@A23488809 base]$ ls -l /dev
total usage 0
crw------- 1 root root root 10, 235 1moon 29 15:12 autofs
drwxr-xr-x 2 root root 280 3moon 23 11:07 block
drwxr-xr-x 2 root root 60 1moon 29 15:12 bsg
crw------- 1 root root root 10, 234 1moon 29 15:12 btrfs-control
drwxr-xr-x 3 root root 60 1moon 29 15:12 bus
drwxr-xr-x 2 root root 3360 1moon 29 17:02 char
crw------- 1 root root root 5, 1moon 29 15:12 console
lrwxrwxrwxrwx 1 root root root 11 1moon 29 15:12 core -> /proc/kcore
drwxr-xr-x 10 root root 220 1moon 29 15:12 cpu
crw------- 1 root root root 10, 61 1moon 29 15:12 cpu_dma_latency
crw------- 1 root root 10, 62 1moon 29 15:12 crash
drwxr-xr-x 5 root root root 100 1moon 29 15:12 disk
brw-rw---- 1 root disk 253, 0 1moon 29 15:12 dm-0
brw-rw---- 1 root disk 253, 1 1moon 29 15:12 dm-1
brw-rw---- 1 root disk 253, 2 1moon 29 15:12 dm-2
brw-rw---- 1 root disk 253, 3 1moon 29 15:45 dm-3
brw-rw---- 1 root disk 253, 4 3moon 9 09:15 dm-4
drwxr-xr-x 2 root disk 80 1moon 29 15:12 dri
crw-rw---- 1 root video 29, 0 1moon 29 15:12 fb0
lrwxrwxrwx 1 root root root 13 1moon 29 15:12 fd -> /proc/self/fd
crw-rw-rw- 1 root root root 1, 7 1moon 29 15:12 full
crw-rw-rw- 1 root root root 10, 229 1moon 29 15:12 fuse
crw------- 1 root root root 10, 228 1moon 29 15:12 hpet
drwxr-xr-x 3 root root 0 1moon 29 16:31 hugepages
crw------- 1 root root 10, 183 1moon 29 15:12 hwrng
lrwxrwxrwx 1 root root root 25 1moon 29 15:12 initctl -> /run/systemd/initctl/fifo
drwxr-xr-x 3 root root 280 January 29 15:12 input
crw-rw-rw- 1 root root 1, 11 January 29 15:12 kmsg
crw-rw-rw- 1 root kvm 10, 232 March 23 11:00 kvm
srw-rw-rw- 1 root root 0 January 29 15:12 log
brw-rw---- 1 root disk 7, 0 January 29 15:45 loop0
brw-rw---- 1 root disk 7, 1 January 29 15:45 loop1
brw-rw---- 1 root root 7, 4 March 23 10:25 loop4
brw-rw---- 1 root root 7, 5 March 23 10:25 loop5
......
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
As you can see from the above output list, each device file's original location where the file size was displayed is now displayed using two comma-separated numbers, which represent the master and slave device numbers.
The master device number is used to indicate the serial number in the system of the hardware driver used by the device.
The device number is used by hardware drivers to distinguish between different devices and to determine how device operations are handled.
In fact, the name of the device file is not the most important thing; what is important is the master and slave device numbers, which are used by the operating system to identify and communicate with the hardware driver.