Writing Device Drivers

cb_ops Structure

static struct cb_ops xx_cb_ops = {
        xxopen,         /* open(9E) */
        xxclose,        /* close(9E) */
        xxstrategy,     /* strategy(9E) */
        xxprint,        /* print(9E) */
        xxdump,         /* dump(9E) */
        xxread,         /* read(9E) */
        xxwrite,        /* write(9E) */
        xxioctl,        /* ioctl(9E) */
        xxdevmap,       /* devmap(9E) */
        nodev,          /* mmap(9E) */
        xxsegmap,       /* segmap(9E) */
        xxchpoll,       /* chpoll(9E) */
        xxprop_op,      /* prop_op(9E) */
        NULL,           /* streamtab(9S) */
        D_MP | D_64BIT  /* cb_flag */
}; 

The cb_ops(9S) structure contains the entry points for the character and block operations of the device driver. Any entry points the driver does not support should be initialized to nodev(9F). For example, character device drivers should set all the block-only fields, such as cb_stategy, to nodev(9F). Note that the mmap(9E) entry point is maintained for compatibility with previous releases, and drivers should use the devmap(9E) entry point for device memory mapping. If devmap(9E) is supported, set mmap(9E) to nodev(9F).

The streamtab field is used to determine if this is a STREAMS-based driver. The device drivers discussed in this book are not STREAMS based. For a non-STREAMS-based driver, it must be set to NULL.

The cb_flag member contains the following flags:

cb_rev is the cb_ops(9S) structure revision number. This field must be set to CB_REV.