Major and Minor Numbers
Char devices are accessed through names (or ``nodes'') in the
filesystem, usually located in the /dev directory. Device
files are special files and are identified by a ``c'' in the first
column of the output of ls -l, indicating that
they are char nodes. Block devices appear in /dev as well, but
they are identified by a ``b''; even if some of the following information
applies also to block devices, I am now focusing on char drivers.
If you issue the ls command, you’ll see two numbers (separated by a comma) on the device file entries before the date of last modification, where the file length normally appears. These numbers are the “major” and “minor” numbers for the particular device. The following listing shows a few devices as they appear on my system. Their major numbers are 10, 1, and 4, while the minors are 0, 3, 5, 64-65, and 128-129.
crw-rw-rw- 1 root root 10, 3 Nov 30 1993 bmouseatixl crw-rw-rw- 1 root sys 1, 3 Nov 30 1993 null crw-rw-rw- 1 root root 4, 128 Apr 30 13:02 ptyp0 crw-rw-rw- 1 root root 4, 129 Apr 30 13:02 ptyp1 crw-rw-rw- 1 rubini staff 4, 0 Jan 30 1995 tty0 crw-rw-rw- 1 root tty 4, 64 Jan 25 1995 ttyS0 crw-rw-rw- 1 root root 4, 65 May 1 00:04 ttyS1 crw-rw-rw- 1 root sys 1, 5 Nov 30 1993 zero
The major number identifies the driver associated
with the device. For example, /dev/null and
/dev/zero are both managed by driver 1, while all the tty’s and pty’s are managed by driver 4. The kernel uses the major number to associate the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access