DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
HDK Technical Reference

Major and minor numbers

Major and minor numbers are associated with the device special files in the /dev directory and are used by the operating system to determine the actual driver and device to be accessed by the user-level request for the special device file.

In DDI versions before version 8, SCO OpenServer 5, and most other UNIX operating systems, the major and minor numbers can be defined in and accessed by the device driver. Beginning with DDI 8, device drivers use the device instance returned by the CFG_ADD subfunction of the config(D2) entry point routine in lieu of the major number, and the channel number and resource manager key in lieu of the minor number to select subcomponents and/or operating modes of this device instance.

Major and minor numbers for DDI 8 drivers are dynamic and are recreated in the .io/bootdisk directory every time the system boots. The root filesystem is mounted read-only at the time these are created during system boot, so the boot process creates the /.io memfs and writes the nodes there. Devices such as /dev/boot and /dev/swap in vstab are symbolic links to .io, and these are the handles the system uses as it boots. ODM interacts with this process through an entry point that is only defined when ODM is installed. The kernel invokes this entry point during the boot process and any value it writes overrides the kernel's value for these devices.

The information about major and minor numbers is provided here in support of DDI drivers for versions prior to version 8 and for SCO OpenServer 5 ODDI drivers.

The major and minor device numbers are related to one another as illustrated in ``Major and minor numbers''. A given software driver can be working with one or more hardware controllers, each of which has its own major number. Each device connected to a given controller then would have its own minor number. Thus, any single device can be identified through the major/minor number combination.

Major and minor numbers

Major numbers

For ODDI and pre-DDI 8 drivers, the major number identifies the device class or group, such as a controller for several terminals. It is used, for example, to tell the kernel which device driver's open routine to call. The major number is assigned, sequentially, to each device driver by the Installable Driver Tools (idtools) during driver installation. Assignment is made by creating an entry in the Master(DSP/4dsp) file (or mdevice(F) file for SCO OpenServer 5).

Character major numbers and block major numbers are assigned separately for devices that are exclusively block or character. This means that two separate special files for two different device drivers may appear to have the same number assigned to them. A device that supports both block and character access (for example, the floppy driver), may have different major numbers for the character and block device files.

Minor numbers

For ODDI and pre-DDI 8 drivers, the minor number identifies a specific device, such as a single terminal. Minor numbers are assigned to special files by the driver writer in another system configuration file called the Node file (see the Node(DSP/4dsp) manual page).

Minor numbers are typically used to distinguish subdevices, but they can also be used to convey other information. For example, consider a floppy disk controller that can read and write data from floppies in several formats, and can also manage two floppy drives. When a special file associated with the floppy driver is opened, the minor number associated with the file, and available to the open( ) routine as one of its arguments, is used to identify to the floppy driver both which drive to access, and what format to assume for the I/O operation. In this particular case, the least significant bit of the minor number could be used to identify the drive, and the remaining bits used to indicate the format.

Using DDI major and minor numbers

DDI drivers use the following functions to access and manipulate major and minor numbers:


etoimajor(D3)
Return internal major number that corresponds to the specified external major number.

getemajor(D3)
Return external major number.

geteminor(D3)
Return external minor number.

getmajor(D3)
Return internal major device.

getminor(D3)
Return internal minor device.

itoimajor(D3)
Return external major number that corresponds to the specified internal major number.

makedevice(D3)
Create a new device number from the specified major and minor numbers.

Using ODDI major and minor numbers

ODDI drivers use the following macros to access and manipulate major and minor numbers:


emajor(D3oddi)
Return the real (external) major number.

eminor(D3oddi)
Return the real (external) minor number

major(D3oddi)
Return the base major number.

minor(D3oddi)
Return the extended minor device number.

makedev(D3oddi)
Create a new device number from the specified base major number and extended minor number.

In utility programs outside the kernel, major( ) and minor( ) are identical to emajor( ) and eminor( ).


© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005