Specifications

D
evice Driver Programming
17-24
shmget(2) to obtain the shared memory identifier for the region
shmat(2) to attach the shared memory region to the process’s virtual address
space
It is recommended that on the first call to the driver’s open routine, the atexit(3C)
routine be called to register an internal driver routine to close open devices when a process
exits. Procedures for using the atexit(3C) routine are explained in “The atexit(3C)
Library Routine” on page 17-17.
If access to the device for which you are writing a user-level driver must be restricted to a
single process at a time, you must use the open routine to enforce this restriction. In such
cases, it is especially important that you also guarantee that the device is closed if a
process that has opened it terminates unexpectedly.
Specification
int xx_open(dev_desc
,
path
,
flags
,
arg)
int *dev_desc
;
char *path
;
int flags
;
dev_struct *arg;
Parameters
dev_desc a pointer to the location to which an identifier for the opened device is
returned. This identifier is allocated by the user-level device driver. Generally
dev_desc is a pointer to a structure that uniquely identifies the device.
path a pointer to the path name of the device special file associated with the device
flags driver status flags. The flags that can be specified are as follows:
UD_FORCE indicates that the specified device is to be opened although
it has already been exclusively opened by another process.
It is intended that you use this flag only during the
development of a user-level device driver. User-level drivers
do not have the same clean-up capability that kernel drivers
do when a device is closed after a user program aborts. If
the close procedure associated with an exclusive open of the
device has not been properly completed, the device is hung.
Setting this bit allows a process to open the device, clean up
the global data structures associated with the device, and
make the device usable again.
UD_EXCL indicates that access to the specified device is to be granted
exclusively to the calling process
UD_DEBUG indicates that the specified device is to be opened for
debugging purposes
arg a pointer to a structure that is specific to the specified device