STREAMS Programming Guide

ioctl(2) Processing

STREAMS is a special type of character device driver that is different from the historical character input/output (I/O) mechanism in several ways.

In the classical device driver, all ioctl(2) calls are processed by the single device driver, which is responsible for their resolution. The classical device driver has user context, that is, all data can be copied directly to and from user space.

By contrast, the Stream head itself can process some ioctl(2) calls (defined in streamio(7I)). Generally, STREAMS ioctl(2) calls operate independently of any particular module or driver on the Stream. This means the valid ioctl(2) calls that are processed on a Stream change over time, as modules are pushed and popped on the Stream. The Stream modules have no user context and must rely on the Stream head to perform copyin and copyout requests.

There is no user context in a module or driver when the information associated with the ioctl(2) call is received. This prevents use of ddi_copyin(9F) or ddi_copyout(9F) by the module. No user context also prevents the module and driver from associating any kernel data with the currently running process. In any case, by the time the module or driver receives the ioctl(2) call, the process generating can have exited.

STREAMS allows user processes to control functions on specific modules and drivers in a Stream using ioctl(2) calls. In fact, many streamio(7I) ioctl(2) commands go no further than the Stream head. They are fully processed there and no related messages are sent downstream. If, however, it is an I_STR ioctl(2) or an unrecognized ioctl(2) command, the Stream head creates an M_IOCTL message, which includes the ioctl(2) argument. This is then sent downstream to be processed by the pertinent module or driver. The M_IOCTL message is the precursor message type carrying ioctl(2) information to modules. Other message types are used to complete the ioctl processing in the Stream. Each module has its own set of M_IOCTL messages it must recognize.