Major and Minor Devices

uunet!bria!mike uunet!bria!mike
Thu Feb 7 10:35:53 AEST 1991


In an article, ddsw1.MCS.COM!vijay (Vijay Gurbani) writes:
>  Could anybody explain what the major and minor devices are?

By way of introduction ...

Under UNIX, devices are "special" files that are two flavors, character-special
and block-special.  Character-special files are used for character-at-a-time
devices, such as terminals, modems, printers, etc.  Block-special files are
used when the driver buffers I/O on the device, such as disks.  Note
that in the case of disks, there are usually both character-special and
block-special files, which are used for different reasons.

Now, to answer the question ...

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.

Device drivers are linked in with the kernel (in most cases anyway; there are
some exceptions), and their major number is defined in the /usr/sys/master
file (or wherever the particular flavor of UNIX chooses to keep it; for
example, XENIX calls it /usr/sys/conf/xenixconf, but the principal is the 
same).

So, let's say that you have a tape device driver that is linked in
with the kernel, and the major device number is 15.

# 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.  In this case, a minor device number of 0 means "normal tape"
operation, and 4 means "no rewind on close" of the tape device.
Most devices' minor number is determined by which bits are turned on.
So, if the driver writer used bit 3 to turn on "no rewind", then a
binary 00000100 would be used, which is decimal 4.

Hope this rambling helped explain things a bit.
-- 
Michael Stefanik                       | Opinions stated are not even my own.
Systems Engineer, Briareus Corporation | UUCP: ...!uunet!bria!mike
-------------------------------------------------------------------------------
technoignorami (tek'no-ig'no-ram`i) a group of individuals that are constantly
found to be saying things like "Well, it works on my DOS machine ..."



More information about the Comp.unix.questions mailing list