device number 1
Some notes on linux device files.
REF:
- Linux Device Drivers
- This is article by Jyoti Singh
This is (part of) the result of ls -l
on a normal directory.
drwxr-xr-x 2 shrik3 shrik3 4096 Jul 12 18:59 Desktop
drwx------ 3 shrik3 shrik3 4096 Jul 8 14:44 Downloads
drwxr-xr-x 8 shrik3 shrik3 4096 Jun 28 09:59 docs
-rw-r--r-- 1 shrik3 shrik3 2821 Jun 30 21:11 notes
drwxr-xr-x 4 shrik3 shrik3 4096 Jul 2 23:30 scripts
drwxr-xr-x 16 shrik3 shrik3 4096 Jul 2 23:24 temp
drwxr-xr-x 7 shrik3 shrik3 4096 Jul 2 18:19 utils
This is (part of) the result of ls -l /dev
crw------- 1 root root 108, 0 Jul 12 16:08 ppp
crw------- 1 root root 10, 1 Jul 12 16:08 psaux
crw-rw-rw- 1 root tty 5, 2 Jul 12 20:16 ptmx
crw-rw-rw- 1 root root 1, 8 Jul 12 16:08 random
crw-rw-r-- 1 root rfkill 10, 242 Jul 12 16:08 rfkill
lrwxrwxrwx 1 root root 4 Jul 12 16:08 rtc -> rtc0
crw------- 1 root root 249, 0 Jul 12 16:08 rtc0
brw-rw---- 1 root disk 8, 0 Jul 12 16:08 sda
brw-rw---- 1 root disk 8, 1 Jul 12 16:08 sda1
brw-rw---- 1 root disk 8, 10 Jul 12 16:08 sda10
brw-rw---- 1 root disk 8, 2 Jul 12 16:08 sda2
brw-rw---- 1 root disk 8, 3 Jul 12 16:08 sda3
brw-rw---- 1 root disk 8, 4 Jul 12 16:08 sda4
brw-rw---- 1 root disk 8, 5 Jul 12 16:08 sda5
brw-rw---- 1 root disk 8, 6 Jul 12 16:08 sda6
brw-rw---- 1 root disk 8, 7 Jul 12 16:08 sda7
brw-rw---- 1 root disk 8, 8 Jul 12 16:08 sda8
crw--w---- 1 root tty 4, 2 Jul 12 16:08 tty2
crw--w---- 1 root tty 4, 20 Jul 12 16:08 tty20
crw--w---- 1 root tty 4, 21 Jul 12 16:08 tty21
crw--w---- 1 root tty 4, 57 Jul 12 16:08 tty57
crw--w---- 1 root tty 4, 8 Jul 12 16:08 tty8
crw--w---- 1 root tty 4, 9 Jul 12 16:08 tty9
The first character of each line flags the device type, they are:
Flag | Type |
---|---|
b | Block device |
c | Char device |
p | Pipe |
d | Directory |
l | Soft link |
For Char and Block devices, in the 5th column, there are 2 numbers separated by a comma. They are called Major and minor numbers of the device, which “replace” the SIZE column for regular nodes.
# WHAT IS MAJOR & MINOR NUMBERS:
Traditionally, the major number identifies the driver associated with the device. For example, /dev/null and /dev/zero are both managed by driver 1, whereas virtual consoles and serial terminals are managerd by driver 4; similarly, both vcs1 and vcsa1 devides are managed by driver 7. Modern Linux kernels allow multiple drivers to share major numbers, but most devices that you will see are still organized on the one-major-one-driver principle.
The major number is an offset to the kernel’s drivers table.
The minor number is used by the kernel to determine exactly which device is being referred to. Well the kernel doesn’t acturlly care about the minor number. The minor number is used by the driver to identify instances of devices.