One way to construct a Stream is to open(2) a STREAMS special file. If the open call is the initial file open, a Stream is created. (There is one Stream for each major or minor device pair.) If this open is not the initial open of this Stream, the open procedures of the driver and all pushable modules on the Stream are called.
Sometimes a user process needs to connect a new Stream to a driver regardless of which minor device is used to access the driver. Instead of the user process polling for an available minor device node, STREAMS provides a facility called clone open. If a STREAMS driver is implemented as a clone device, a single node in the file system may be opened to access any unused device that the driver controls. This special node guarantees that the user is allocated a separate Stream to the driver for every open call. Each Stream is associated with an unused major or minor device, so the total number of Streams that can connect to a particular clone driver is limited to the number of minor devices configured for the driver.
Clone devices are used, for example, in a networking environment where a protocol pseudo-device driver requires each user to open a separate Stream to establish communication.
You can open a clone device in two ways. The first is to create a node with the major number of the clone device (--) and a minor number corresponding to the major number of the device to be cloned. For example /dev/ps0 might have a major number of 50 and a minor number of 0 for normal opens. The clone device may have a major number of 40. By creating a node /dev/ps with a major number of 40 and a minor number of 50, a clonable device is created. In this case, the driver is passed a special flag (CLONEOPEN) that tells it to return a unique minor device number.
The second way is to have the driver open itself as a clone device, that is, the driver returns a unique minor number.
When a Stream is already open, further opens of the same device result in the open routines of all modules and the driver on the Stream being called. In this case, a driver is opened and a module is pushed on a Stream. When a push occurs the module open routine is called. If another open of the same device is made, the open routine of the module is called, followed by the open routine of the driver. This is opposite to the initial order of opens when the Stream is created.
STREAMS also offers autopush. On an open(2) system call, a preconfigured list is checked for modules to be pushed. All modules in this list are pushed before the open(2) returns. For more information see the autopush(1M) and sad(7D) man pages.
There is one Stream head per Stream. The Stream head, which is initiated by the first open call, is created from a data structure and a pair of queue structures. The content of the Stream head and queues is initialized with predetermined values, including the Stream head processing procedures.