Specifications

D
evice Driver Programming
9-6
The cdevsw structure specifies the interface routines present for the character device.
Each device driver can provide open, close, read, write, ioctl, chpoll, and
mmap entry point routines. All of these are not necessary.
The driver’s entry points are specified in the Master(4) file associated with the driver
(see Chapter 16 for an explanation of this file). A driver can be either statically or dynami-
cally linked to the kernel image. In the former case, the driver’s entry points are stored as
function pointers in the cdevsw structure. In the latter case, the driver’s entry points are
dynamically linked to the cdevsw structure using a dynamic loader/linker at run time.
The cdevsw structure is never accessed directly from the device driver code. This struc-
ture is defined in the /usr/include/sys/conf.h file.
/*
* Character device switch table structure.
*/
struct cdevsw {
int (*d_open)();
int (*d_close();
int (*d_read)();
int (*d_write)();
int (*d_ioctl)();
int (*d_mmap)();
int (*d_segmap)();
int (*d_poll)();
int (*d_msgio)();
struct tty *d_ttys;
struct streamtab *d_str;
char *d_name;
int *d_flag;
int d_cpu;
struct module *d_modp;
};
The fields are defined as follows:
d_open Pointer to the driver’s open routine.
d_close Pointer to the driver’s close routine.
d_read Pointer to the driver’s read routine.
d_write Pointer to the driver’s write routine.
d_ioctl Pointer to the driver’s ioctl routine.
d_mmap Pointer to the driver’s mmap routine (for the implementation of the
mmap(2) system call).
d_segmap For character devices, can be used to specify a device specific rou-
tine to be used for creating address translations from mmap(2)
requests.
d_poll Pointer to the driver’s chpoll routine.