在freebsd 6.1 release的/usr/share/example/kld/cdev/module下的cdevmod.c有一个结构:
引用:static struct cdevsw my_devsw = {
/* version */ .d_version = D_VERSION,
/* open */ .d_open = mydev_open,
/* close */ .d_close = mydev_close,
/* read */ .d_read = mydev_read,
/* write */ .d_write = mydev_write,
/* ioctl */ .d_ioctl = mydev_ioctl,
/* name */ .d_name = "cdev",
/* maj */ .d_maj = CDEV_MAJOR
};
在make时会发现,这个结构的d_maj没有定义。这个结构的定义在/usr/include/sys/conf.h中:
引用:struct cdevsw {
int d_version;
u_int d_flags;
const char *d_name;
d_open_t *d_open;
d_fdopen_t *d_fdopen;
d_close_t *d_close;
d_read_t *d_read;
d_write_t *d_write;
d_ioctl_t *d_ioctl;
d_poll_t *d_poll;
d_mmap_t *d_mmap;
d_strategy_t *d_strategy;
dumper_t *d_dump;
d_kqfilter_t *d_kqfilter;
d_purge_t *d_purge;
d_spare2_t *d_spare2;
uid_t d_uid;
gid_t d_gid;
mode_t d_mode;
const char *d_kind;
/* These fields should not be messed with by drivers */
LIST_ENTRY(cdevsw) d_list;
LIST_HEAD(, cdev) d_devs;
int d_spare3;
struct cdevsw *d_gianttrick;
};
显然,找不到d_maj的定义。如果想make通过,简单的方法就是去掉d_maj的赋值。修改cdevmod.c中的代码为这样:
引用:static struct cdevsw my_devsw = {
/* version */ .d_version = D_VERSION,
/* open */ .d_open = mydev_open,
/* close */ .d_close = mydev_close,
/* read */ .d_read = mydev_read,
/* write */ .d_write = mydev_write,
/* ioctl */ .d_ioctl = mydev_ioctl,
/* name */ .d_name = "cdev",
/* maj */ //.d_maj = CDEV_MAJOR
};
然后,make load来load这个module,make unload来unload这个module。也可以在../test目录下make并运行测试程序试试。注意所有的module里面的输出都得用dmesg命令查看。