What Are Major and Minor Numbers?

As stated, device files have an 8 bit major and minor number. This means they can each range from 0 to 255. People loosely say that the major number identifies what kind of device we're talking about. A more accurate statement would be that the major number tells the kernel which driver to use when a particular device file is used. By the way, block and char major numbers are completely separate, in much the same way that tcp and udp port numbers are completely separate.

In our example above, hda1 is block major 3 while ttyS3 is char major 4. The minor number comes after the major numbers (hda1 is minor 1 and ttyS3 is minor number 67). So if you access a device file with block major number 3, the kernel knows that it needs to use the IDE hard drive number. If you access the device file with char major 4, the kernel knows it needs to use the TTY device driver (which handles virtual consoles and serial ports!).

The minor number isn't used by the kernel. It's used by the device driver. As previously stated, the virtual consoles and serial ports are both handled by the same driver, the "TTY driver". Suppose you try accessing a serial port device file. There are two questions which seem natural to ask. If the major number only identifies the which driver to use for the device file

  1. how does the kernel know which serial port your're trying to use?
  2. how does the kernel know that you want the serial port, not a console?

The answer to both questions is: "it doesn't". To the kernel, an access to the virtual console is the same as an access to a serial port. It's up to the TTY driver to know what you mean. The driver knows what particular hardware you want by the minor number. So in summary:

This should all imply that major numbers must be assigned by some authority, to avoid major number clashing between hardware. In fact, Peter Anvin <device@lanana.org> (the guy who wrote the SYSLINUX boot loader) maintains a list of assigned major/minor numbers. You can find this list in /usr/src/linux/Documentation/device.txt.