DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
SCO OpenServer

open(D2oddi)


open -- gain access to a device

Synopsis

   void prefixopen (dev_t dev, int flag, int otyp);

Description

The open( ) entry point routine is called by the kernel as a result of an open or mount system call for the device file. It establishes a connection between the user process that issued the open( ) call and the device being opened.

Arguments


dev
device number

flag
information passed from the user program in an open or creat system call, instructing the driver on how the special device file will be accessed. The values for the flag are defined in the file.h header file for the f_flag member of the file structure. Valid values are:

FAPPEND
open an existing file and set the file pointer to the end of the file.

FCREAT
open a new file; ignored if the file already exists.

FEXCL
open a new file, but fail if the file already exists (used with FCREAT)

FNDELAY
open the file with no delay. (do not block the open to wait for resources).

FREAD
open the file for read-only permission. If ORed with FWRITE, then allow both read and write access.

FSYNC
grant synchronous write permission to a user program for file access.

FTRUNC
open an existing file and truncate its length to 0

FWRITE
open a file with write-only permission. If ORed with FREAD, then allow both read and write access.

otyp
parameter supplied so that drivers keep an accurate record of how many times a device is opened and for what reasons

OTYP_BLK
open a block special file for the first time

OTYP_CHAR
open a character special file for the first time

OTYP_MNT
open (mount) a file system

OTYP_SWP
open a swapping device

OTYP_LYR
open a layered process. The OTYP_LYR flag is used when one driver calls another's open( ) or close(D2oddi) routine. In this case, there is exactly one close( ) for each open( ) call. This permits software drivers to exist above hardware drivers without introducing ambiguity to the hardware driver regarding how a device is being used. This flag is used for both block and character devices.

Return values

None

Usage

The open( ) routine should perform the following tasks:

An open( ) routine should set the device for subsequent data transfer. When a device is opened simultaneously by multiple processes, the operating system calls the open(D2oddi) routine for each open call.

If an error occurs, the routine sets u.u_error. Read and write parameters are defined in the user.h header file.

An incorect special device file could cause the driver's open( ) routine to be passed an incorrect device number, which could cause it to open a different device. The driver should be coded to compare the device number to a variable that defines the number of devices associated with a controller to ensure that the number is correct.

The first instance of the open( ) routine can also be used to initialize the device. This is useful when the device needs system services or another driver to be initialized before it is initialized.

Context and synchronization

Blockable context. The driver can block but cannot do operations such as copyout(D3) that require access to the requesting process's address space.

Hardware applicability

All

Version applicability

oddi: 1, 2, 2mp, 3, 3mp, 4, 4mp, 5, 5mp, 6, 6mp

SVR5 DDI compatibility

The open(D2) entry point routine provides similar functionality for DDI drivers, although note that the syntax is different.

External dependencies

Drivers that contain a open( ) routine must have a o in the second column of the mdevice(F) file.

References

close(D2oddi), close(S) , open(S)


19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 5 HDK - June 2005