FreeBSD Device Driver Writer's Guide : Linking Into the Kernel. : Standard Model : Make room in conf.c
Previous: Adding to the driver list.
Next: Adding your device to the config file.

4.1.2. Make room in conf.c

Now you must edit ``/usr/src/sys/i386/i386/conf.c'' to make an entry for your driver. Somewhere near the top, you need to declare your entry points. The entry for the joystick driver is:


#include "joy.h"
#if NJOY > 0
d_open_t        joyopen;
d_close_t       joyclose;
d_rdwr_t        joyread;
d_ioctl_t       joyioctl;
#else
#define joyopen         nxopen
#define joyclose        nxclose
#define joyread         nxread
#define joyioctl        nxioctl
#endif

This either defines your entry points, or null entry points which will return ENXIO when called (the #else clause).

The include file ``joy.h'' is automatically generated by config(8) when the kernel build tree is created. This usually has only one line like:


#define NJOY 1

or
#define NJOY 0

which defines the number of your devices in your kernel.

You must additionally add a slot to either cdevsw[], or to bdevsw[], depending on whether it is a character device or a block device, or both if it is a block device with a raw interface. The entry for the joystick driver is:


/* open, close, read, write, ioctl, stop, reset, ttys, select, mmap, strat */
struct cdevsw   cdevsw[] =
{
 ...
        { joyopen,      joyclose,       joyread,        nowrite,        /*51*/
          joyioctl,     nostop,         nullreset,      nodevtotty,/*joystick */
          seltrue,      nommap,         NULL},
 ...
}

Order is what determines the major number of your device. Which is why there will always be an entry for your driver, either null entry points, or actual entry points. It is probably worth noting that this is significantly different from SCO and other system V derivatives, where any device can (in theory) have any major number. This is largely a convenience on FreeBSD, due to the way device nodes are created. More on this later.


FreeBSD Device Driver Writer's Guide : Linking Into the Kernel. : Standard Model : Make room in conf.c
Previous: Adding to the driver list.
Next: Adding your device to the config file.
freebsd-questions@freebsd.org