summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpooka <pooka@NetBSD.org>2007-11-22 11:28:48 +0000
committerpooka <pooka@NetBSD.org>2007-11-22 11:28:48 +0000
commita4b032e2c8dedbb826547920ffe49398315801c3 (patch)
treec870df4ee3fc08022636618356bd933945e28567
parent2bde3fa647019bc1a6bbec14ec01a95f70f26d4e (diff)
quick & dirty support & tests for ioctl
-rw-r--r--share/examples/pud/intro/common.h4
-rw-r--r--share/examples/pud/intro/doioctl.c33
-rw-r--r--share/examples/pud/intro/intro.c42
3 files changed, 75 insertions, 4 deletions
diff --git a/share/examples/pud/intro/common.h b/share/examples/pud/intro/common.h
new file mode 100644
index 00000000000..1a3e11faa8b
--- /dev/null
+++ b/share/examples/pud/intro/common.h
@@ -0,0 +1,4 @@
+#include <sys/ioctl.h>
+
+#define INTROTOGGLE _IOWR('i', 1, int)
+#define INTROTOGGLE_R _IOW('i', 2, int)
diff --git a/share/examples/pud/intro/doioctl.c b/share/examples/pud/intro/doioctl.c
new file mode 100644
index 00000000000..5016f8e7989
--- /dev/null
+++ b/share/examples/pud/intro/doioctl.c
@@ -0,0 +1,33 @@
+/* $NetBSD: doioctl.c,v 1.1 2007/11/22 11:28:48 pooka Exp $ */
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+
+#include "common.h"
+
+int
+main(int argc, char *argv[])
+{
+ int fd, i;
+
+ if (argc != 3 && argc != 4)
+ errx(1, "args");
+
+ fd = open(argv[1], O_RDWR);
+ if (fd == -1)
+ err(1, "open");
+
+ i = atoi(argv[2]);
+
+ if (argc == 3)
+ if (ioctl(fd, INTROTOGGLE, &i) == -1)
+ err(1, "ioctl");
+ else
+ if (ioctl(fd, INTROTOGGLE_R, &i) == -1)
+ err(1, "ioctl");
+
+ printf("i is now %d\n", i);
+}
diff --git a/share/examples/pud/intro/intro.c b/share/examples/pud/intro/intro.c
index 06f851c19b9..3b0cdf73f78 100644
--- a/share/examples/pud/intro/intro.c
+++ b/share/examples/pud/intro/intro.c
@@ -1,4 +1,4 @@
-/* $NetBSD: intro.c,v 1.2 2007/11/21 18:11:17 pooka Exp $ */
+/* $NetBSD: intro.c,v 1.3 2007/11/22 11:28:49 pooka Exp $ */
/*
* El extra-simplo example of the userspace driver framework.
@@ -27,8 +27,14 @@
#include <string.h>
#include <unistd.h>
+#include "common.h"
+
#define DEFALLOC 1024*1024
-#define ECHOSTR "Would you like some sauce diable with that?\n"
+#define ECHOSTR1 "Would you like some sauce diable with that?\n"
+#define ECHOSTR2 "Nej tack, you fool, I'm happy with my tournedos Rossini\n"
+#define NSTR 2
+
+const char *curstr = ECHOSTR1;
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
@@ -93,8 +99,8 @@ main(int argc, char *argv[])
(unsigned long long)pc_read->pm_offset,
pc_read->pm_resid);
- clen = MIN(strlen(ECHOSTR), pc_read->pm_resid);
- strncpy(pc_read->pm_data, ECHOSTR, clen);
+ clen = MIN(strlen(curstr), pc_read->pm_resid);
+ strncpy(pc_read->pm_data, curstr, clen);
if (pdr->pdr_reqclass == PUD_REQ_BDEV) {
clen = pc_read->pm_resid;
pc_read->pm_resid = 0;
@@ -124,6 +130,34 @@ main(int argc, char *argv[])
}
break;
+ case PUD_CDEV_IOCTL:
+ {
+ struct pud_req_ioctl *pc_ioctl;
+ int *iocval;
+
+ pc_ioctl = (void *)pdr;
+ switch (pc_ioctl->pm_iocmd) {
+ case INTROTOGGLE:
+ case INTROTOGGLE_R:
+ iocval = (int *)pc_ioctl->pm_data;
+ if (*iocval < 0 || *iocval > 2) {
+ pdr->pdr_rv = ERANGE;
+ break;
+ }
+
+ if (*iocval == 1)
+ curstr = ECHOSTR1;
+ else
+ curstr = ECHOSTR2;
+
+ *iocval = 0;
+ break;
+ default:
+ abort();
+ }
+ }
+ break;
+
default:
abort();
}