STREAMS-UX Programmer's Guide (February 2007)
Modules and Drivers
Entry Points
Chapter 4
70
Entry Points
This section explains the entry points for drivers and modules in detail.
Open
The open routine for a driver is called when the device is first opened by the user process with an open (2)
system call. The module open routine is called when the module is pushed onto the stream with I_PUSH
IOCTL command or with the autopush utility.
For SVR 4 compliance, the open routine has the following definition:
int drv_open(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *credp);
For SVR 3.2 compliance, the open routine is as follows:
int drv_open(queue_t *q, dev_t devp, int oflag, int sflag, cred_t *credp);
q is the pointer to the driver/module’s read queue. devp points to the device pointer in SVR4 open (2). devp is
the device number in SVR 3.2 open (2). oflag are the flags used by the application in the open (2) system
call, sflag indicates the type of STREAMS open to perform and credp point to the processes credentials. On
success the open routine should return 0 and an error number on failure.
Valid sflag values are defined in <sys/stream.h> and are as follows:
0 — Non-cloneable driver open
CLONEOPEN — Cloneable driver open
MODOPEN — Module open
Do not call a driver with the sflag set to MODOPEN. But, as a driver can be configured as both module and
driver, appropriate sflag should be used in the open routine. i.e., when it is configured as driver sflag
should be set to 0 or CLONEOPEN and when it is configured as module sflag should be set to MODOPEN.
In the open routine the module or driver allocates and initializes its resources. For same minor device, the
driver open routines are serialized and only one open routine will be allowed to process at a time. Usually, the
first open of the device will allocate the structures and subsequent open routines will have very little
processing to do if any. Modules and drivers can sleep in the open routine at an uninterruptible priority level
or with PCATCH set, as it has user context.
Close
The close routine for a driver is invoked on the last close of the device. The close routine for a module is
invoked when it is popped from the stream as a result of a I_POP IOCTL command or closing of the stream.
For SVR 4 compliance, the close routine has the following definition:
int drv_close(queue_t *q, int oflag, cred_t *credp);
For the SVR 3.2 compliance, the close routine is as follows:
int drv_close(queue_t *q, int oflag);
Where q is the pointer to the driver or modules read queue, oflag is the bitmask of flags indicating the file
status and credp point to the processes credentials. On success the close routine should return 0 and it
returns an error value on failure, even though the return value from the close routine is currently ignored by
STREAMS.