STREAMS-UX Programmer's Guide (February 2007)
Modules and Drivers
Entry Points
Chapter 4
73
}
The structure strioctl is defined in <stropts.h> and contains the following fields:
int ic_cmd; /* downstream command */
int ic_timout; /* ACK/NAK timeout */
int ic_len; /* length of data arg */
char * ic_dp; /* ptr to data arg */
The ic_cmd field describes the command intended for module or driver, ic_timout specifies the number of
seconds the I_STR request will wait for an acknowledgement before timing out. The ic_len field is the length
of the data buffer and ic_dp field points to the data buffer.
The stream head generates an M_IOCTL message for each I_STR IOCTL it receives. The attributes of the
strioctl structure provided by the user are copied into an iocblk structure and are attached as the data
buffer of the M_IOCTL message block. The actual user data is then attached as zero or more M_DATA messages
to the M_IOCTL message block.
The packaged M_IOCTL message is then sent downstream by the stream head for further processing. The first
component in the stream that recognizes the command in ic_cmd processes the message and sends a positive
or negative acknowledgment message upstream. If the positive/negative acknowledgment is not received by
the stream head within ic_timout seconds, then the I_STR IOCTL will fail. If data needs to be returned by
the target module or driver, ic_dp must point to a buffer large enough to hold that data, and ic_len will be
set on return to indicate the amount of data returned.
The following code sample from a put procedure of a driver describes the processing of an M_IOCTL message
generated from an I_STR IOCTL request:
drvput(q, mp)
queue_t *q;
mblk_t *mp;
{
struct iocblk *iocp;
struct drvdata *mydata;
/* Get driver private data structure pointer */
mydata = q->q_ptr;
switch(mp->b_datap->db_type) /* Check message type */
{
...
...
case M_IOCTL:
iocp = (struct iocblk *) mp->b_rptr;
/* Check ioctl command in the M_IOCTL message type */
switch(iocp->ioc_cmd)
{
/* valid ioctl recognized by this driver */
case SET_OPTIONS:
/* validate user data: