|
OpenBSD可加载内核模块编程完全指南(12) (dev_type_stop((*))) lkmenodev, 0, (dev_type_select((*))) lkmenodev, (dev_type_mmap((*))) lkmenodev }
#endif /* _KERNEL */
Now this is the program we'll use to test (chardevtest.c): #include <sys/types.h> #include <sys/ioctl.h>
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <err.h>
#include "common.h"
int main(void) { struct ourdev_io a; int error, fd;
fd = open("/dev/ourdev", O_WRONLY); if (fd == -1) err(1, "open");
error = ioctl(fd, ODREAD, &a); if (error == -1) err(1, "ioctl");
printf("%d %s", a.value, a.msg); bzero(a.msg, MAXMSGLEN);
strlcpy(a.msg, "cowsn", sizeof(a.msg)); a.value = 42;
error = ioctl(fd, ODWRITE, &a); if (error == -1) err(1, "ioctl");
bzero(&a, sizeof(struct ourdev_io));
|