JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
man pages section 9: DDI and DKI Driver Entry Points     Oracle Solaris 11.1 Information Library
search filter icon
search icon

Document Information

Preface

Introduction

Driver Entry Points

aread(9E)

attach(9E)

audio_engine_channels(9E)

audio_engine_chinfo(9E)

audio_engine_close(9E)

audio_engine_count(9E)

audio_engine_format(9E)

audio_engine_open(9E)

audio_engine_playahead(9E)

audio_engine_qlen(9E)

audio_engine_rate(9E)

audio_engine_start(9E)

audio_engine_stop(9E)

audio_engine_sync(9E)

awrite(9E)

chpoll(9E)

close(9E)

csx_event_handler(9E)

detach(9E)

devmap(9E)

devmap_access(9E)

devmap_contextmgt(9E)

devmap_dup(9E)

devmap_map(9E)

devmap_unmap(9E)

dump(9E)

_fini(9E)

getinfo(9E)

gld(9E)

gldm_get_stats(9E)

gldm_intr(9E)

gldm_ioctl(9E)

gldm_reset(9E)

gldm_send(9E)

gldm_set_mac_addr(9E)

gldm_set_multicast(9E)

gldm_set_promiscuous(9E)

gldm_start(9E)

gldm_stop(9E)

identify(9E)

_info(9E)

_init(9E)

ioctl(9E)

ks_snapshot(9E)

ks_update(9E)

mac(9E)

mac_capab_rings(9E)

mac_group_info(9E)

mac_ring_info(9E)

mc_getcapab(9E)

mc_getprop(9E)

mc_getstat(9E)

mc_ioctl(9E)

mc_multicst(9E)

mc_propinfo(9E)

mc_setpromisc(9E)

mc_setprop(9E)

mc_start(9E)

mc_stop(9E)

mc_tx(9E)

mc_unicst(9E)

mgi_addmac(9E)

mgi_add_vlanfilter(9E)

mgi_getsriov_info(9E)

mgi_remmac(9E)

mgi_rem_vlanfliter(9E)

mgi_setmtu(9E)

mgi_start(9E)

mgi_stop(9E)

mmap(9E)

mr_gaddring(9E)

mr_gget(9E)

mr_gremring(9E)

mri_intr_disable(9E)

mri_intr_enable(9E)

mri_poll(9E)

mri_start(9E)

mri_stat(9E)

mri_stop(9E)

mri_tx(9E)

mr_rget(9E)

open(9E)

power(9E)

print(9E)

probe(9E)

prop_op(9E)

put(9E)

quiesce(9E)

read(9E)

segmap(9E)

sofop_accepted(9E)

sofop_attach_active(9E)

sofop_attach_passive(9E)

sofop_bind(9E)

sofop_connect(9E)

sofop_data_in(9E)

sofop_data_in_proc(9E)

sofop_data_out(9E)

sofop_detach(9E)

sofop_getpeername(9E)

sofop_getsockname(9E)

sofop_getsockopt(9E)

sofop_listen(9E)

sofop_notify(9E)

sofop_setsockopt(9E)

sofop_shutdown(9E)

srv(9E)

strategy(9E)

tran_abort(9E)

tran_bus_reset(9E)

tran_destroy_pkt(9E)

tran_dmafree(9E)

tran_getcap(9E)

tran_init_pkt(9E)

tran_pkt_constructor(9E)

tran_pkt_destructor(9E)

tran_quiesce(9E)

tran_reset(9E)

tran_reset_notify(9E)

tran_setcap(9E)

tran_setup_pkt(9E)

tran_start(9E)

tran_sync_pkt(9E)

tran_teardown_pkt(9E)

tran_tgt_free(9E)

tran_tgt_init(9E)

tran_tgt_probe(9E)

tran_unquiesce(9E)

write(9E)

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);

Interface Level

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

Parameters

Block and Character

devp

Pointer to a device number.

flag

A bit field passed from the user program open(2) system call that instructs the driver on how to open the file. 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. Do not block the open even if something is wrong.

FREAD

Open the device with read-only permission, If ORed with FWRITE, allow both read and write access.

FWRITE

Open a device with write-only permission. If ORed with FREAD, allow both read and write access.

otyp

Parameter supplied for driver to determine how many times a device was opened and for what reasons. For OTYP_BLK and OTYP_CHR, the open() function can be called many times, but the close(9E) function is called only when the last reference to a device is removed. If the device is accessed through file descriptors, it is done by a call to close(2) or exit(2). If the device is accessed through memory mapping, it is done by a call to munmap(2) or exit(2). For OTYP_LYR, there is exactly one close(9E) for each open() operation that is called. This permits software drivers to exist above hardware drivers and removes any ambiguity from the hardware driver regarding how a device is used.

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) function. The calling driver ensures that there is one-layered close for each layered open. This flag applies to both block and character devices.

cred_p

Pointer to the 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 FEXCL, FNDELAY, FREAD, and FWRITEL — the same as those listed above for flag.. For STREAMS modules, oflag is always set to 0.

sflag

Valid values are as follows:

CLONEOPEN

Indicates that the open() function 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 user credential structure.

Description

The driver's open() function is called by the kernel during an open(2) or a mount(2) on the special file for the device. A device can be opened simultaneously by multiple processes and the open() driver operation is called for each open. Note that a device is referenced once its associated open(9E) function is entered, and thus open(9E) operations which have not yet completed will prevent close(9E) from being called. The function should verify that the minor number component of *devp 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.

The kernel provides open() close() exclusion guarantees to the driver at *devp, otyp granularity. This delays new open() calls to the driver while a last-reference close() call is executing. If the driver has indicated that an EINTR returns safe via the D_OPEN_RETURNS_EINTR cb_ops(9S) cb_flag, a delayed open() may be interrupted by a signal that results in an EINTR return.

Last-reference accounting and open() close() exclusion typically simplify driver writing. In some cases, however, they might be an impediment for certain types of drivers. To overcome any impediment, the driver can change minor numbers in open(9E), as described below, or implement multiple minor nodes for the same device. Both techniques give the driver control over when close() calls occur and whether additional open() calls will be delayed while close() is executing.

The open() function is passed a pointer to a device number so that the driver can change the minor number. This allows drivers to dynamically create minor instances of the device. An example of this might be a pseudo-terminal driver that creates a new pseudo-terminal whenever it is opened. A driver that chooses the minor number dynamically, normally creates only one minor device node in attach(9E) with ddi_create_minor_node(9F). It then changes the minor number component of *devp using makedevice(9F) and getmajor(9F). The driver needs to keep track of available minor numbers internally. A driver that dynamically creates minor numbers might want to avoid returning the original minor number since returning the original minor will result in postponed dynamic opens when original minor close() call occurs.

*devp = makedevice(getmajor(*devp), new_minor);

Return Values

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

See Also

close(2), exit(2), mmap(2), mount(2), munmap(2), open(2), Intro(9E), attach(9E), close(9E), ddi_create_minor_node(9F), getmajor(9F), getminor(9F), makedevice(9F), nulldev(9F), cb_ops(9S)

Writing Device Drivers

STREAMS Programming Guide

Warnings

Do not attempt to change the major number.

When a driver modifies the device number passed in, it must not change the major number portion of the device number. Unless CLONEOPEN is specified, the modified device number must map to the same driver instance indicated by the driver's getinfo(9e) implementation. In other words, cloning across different drivers is not supported. Cloning across different instances of the same driver in only permitted if the driver specified in CLONE_DEV in ddi_create_minor_node(9F) is not supported.