diff options
author | sobomax <sobomax@FreeBSD.org> | 2000-10-02 14:14:07 +0000 |
---|---|---|
committer | sobomax <sobomax@FreeBSD.org> | 2000-10-02 14:14:07 +0000 |
commit | ca9093b327311b17a6c77820abb0c66abf6a94f4 (patch) | |
tree | b7b5dd86df52d6d28fcd6420e78651ff948cf748 /share/examples/kld/cdev/test | |
parent | f35f4e93b21d23ac9951fb2a706ba5bb5c2bd00a (diff) | |
download | FreeBSD-src-ca9093b327311b17a6c77820abb0c66abf6a94f4.zip FreeBSD-src-ca9093b327311b17a6c77820abb0c66abf6a94f4.tar.gz |
Fix cdev kld example after it has been broken for year or so. Also extend list
of supported operations by example read() and write() operations.
Inspired by: http://www.daemonnews.org/200010/blueprints.html
PR: 16173
Submitted by: sobomax
Diffstat (limited to 'share/examples/kld/cdev/test')
-rw-r--r-- | share/examples/kld/cdev/test/Makefile | 2 | ||||
-rw-r--r-- | share/examples/kld/cdev/test/testcdev.c | 26 |
2 files changed, 26 insertions, 2 deletions
diff --git a/share/examples/kld/cdev/test/Makefile b/share/examples/kld/cdev/test/Makefile index 001fde1..2ca3d21 100644 --- a/share/examples/kld/cdev/test/Makefile +++ b/share/examples/kld/cdev/test/Makefile @@ -87,6 +87,6 @@ unload: @echo "has been successfully unloaded by building 'unload' in" @echo "the 'module' subdirectory." @echo - ${MODSTAT} -n misc_mod + ${MODSTAT} -n cdev .include <bsd.prog.mk> diff --git a/share/examples/kld/cdev/test/testcdev.c b/share/examples/kld/cdev/test/testcdev.c index e43df97..8f2c0b3 100644 --- a/share/examples/kld/cdev/test/testcdev.c +++ b/share/examples/kld/cdev/test/testcdev.c @@ -67,21 +67,28 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * + * + * $FreeBSD$ */ #include <stdio.h> #include <fcntl.h> +#include <string.h> #include <sys/ioccom.h> #define CDEV_IOCTL1 _IOR('C', 1, u_int) #define CDEV_DEVICE "cdev" +static char writestr[] = "Hello kernel!"; +static char buf[512+1]; + int main(int argc, char *argv[]) { int kernel_fd; int one; + int len; - if ((kernel_fd = open("/dev/" CDEV_DEVICE, O_RDONLY)) == -1) { + if ((kernel_fd = open("/dev/" CDEV_DEVICE, O_RDWR)) == -1) { perror("/dev/" CDEV_DEVICE); exit(1); } @@ -92,5 +99,22 @@ main(int argc, char *argv[]) } else { printf( "Sent ioctl CDEV_IOCTL1 to device /dev/" CDEV_DEVICE "\n"); } + + len = strlen(writestr) + 1; + + /* Write operation */ + if (write(kernel_fd, writestr, len) == -1) { + perror("write()"); + } else { + printf("Written \"%s\" string to device /dev/" CDEV_DEVICE "\n", writestr); + } + + /* Read operation */ + if (read(kernel_fd, buf, len) == -1) { + perror("read()"); + } else { + printf("Read \"%s\" string from device /dev/" CDEV_DEVICE "\n", buf); + } + exit(0); } |