struct cdevsw {
int (*d_open) __P((dev_t dev, int oflags, int devtype,
struct proc *p));
int (*d_close) __P((dev_t dev, int fflag, int devtype,
struct proc *));
int (*d_read) __P((dev_t dev, struct uio *uio, int ioflag));
int (*d_write) __P((dev_t dev, struct uio *uio, int ioflag));
int (*d_ioctl) __P((dev_t dev, int cmd, caddr_t data,
int fflag, struct proc *p));
int (*d_stop) __P((struct tty *tp, int rw));
int (*d_reset) __P((int uban)); /* XXX */
struct tty *d_ttys;
int (*d_select) __P((dev_t dev, int which, struct proc *p));
int (*d_mmap) __P(());
int (*d_strategy) __P((struct buf *bp));
};
/*
* Called to initialize our device,
* and to register ourselves with devfs
*/
void
random_init(void)
{
int ret;
if (gRandomInstalled)
return;
/* install us in the file system */
gRandomInstalled = 1;
/* setup yarrow and the mutex */
PreliminarySetup();
ret = cdevsw_add(RANDOM_MAJOR, &random_cdevsw);
if (ret < 0) {
printf("random_init: failed to allocate a major number!\n");
gRandomInstalled = 0;
return;
}
devfs_make_node(makedev (ret, 0), DEVFS_CHAR,
UID_ROOT, GID_WHEEL, 0666, "random", 0);
/*
* also make urandom
* (which is exactly the same thing in our context)
*/
devfs_make_node(makedev (ret, 1), DEVFS_CHAR,
UID_ROOT, GID_WHEEL, 0666, "urandom", 0);
}
......
if (kernel_thread_start(pf_purge_thread_fn, NULL,
&pf_purge_thread) != 0) {
printf("%s: unable to start purge thread!", __func__);
return;
}
maj = cdevsw_add(PF_CDEV_MAJOR, &pf_cdevsw);
if (maj == -1) {
printf("%s: failed to allocate major number!\n", __func__);
return;
}
(void) devfs_make_node(makedev(maj, 0), DEVFS_CHAR,
UID_ROOT, GID_WHEEL, 0600, "pf", 0);
......
/dev/ptmx:
int
ptmx_init( __unused int config_count)
{
/*
* We start looking at slot 10, since there are inits that will
* stomp explicit slots (e.g. vndevice stomps 1) below that.
*/
/* Get a major number for /dev/ptmx */
if((ptmx_major = cdevsw_add(-15, &ptmx_cdev)) == -1) {
printf("ptmx_init: failed to obtain /dev/ptmx major number\n");
return (ENOENT);
}
if (cdevsw_setkqueueok(ptmx_major, &ptmx_cdev, 0) == -1) {
panic("Failed to set flags on ptmx cdevsw entry.");
}
/* Get a major number for /dev/pts/nnn */
if ((ptsd_major = cdevsw_add(-15, &ptsd_cdev)) == -1) {
(void)cdevsw_remove(ptmx_major, &ptmx_cdev);
printf("ptmx_init: failed to obtain /dev/ptmx major number\n");
return (ENOENT);
}
if (cdevsw_setkqueueok(ptsd_major, &ptsd_cdev, 0) == -1) {
panic("Failed to set flags on ptmx cdevsw entry.");
}
/*
* Locks to guard against races between revoke and kevents
*/
ptsd_kevent_lock_init();
/* Create the /dev/ptmx device {<major>,0} */
(void)devfs_make_node_clone(makedev(ptmx_major, 0),
DEVFS_CHAR, UID_ROOT, GID_TTY, 0666,
ptmx_clone, PTMX_TEMPLATE);
return (0);
}