Next | Prev | Up | Top | Contents | Index

Driver Entry Points

A set of driver entry point routines define what the system must do when a user-level program executes a system call, such as open(), that accesses the device. Because the user expects to treat the device as a file, you must write a driver entry point routine for each operation normally performed on a file, such as open, read, write, and close. You will probably also have to write additional driver routines to handle initialization at system power-up.

When you successfully configure a driver into the kernel, lboot automatically adds members (one for each entry point in the driver) to the cdevsw structure, the character device switch table.

Note: The cdevsw structure is used for character device drivers; a block device driver structure would be named bdevsw. STREAMS drivers, which have user-accessible device nodes, such as /dev/llc2, also belong in the cdevsw structure; STREAMS modules, which have no device nodes, belong in fmodsw. The section of the cdevsw structure that maintains the pointers to the device entry points for a device called drv would look like this:

struct cdevsw cdevsw[] = {
    { nodevflag, 0, drvopen, drvclose, drvread, drvwrite,
    drvioctl, drvmmap, drvmap, drvunmap, drvpoll, 0, 0 },
};
When the kernel handles a system call, it can find a specific entry point for a device if it constructs the name of the appropriate cdevsw member. For example, if the kernel must handle an open() for a device, drv, the kernel knows that drvopen is the member of csdevsw that contains a pointer to the open routine for the drv device.


Missing Driver Entry Points
Character and Block Entry Point Driver Routines
Writing Other Driver Routines
STREAMS Driver Entry Points

Next | Prev | Up | Top | Contents | Index