DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
DDI: 8 sample driver

samp_open entry point routine

The open(D2) entry point is called the first time the device is accessed from a user-level call such as open or mount or from another driver that calls the drv_open(D3) function.

Note differences in the syntax of DDI 8 open( ) routine from other DDI versions and SCO OpenServer 5. The dev_t argument is replaced by the idata/channelp pair, and the syntax includes the queue_t pointer that is used for STREAMS drivers, since for DDI 8, STREAMS and non-STREAMS drivers use the same syntax for open( ) and close( ). People coming from an SCO OpenServer 5 background will also note the addition of the cred_t pointer which is used to check for privilege.

For debugging purposes, an ASSERT(D3) statement verifies that the channel being opened is valid.

The code then calls the drv_priv(D3) function to check for privileges. DDI drivers use this privileges scheme in place of the more limited suser(D3oddi) check for superuser privileges that is used for SCO OpenServer 5 drivers.

The code then locks the idata for the device instance, increments the number of open channels, and unlocks the idata structure. For debugging purposes, an ASSERT( ) statement verifies that the pl(D5) value is set to the proper level (plbase) before setting the lock. Using this counter to determine the number of open channels for the device avoids the overhead of scanning all the channels whenever this information is needed.

The samp_open( ) routine returns 0 to indicate success. A driver for a hardware peripheral device would include more error checking and would be coded to return appropriate values from those listed on the errnos(D5) manual page if errors were encountered.


© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005