Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ close(D2DK) — Motorola System V 88k Release 4 Version 4.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

close(D2DK)  —  

.IX \f4close\fP(D2DK)

NAME

close − relinquish access to a device

SYNOPSIS    [Block and Character]

#include <sys/types.h>
#include <sys/file.h>
#include <sys/errno.h>
#include <sys/open.h>
#include <sys/cred.h>
#include <sys/ddi.h>
int prefixclose(dev_t dev, int flag, int otyp, cred_t ∗crp);

ARGUMENTS

devDevice number. 

flagFile status flag.  Possible flag values and their definitions can be found in open(D2DK). 

otypParameter supplied so that the driver can determine how many times a device was opened and for what reasons.  The values are mutually exclusive. 

OTYP_BLK Close was through block interface for the device. 

OTYP_MNT Close was called as a result of a umount(2) system call; unmount the file system associated with the block device. 

OTYP_CHR Close was through the raw/character interface for the device. 

OTYP_SWP Close a swapping device. 

OTYP_LYR Close a layered device.  This flag is used when one driver calls another driver’s close routine. 

OTYP_DMP Close a device previously opened for crash dump. 

crpPointer to the user credential structure. 

SYNOPSIS          [STREAMS]

#include <sys/types.h>
#include <sys/stream.h>
#include <sys/file.h>
#include <sys/errno.h>
#include <sys/cred.h>
#include <sys/ddi.h>
int prefixclose(queue_t ∗q, int flag, cred_t ∗crp);

ARGUMENTS

qPointer to queue used to reference the read side of the driver. 

flagFile status flag. 

crpPointer to the user credential structure. 

DESCRIPTION

The close routine 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. 

For OTYP_BLK and OTYP_CHR, a device may be opened simultaneously by multiple processes and the driver open 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) system call or exits. 

There is one exception to this rule.  If a device is opened through both its character and its block interfaces, then there will be one close per interface.  For example, if the same device is opened twice through its block interface and three times through its character interface, then there will be two calls to the driver’s close routine; one when the block interface is finished being used, and one when the character interface is finished being used. 

For OTYP_LYR, there will be one such close for every corresponding open.  Here, the driver should count each open and close based on the otyp parameter to determine when the device should really be closed. 

A close routine could perform any of the following general functions, depending on the type of device and the service provided:

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

cancel any pending timeout or bufcall routines that access data that are de-initialized or deallocated during close

deallocate any resources allocated on open

If the FNDELAY or FNONBLOCK flags are specified in the flag argument, the driver should try to avoid sleeping, if possible, during close processing. 

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 non-persistent 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:

1.  The write queue is given a chance to drain. 

2.  The close routine is called. 

3.  The module or driver is removed from the stream. 

4.  Any remaining messages on the queues are freed. 

NOTES

This entry point is required in all drivers.  The close routine has user context and can sleep.  STREAMS drivers and modules must call qprocsoff(D3DK) to disable their put(D2DK) and service [srv(D2DK)] routines before returning from the close routine. 

RETURN VALUE

The close routine should return 0 for success, or the appropriate error number.  Refer to errnos(D5DK) for a list of DDI/DKI error numbers.  Return errors rarely occur, but if a failure is detected, the driver should still close the device and then decide whether the severity of the problem warrants displaying a message on the console. 

ERROR RETURN CODES

EFAULTBad address.  Drivers should return this error whenever a call to ­copyin(D3DK) or copyout(D3DK) fails. 

EINTRInterrupted operation.  Drivers can return this error whenever an interruptible operation is interrupted by receipt of an asynchronous signal. 

EIOAn I/O error has occurred.  Drivers can return this error when an input or output request has failed. 

ENXIONo such device or address.  Drivers can return this error when trying to open an invalid minor device, or when trying to perform I/O past the end of a device. 

EPERMPermission denied.  Drivers can return this error when a operation is attempted that requires more privilege than the current process has. 

SEE ALSO

open(D2DK), drv_priv(D3DK), qprocsoff(D3DK), unbufcall(D3DK), untimeout(D3DK), queue(D4DK), errnos(D5DK)

DDI/DKI

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026