gain access to a device
void prefixopen (dev_t dev, int flag, int otyp);
entry point routine
is called by the kernel as a result of an
system call for the device file.
It establishes a connection between the user process
that issued the
call and the device being opened.
information passed from the user program in an
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
f_flag member of the file structure.
Valid values are:
open an existing file and set the file pointer
to the end of the file.
open a new file;
ignored if the file already exists.
open a new file,
but fail if the file already exists
(used with FCREAT)
open the file with no delay.
(do not block the open to wait for resources).
open the file for read-only permission.
If ORed with FWRITE,
then allow both read and write access.
grant synchronous write permission
to a user program for file access.
open an existing file and truncate its length to 0
open a file with write-only permission.
If ORed with FREAD,
then allow both read and write access.
parameter supplied so that drivers keep
an accurate record of how many times a device is opened
and for what reasons
open a block special file for the first time
open a character special file for the first time
open (mount) a file system
open a swapping device
open a layered process.
The OTYP_LYR flag is used
when one driver calls another's
In this case, there is exactly one
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.
routine should perform the following tasks:
Validate the minor portion of the device number.
Set up device for subsequent data transfer.
Specify whether or not to wait for a hardware connection.
Follow the specifications for the ONDELAY flag
given on the
the O_NDELAY specified by the user-level program
corresponds to FNDELAY in the driver's
If this flag is set,
the open returns without waiting for a hardware connection;
this is used primarily for software drivers.
If this flag is not set,
sleeps until the hardware establishes a connection.
If this is an unsharable device,
verify that no other processes
are using or sleeping on the device
and then lock the device.
An unsharable device is one that
should be opened by only one process at a time.
Perform other device-specific operations.
For example, the
routine for a removable media disk drive
could lock the disk drive door
and cause the disk controller to select the drive.
routine for a terminal interface controller
could turn on the Data Terminal Ready (DTR) indicator.
routine should set the device for subsequent data transfer.
When a device is opened simultaneously
by multiple processes,
the operating system calls the
routine for each
If an error occurs,
the routine sets
Read and write parameters are defined in
the user.h header file.
An incorect special device file
could cause the driver's
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
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
The driver can block but cannot do operations such as
that require access to
the requesting process's address space.
1, 2, 2mp, 3, 3mp, 4, 4mp, 5, 5mp, 6, 6mp
SVR5 DDI compatibility
entry point routine provides similar functionality
for DDI drivers,
although note that the syntax is different.
Drivers that contain a
routine must have a o in the second column of the
19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 5 HDK - June 2005