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