Major and Minor Devices

Guy Harris guy at auspex.auspex.com
Fri Feb 8 06:44:16 AEST 1991


>Each device file has a device number, which is broken down into a major device
>and minor device number.  Simply put, the major device number lets the kernel
>know which device you are talking about; the minor device number is used by
>the device driver itself, with different minor numbers telling the driver
>to behave in different ways.

A little *too* simply put, I'd say.  The major device number mainly
indicates what *type* of device; one thing the minor device number is
used for, although not the only thing, is to indicate which particular
device of that type is being referred to.  I.e.:

># ls -l /dev/rmt0*
>crw-rw-rw-   1 root     system    15,  0 Feb  6 00:14 /dev/rmt0
>crw-rw-rw-   1 root     system    15,  4 Aug  3 1990  /dev/rmt0.4
>
>This would show that /dev/rmt0 and /dev/rmt0.4 both refer to the same
>device, because the major device number for both character-special files
>is 15.

Well:

	alpha1% ls -l /dev/rast[012]
	crw-rw-rw-  1 root      87,   0 Jan 14 12:19 /dev/rast0
	crw-rw-rw-  1 root      87,   1 Jan 10 08:23 /dev/rast1
	crw-rw-rw-  1 root      87,   2 Jan 15 09:04 /dev/rast2

They all have the same major device number, but they aren't the same
device; they're three different tape drives.  The lower 2 bits of the
minor device number, on that particular system, specify the unit number.
The next bit up indicates the "normal" vs. "no rewind on close" flag:

	alpha1% ls -l /dev/*rast0
	crw-rw-rw-  1 root      87,   4 Feb  2 00:30 /dev/nrast0
	crw-rw-rw-  1 root      87,   0 Jan 14 12:19 /dev/rast0

(Also, for assorted reasons, the flavor of UNIX running on that
particular system also uses part of the *major* device number to
indicate which unit is being referred to; that's actually not strictly
necessary for tapes, but it *is* for disks, since:

	you can hang up to 60 disks on those machines;

	each disk can have up to 8 partitions, and each partition is a
	separate device with its own minor device;

	minor device numbers in that OS, as in most versions of UNIX,
	are 8 bits long.

That sort of thing is relatively rare, and may get rarer as systems go
to larger minor device numbers; minor device numbers are longer than 8
bits in most if not all System V Release 4 systems, for example.)



More information about the Comp.unix.questions mailing list