For STREAMS drivers, the close() routine is called by the kernel through the cb_ops(9S) table entry for the device. (Modules use the fmodsw table.) A non-null value in the d_str field of the cb_ops entry points to a streamtab structure, which points to a qinit(9S) containing a pointer to the close() routine. Non-STREAMS close() routines are called directly from the cb_ops
table.
close() ends the connection between the user process and the device, and prepares the device (hardware and software) so that it is ready to be opened again.
A device may be opened simultaneously by multiple processes and the open() driver routine is called for each open, but the kernel will only call the close()
routine when the last process using the device issues a close(2)
or umount(2) system call or exits. (An exception is a close
occurring with the otyp argument set to OTYP_LYR, for which a close (also having otyp = OTYP_LYR) occurs for
each open.)
In general, a close() routine should always check the validity of the minor number component of the dev parameter. The routine should also check permissions
as necessary, by using the user credential structure (if pertinent), and the appropriateness of the flag and otyp parameter values.
close() could perform any of the following general functions:
- disable interrupts
- hang up phone lines
- rewind a tape
- deallocate buffers from a private buffering scheme
- unlock an unsharable device (that was locked in the open() routine)
- flush buffers
- notify a device of the close
- deallocate any resources allocated on open
The close() routines of STREAMS drivers and modules are called when a stream is dismantled or a module popped. The steps for dismantling a stream are performed in the following
order. First, any multiplexor links present are unlinked and the lower streams are closed. Next, the following steps are performed for each module or driver on the stream, starting at the head and working
toward the tail:
- The write queue is given a chance to drain.
- The close() routine is called.
- The module or driver is removed from the stream.
|