STREAMS-UX Programmer's Guide (February 2007)
Modules and Drivers
STREAMS Driver
Chapter 4
97
A device is then accessed by opening, reading, writing or closing the special device file associated with the
device with proper major and minor numbers. The following example lists such special device files:
$ ls -l /dev/udp*
crw-rw-rw- 1 root root 72 0x000033 Dec 18 05:40 /dev/udp
crw-rw-rw- 1 root root 72 0x000036 Dec 18 05:40 /dev/udp6
Where, udp and udp6 are two different devices with major number as 72 and unique minor numbers
0x000033 and 0x000036 respectively.
Major numbers for the hardware devices are typically assigned by the system at boot time or by utilities like
install_driver(). Major numbers for the pseudo-devices are assigned by install_driver(). Character
major numbers and block major numbers are assigned separately for devices that are exclusively block or
character. This means that two separate special device files for two different device drivers namely character
and block device drivers may have the same value assigned to them as major number.
The minor number identifies a specific device, such as a single terminal. Minor numbers for devices are
designated by the driver developer.
The utilities getmajor() and getminor() can be used to obtain the major and minor numbers associated
with a device.
Cloning
A user process connects a stream to a driver by opening a specific device file. The connection is assigned a
major number and a minor number. When a second user process (or a second open call from the same process)
connects to the same driver, it will, by default, communicate with the stream head already created for the
stream. But if this second user process needs to connect to a different device file under the same driver, it now
becomes responsible for finding its own minor number, typically by polling for available minor device
numbers under the driver. To make the task of finding minor device number easier, STREAMS supports clone
opens. When a driver is implemented as a cloneable device, a single node in the file system can be opened to
access any unused minor devices that the driver controls, for example, the special node guarantees a separate
stream for every open (2) system call on the driver.
In HP-UX the driver can be implemented as cloneable devices in two ways.
The first cloning method uses a special clone major number, 72, to provide cloning. For each cloneable device,
a device file must exist that has the clone major number of 72 and also has a minor number equal to the major
number of the real device. When an application opens this type of device file, STREAMS passes the driver
open routine CLONEOPEN in the
sflag
parameter. The driver allocates a minor number and returns a new
device number containing the true major number and the chosen minor number.
The second cloning method is useful for drivers which need to be able to encode information in their minor
numbers. This is not possible in the first method, as the clone device file for that method must have as its
minor number the major number of the driver being cloned.
In the second cloning method, the driver designates a particular minor number as its “clone” minor number.
The driver open routine checks the minor number portion of the device number parameter passed to it, and if
it is the clone minor number, the driver open routine allocates a minor number and returns a new device
number to the caller, in the same way as the first cloning method described. The returned device number
must contain both a major number and the new minor number. A driver using this cloning method may also
change the major number in the device number it returns. However, the new major number must correspond
to a STREAMS driver with the same streamtab structure as the driver associated with the original major
number.