#include <sys/types.h> #include <sys/file.h> #include <sys/errno.h> #include <sys/open.h> #include <sys/cred.h> #include <sys/stream.h> #include <sys/ddi.h>See ``Differences between versions''
int prefixopen(void *idata, channel_t *channelp, int oflags, cred_t *crp, queue_t *q);
For STREAMS modules, channelp is undefined and should not be referenced.
The open routine can perform any of the following general functions, depending on the type of device and the service provided:
The open routine should verify that the type of access requested by oflags is appropriate for the device, and, if required, check for required privilege using the user credentials pointed to by crp; see drv_priv(D3).
To implement clone behavior in a driver, designate a particular channel number to be the clone channel. When this channel is opened, the driver searches its list of open channels; the first one that is not already open becomes the target. The driver changes channelp to the new target channel number and proceeds to open that channel.
If the driver returns successfully with *channelp set to a new value, the new channel is considered to have been opened; this does not result in another open(D2) call. The original channel has not been opened and will not receive a subsequent close( ) unless it was previously opened by another call.
The $maxchan field of the
file and the
drv_maxchan member of the
file determine the number of channels
that are allocated in the device table for this driver.
Drivers that use open redirection
should create one channel for the initial open
plus one for each clone channel.
You should allocate enough channels to support
the maximum number of simultaneous open redirection operations
that you anticipate,
but remember that each additional channel
consumes a device number from the 32-bit address space,
so randomly picking artificially high numbers
is not advised.
The driver should be coded to handle
an open redirection request that is issued
when no clone devices are available.
The driver can either fail the I/O operation
and return an error with the
function, or it can wait for a channel to be available.
If the FNONBLOCK flag is set in oflags, the driver must not wait for long-term conditions to change in order to complete this operation. It should, however, block for system resource allocations such as memory allocations if necessary.
int prefixopen(dev_t *devp, int oflags, int otyp, cred_t *crp);devp is a pointer to a device number. otyp is a parameter supplied so that the driver can determine how many times a device was opened and for what reasons. Valid values for otyp are listed below. These values are mutually exclusive:
In DDI versions prior to version 8, drivers implement open redirection by changing the device number pointed to by devp. The driver may either recognize a particular minor number as the ``clone'' minor, or if it is a STREAMS driver, it may depend on the STREAMS clone driver, and then check for the CLONEOPEN styp value. A driver may designate certain minor devices as special clone entry points into the driver. When these are opened, the driver searches for an unused device and returns the new device number by changing the value of the device number to which devp points. Both the major device number and the minor device number can be changed, although usually just the minor number is changed. The major number is only changed when the clone controls more than one device.
In DDI versions prior to version 8, the driver must treat an FNDELAY flag in oflags the same as the FNONBLOCK flag.
In DDI versions prior to version 8, open( ) is a named entry point for non-STREAMS drivers and must be defined as a global symbol.
Some earlier releases of the documentation claimed that this entry point had user context, but this was not true in all cases.
d_openmember of their drvops(D4) structure.
Named entry point routines must be declared in the driver's Master(DSP/4dsp) file. The declaration for this entry point is $entry open. This applies only to non-STREAMS drivers that use DDI versions prior to version 8.
SDI HBA drivers that support passthrough operations use a different form of this routine, which is declared in the driver's hba_info(D4sdi) structure. See open(D2sdi).