#include <sys/types.h> #include <sys/file.h> #include <sys/errno.h> #include <sys/open.h> #include <sys/cred.h> #include <sys/ddi.h> #include <sys/sunddi.h> int prefixclose(dev_t dev, int flag, int otyp, cred_t *cred_p);
#include <sys/types.h> #include <sys/stream.h> #include <sys/file.h> #include <sys/errno.h> #include <sys/open.h> #include <sys/cred.h> #include <sys/ddi.h> #include <sys/sunddi.h> int prefixclose(queue_t *q, int flag, cred_t *cred_p);
Architecture independent level 1 (DDI/DKI). This entry point is required for block devices.
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:
deallocate any resources allocated on open
- 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
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.