Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ open(9E) — SunOS 5.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

close(9E)

open(9E)

NAME

open − gain 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>
#include <sys/sunddi.h>
int prefixopen(dev_t ∗devp, int flag
, int otyp, cred_t ∗cred_p);

STREAMS

#include <sys/file.h>
#include <sys/stream.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
int prefixopen(queue_t ∗q, dev_t ∗devp
, int oflag, int sflag, cred_t ∗cred_p
);

ARGUMENTS

Block and Character

devp Pointer to a device number. 

flag Information passed from the user program open(2) system call that instruct the driver on how to open the file.  The bit settings for the flag are found in file.h associated with the f_flag member of the file structure.  Valid settings are:

FEXCL
Open the device with exclusive access; fail all other attempts to open the device.

FNDELAY
Open the device and return immediately without sleeping (do not block the open)

FREAD
Open the device with read-only permission (if ORed with FWRITE, then allow both read and write access)

FWRITE
Open a device with write-only permission (if ORed with FREAD, then allow both read and write access)

otyp Parameter supplied so that the driver can determine how many times a device was opened and for what reasons.  The flags assume the open() routine may be called many times, but the close() routine is called only on the last close(9E) of a device.  All flags are defined in open.h. 

OTYP_BLK
Open occurred through block interface for the device

OTYP_CHR
Open occurred through the raw/character interface for the device

OTYP_LYR
Open a layered process. This flag is used when one driver calls another driver’s open() or close(9E) routine.  In this case, there is exactly one close(9E) for each open() called. This permits software drivers to exist above hardware drivers and removes any ambiguity from the hardware driver regarding how a device is used. This flag applies to both block and character devices.

cred_p
Pointer to the cred(9S) user credential structure. 

STREAMS

q A pointer to the read queue. 

devp Pointer to a device number.  For STREAMS modules, devp always points to the device number associated with the driver at the end (tail) of the stream. 

oflag Valid oflag values are the same as those listed above, with the exception that FAPPEND, FCREAT, and FTRUNC have no meaning to a STREAMS device.  For STREAMS modules, oflag is always set to 0. 

sflag Valid values are as follows:

CLONEOPEN
Indicates that the open routine is called through the clone driver.  The driver should return a unique device number. 

MODOPEN
Modules should be called with sflag set to this value. Modules should return an error if they are called with sflag set to a different value. Drivers should return an error if they are called with sflag set to this value. 

0 Indicates a driver is opened directly, without calling the clone driver. 

cred_p
Pointer to the cred(9S) user credential structure. 

INTERFACE LEVEL

Architecture independent level 1 (DDI/DKI).  This entry point is Required, but it can be nulldev. 

DESCRIPTION

The driver’s open() routine is called by the kernel through the cb_ops(9S) entry for the device during an open(2) or a mount(2) on the special file for the device.  The routine should verify that the minor number component of dev is valid, that the type of access requested by otyp and flag is appropriate for the device, and, if required, check permissions using the user credentials pointed to by cred_p.

RETURN VALUES

The open() routine should return  0 for success, or the appropriate error number.

SEE ALSO

close(9E)

SunOS 5.1 STREAMS Programmer’s Guide

SunOS 5.1  —  Last change: 1 May 1992

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