DragonFly BSD
DragonFly submit List (threaded) for 2005-03
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

PATCH src/share/examples/kld/cdev/module


From: Chuck Tuffli <chuck_tuffli@xxxxxxxxxxx>
Date: Fri, 18 Mar 2005 11:57:48 -0800

In trying to figure out what was going on with my driver, I ported the
character device example to work with DFly.

-- 
Chuck Tuffli
Agilent Technologies
? cdev_module.patch
Index: cdev.c
===================================================================
RCS file: /home/dcvs/src/share/examples/kld/cdev/module/cdev.c,v
retrieving revision 1.2
diff -u -r1.2 cdev.c
--- cdev.c	17 Jun 2003 04:36:57 -0000	1.2
+++ cdev.c	18 Mar 2005 19:52:06 -0000
@@ -69,12 +69,12 @@
  * $DragonFly: src/share/examples/kld/cdev/module/cdev.c,v 1.1 2003/06/16 05:27:37 dillon Exp $
  */
 #include <sys/types.h>
-#include <sys/uio.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/ioccom.h>
 #include <sys/systm.h>
 #include <sys/conf.h>
+#include <sys/uio.h>
 
 #include "cdev.h"
 
@@ -100,30 +100,30 @@
 static int len;
 
 int
-mydev_open(dev_t dev, int flag, int otyp, struct proc *procp)
+mydev_open(dev_t dev, int flag, int otyp, d_thread_t *td)
 {
-    printf("mydev_open: dev_t=%d, flag=%x, otyp=%x, procp=%p\n",
-	   dev2udev(dev), flag, otyp, procp);
+    printf("mydev_open: dev_t=%d, flag=%x, otyp=%x, td=%p\n",
+	   dev2udev(dev), flag, otyp, td);
     memset(&buf, '\0', 513);
     len = 0;
     return (0);
 }
 
 int
-mydev_close(dev_t dev, int flag, int otyp, struct proc *procp)
+mydev_close(dev_t dev, int flag, int otyp, d_thread_t *td)
 {
-    printf("mydev_close: dev_t=%d, flag=%x, otyp=%x, procp=%p\n",
-	      dev2udev(dev), flag, otyp, procp);
+    printf("mydev_close: dev_t=%d, flag=%x, otyp=%x, td=%p\n",
+	      dev2udev(dev), flag, otyp, td);
     return (0);
 }
 
 int
-mydev_ioctl(dev_t dev, u_long cmd, caddr_t arg, int mode, struct proc *procp)
+mydev_ioctl(dev_t dev, u_long cmd, caddr_t arg, int mode, d_thread_t *td)
 {
     int error = 0;
 
-    printf("mydev_ioctl: dev_t=%d, cmd=%lx, arg=%p, mode=%x procp=%p\n",
-	   dev2udev(dev), cmd, arg, mode, procp);
+    printf("mydev_ioctl: dev_t=%d, cmd=%lx, arg=%p, mode=%x td=%p\n",
+	   dev2udev(dev), cmd, arg, mode, td);
 
     switch(cmd) {
     case CDEV_IOCTL1:
Index: cdevmod.c
===================================================================
RCS file: /home/dcvs/src/share/examples/kld/cdev/module/cdevmod.c,v
retrieving revision 1.2
diff -u -r1.2 cdevmod.c
--- cdevmod.c	17 Jun 2003 04:36:57 -0000	1.2
+++ cdevmod.c	18 Mar 2005 19:52:06 -0000
@@ -79,6 +79,12 @@
 #define CDEV_MAJOR 32
 
 static struct cdevsw my_devsw = {
+	/* name */	"cdev",
+	/* maj */	CDEV_MAJOR,
+	/* flags */	D_TTY,
+	/* port */	NULL,
+	/* clone */	NULL,
+
 	/* open */	mydev_open,
 	/* close */	mydev_close,
 	/* read */	mydev_read,
@@ -87,11 +93,8 @@
 	/* poll */	nopoll,
 	/* mmap */	nommap,
 	/* strategy */	nostrategy,
-	/* name */	"cdev",
-	/* maj */	CDEV_MAJOR,
 	/* dump */	nodump,
 	/* psize */	nopsize,
-	/* flags */	D_TTY,
 	/* bmaj */	-1
 };
 
@@ -128,12 +131,13 @@
 	printf("Copyright (c) 1998\n");
 	printf("Rajesh Vaidheeswarran\n");
 	printf("All rights reserved\n");
+	cdevsw_add(&my_devsw, 0, 0);
 	sdev = make_dev(&my_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "cdev");
 	break;		/* Success*/
 
     case MOD_UNLOAD:
 	printf("Unloaded kld character device driver\n");
-	destroy_dev(sdev);
+	cdevsw_remove(&my_devsw, 0, 0);
 	break;		/* Success*/
 
     default:	/* we only understand load/unload*/


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]