1*abbcaa0aSDoug Rabson /* 08 Nov 1998*/
2*abbcaa0aSDoug Rabson /*
3*abbcaa0aSDoug Rabson  * cdev.c
4*abbcaa0aSDoug Rabson  *
5*abbcaa0aSDoug Rabson  * 08 Nov 1998	Rajesh Vaidheeswarran
6*abbcaa0aSDoug Rabson  *
7*abbcaa0aSDoug Rabson  * Copyright (c) 1998 Rajesh Vaidheeswarran
8*abbcaa0aSDoug Rabson  * All rights reserved.
9*abbcaa0aSDoug Rabson  *
10*abbcaa0aSDoug Rabson  * Redistribution and use in source and binary forms, with or without
11*abbcaa0aSDoug Rabson  * modification, are permitted provided that the following conditions
12*abbcaa0aSDoug Rabson  * are met:
13*abbcaa0aSDoug Rabson  * 1. Redistributions of source code must retain the above copyright
14*abbcaa0aSDoug Rabson  *    notice, this list of conditions and the following disclaimer.
15*abbcaa0aSDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
16*abbcaa0aSDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
17*abbcaa0aSDoug Rabson  *    documentation and/or other materials provided with the distribution.
18*abbcaa0aSDoug Rabson  * 3. All advertising materials mentioning features or use of this software
19*abbcaa0aSDoug Rabson  *    must display the following acknowledgement:
20*abbcaa0aSDoug Rabson  *      This product includes software developed by Rajesh Vaidheeswarran.
21*abbcaa0aSDoug Rabson  * 4. The name Rajesh Vaidheeswarran may not be used to endorse or promote
22*abbcaa0aSDoug Rabson  *    products derived from this software without specific prior written
23*abbcaa0aSDoug Rabson  *    permission.
24*abbcaa0aSDoug Rabson  *
25*abbcaa0aSDoug Rabson  * THIS SOFTWARE IS PROVIDED BY RAJESH VAIDHEESWARRAN ``AS IS'' AND ANY
26*abbcaa0aSDoug Rabson  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27*abbcaa0aSDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28*abbcaa0aSDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE RAJESH VAIDHEESWARRAN BE LIABLE
29*abbcaa0aSDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30*abbcaa0aSDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31*abbcaa0aSDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32*abbcaa0aSDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33*abbcaa0aSDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34*abbcaa0aSDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35*abbcaa0aSDoug Rabson  * SUCH DAMAGE.
36*abbcaa0aSDoug Rabson  *
37*abbcaa0aSDoug Rabson   * Copyright (c) 1993 Terrence R. Lambert.
38*abbcaa0aSDoug Rabson  * All rights reserved.
39*abbcaa0aSDoug Rabson  *
40*abbcaa0aSDoug Rabson  * Redistribution and use in source and binary forms, with or without
41*abbcaa0aSDoug Rabson  * modification, are permitted provided that the following conditions
42*abbcaa0aSDoug Rabson  * are met:
43*abbcaa0aSDoug Rabson  * 1. Redistributions of source code must retain the above copyright
44*abbcaa0aSDoug Rabson  *    notice, this list of conditions and the following disclaimer.
45*abbcaa0aSDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
46*abbcaa0aSDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
47*abbcaa0aSDoug Rabson  *    documentation and/or other materials provided with the distribution.
48*abbcaa0aSDoug Rabson  * 3. All advertising materials mentioning features or use of this software
49*abbcaa0aSDoug Rabson  *    must display the following acknowledgement:
50*abbcaa0aSDoug Rabson  *      This product includes software developed by Terrence R. Lambert.
51*abbcaa0aSDoug Rabson  * 4. The name Terrence R. Lambert may not be used to endorse or promote
52*abbcaa0aSDoug Rabson  *    products derived from this software without specific prior written
53*abbcaa0aSDoug Rabson  *    permission.
54*abbcaa0aSDoug Rabson  *
55*abbcaa0aSDoug Rabson  * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY
56*abbcaa0aSDoug Rabson  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57*abbcaa0aSDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58*abbcaa0aSDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
59*abbcaa0aSDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60*abbcaa0aSDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61*abbcaa0aSDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62*abbcaa0aSDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63*abbcaa0aSDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64*abbcaa0aSDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65*abbcaa0aSDoug Rabson  * SUCH DAMAGE.
66*abbcaa0aSDoug Rabson  *
67*abbcaa0aSDoug Rabson  */
68*abbcaa0aSDoug Rabson #include <sys/param.h>
69*abbcaa0aSDoug Rabson #include <sys/systm.h>
70*abbcaa0aSDoug Rabson #include <sys/ioccom.h>
71*abbcaa0aSDoug Rabson #include "cdev.h"
72*abbcaa0aSDoug Rabson 
73*abbcaa0aSDoug Rabson /*
74*abbcaa0aSDoug Rabson  * This is the actual code for the system call... it can't be static because
75*abbcaa0aSDoug Rabson  * it is exported to another part of the module... the only place it needs
76*abbcaa0aSDoug Rabson  * to be referenced is the sysent we are interested in.
77*abbcaa0aSDoug Rabson  *
78*abbcaa0aSDoug Rabson  * To write your own system call using this as a template, you could strip
79*abbcaa0aSDoug Rabson  * out this code and use the rest as a prototype module, changing only the
80*abbcaa0aSDoug Rabson  * function names and the number of arguments to the call in the module
81*abbcaa0aSDoug Rabson  * specific "sysent".
82*abbcaa0aSDoug Rabson  *
83*abbcaa0aSDoug Rabson  * You would have to use the "-R" option of "ld" to ensure a linkable file
84*abbcaa0aSDoug Rabson  * if you were to do this, since you would need to combine multiple ".o"
85*abbcaa0aSDoug Rabson  * files into a single ".o" file for use by "modload".
86*abbcaa0aSDoug Rabson  */
87*abbcaa0aSDoug Rabson 
88*abbcaa0aSDoug Rabson #define CDEV_IOCTL1         _IOR('C', 1, u_int)
89*abbcaa0aSDoug Rabson 
90*abbcaa0aSDoug Rabson int
91*abbcaa0aSDoug Rabson mydev_open(dev_t dev, int flag, int otyp, struct proc *procp)
92*abbcaa0aSDoug Rabson {
93*abbcaa0aSDoug Rabson     printf("mydev_open: dev_t=%d, flag=%x, otyp=%x, procp=%p\n",
94*abbcaa0aSDoug Rabson 	   dev, flag, otyp, procp);
95*abbcaa0aSDoug Rabson     return (0);
96*abbcaa0aSDoug Rabson }
97*abbcaa0aSDoug Rabson 
98*abbcaa0aSDoug Rabson int
99*abbcaa0aSDoug Rabson mydev_close(dev_t dev, int flag, int otyp, struct proc *procp)
100*abbcaa0aSDoug Rabson {
101*abbcaa0aSDoug Rabson     printf("mydev_close: dev_t=%d, flag=%x, otyp=%x, procp=%p\n",
102*abbcaa0aSDoug Rabson 	      dev, flag, otyp, procp);
103*abbcaa0aSDoug Rabson     return (0);
104*abbcaa0aSDoug Rabson }
105*abbcaa0aSDoug Rabson 
106*abbcaa0aSDoug Rabson int
107*abbcaa0aSDoug Rabson mydev_ioctl(dev_t dev, u_long cmd, caddr_t arg, int mode, struct proc *procp)
108*abbcaa0aSDoug Rabson {
109*abbcaa0aSDoug Rabson     int error = 0;
110*abbcaa0aSDoug Rabson 
111*abbcaa0aSDoug Rabson     printf("mydev_ioctl: dev_t=%d, cmd=%lx, arg=%p, mode=%x procp=%p\n",
112*abbcaa0aSDoug Rabson 	   dev, cmd, arg, mode, procp);
113*abbcaa0aSDoug Rabson 
114*abbcaa0aSDoug Rabson     switch(cmd) {
115*abbcaa0aSDoug Rabson     case CDEV_IOCTL1:
116*abbcaa0aSDoug Rabson 	printf("you called mydev_ioctl CDEV_IOCTL1\n");
117*abbcaa0aSDoug Rabson 	break;
118*abbcaa0aSDoug Rabson     default:
119*abbcaa0aSDoug Rabson 	printf("No such ioctl for me!\n");
120*abbcaa0aSDoug Rabson 	error = EINVAL;
121*abbcaa0aSDoug Rabson 	break;
122*abbcaa0aSDoug Rabson     }
123*abbcaa0aSDoug Rabson     return error;
124*abbcaa0aSDoug Rabson }
125