Expanded Streams
As the second step in building a stream, modules can be added to the stream.
In the right-hand stream in the Stream Setup diagram (Figure 1), the CANONPROC module was added to provide additional processing on the characters sent between head and driver.
Modules are added and removed from a stream in last-in-first-out (LIFO) order. They are inserted and deleted at the stream head by using ioctl operations. In the stream on the left of the Module Reusability diagram (Figure 1), the Class 1 Transport was added first, followed by the Canonical modules. To replace the Class 1 module with a Class 0 module, the Canonical module would have to be removed first, and then the Class 1 module. Finally, a Class 0 module would be added and the Canonical module put back.

Because adding and removing modules resembles stack operations, an add routine is called a push and the remove routine is called a pop. I_PUSH and I_POP are two of the operations included in the STREAMS subset of ioctl operations (the streamio operations). These operations perform various manipulations of streams. The modules manipulated in this manner are called pushable modules, in contrast to the modules contained in the stream head and stream end. This stack terminology applies only to the setup, modification, and breakdown of a stream.
The stream head processes the streamio operation and executes the push, which is analogous to opening the stream driver. Modules are referenced by a unique symbolic name, contained in the STREAMS fmodsw module table (similar to the devsw table associated with a device file). The module table and module name are internal to STREAMS and are accessible from user space only through STREAMS ioctl subroutines. The fmodsw table points to the module template in the kernel. When a module is pushed, the template is located, the module structures for both QUEUES are allocated, and the template values are copied into the structures.
In addition to the module elements, each module contains pointers to an open routine and a close routine. The open routine is called when the module is pushed, and the close routine is called when the module is popped. Module open and close procedures are similar to a driver open and close.
As in other files, a STREAMS file is closed when the last process open to it closes the file by the close subroutine. This subroutine causes the stream to be dismantled (that is, modules are popped and the driver close routine is executed).