cdev.c revision 41681
141681Sdfr/* 08 Nov 1998*/ 241681Sdfr/* 341681Sdfr * cdev.c 441681Sdfr * 541681Sdfr * 08 Nov 1998 Rajesh Vaidheeswarran 641681Sdfr * 741681Sdfr * Copyright (c) 1998 Rajesh Vaidheeswarran 841681Sdfr * All rights reserved. 941681Sdfr * 1041681Sdfr * Redistribution and use in source and binary forms, with or without 1141681Sdfr * modification, are permitted provided that the following conditions 1241681Sdfr * are met: 1341681Sdfr * 1. Redistributions of source code must retain the above copyright 1441681Sdfr * notice, this list of conditions and the following disclaimer. 1541681Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1641681Sdfr * notice, this list of conditions and the following disclaimer in the 1741681Sdfr * documentation and/or other materials provided with the distribution. 1841681Sdfr * 3. All advertising materials mentioning features or use of this software 1941681Sdfr * must display the following acknowledgement: 2041681Sdfr * This product includes software developed by Rajesh Vaidheeswarran. 2141681Sdfr * 4. The name Rajesh Vaidheeswarran may not be used to endorse or promote 2241681Sdfr * products derived from this software without specific prior written 2341681Sdfr * permission. 2441681Sdfr * 2541681Sdfr * THIS SOFTWARE IS PROVIDED BY RAJESH VAIDHEESWARRAN ``AS IS'' AND ANY 2641681Sdfr * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2741681Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2841681Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE RAJESH VAIDHEESWARRAN BE LIABLE 2941681Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3041681Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3141681Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3241681Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3341681Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3441681Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3541681Sdfr * SUCH DAMAGE. 3641681Sdfr * 3741681Sdfr * Copyright (c) 1993 Terrence R. Lambert. 3841681Sdfr * All rights reserved. 3941681Sdfr * 4041681Sdfr * Redistribution and use in source and binary forms, with or without 4141681Sdfr * modification, are permitted provided that the following conditions 4241681Sdfr * are met: 4341681Sdfr * 1. Redistributions of source code must retain the above copyright 4441681Sdfr * notice, this list of conditions and the following disclaimer. 4541681Sdfr * 2. Redistributions in binary form must reproduce the above copyright 4641681Sdfr * notice, this list of conditions and the following disclaimer in the 4741681Sdfr * documentation and/or other materials provided with the distribution. 4841681Sdfr * 3. All advertising materials mentioning features or use of this software 4941681Sdfr * must display the following acknowledgement: 5041681Sdfr * This product includes software developed by Terrence R. Lambert. 5141681Sdfr * 4. The name Terrence R. Lambert may not be used to endorse or promote 5241681Sdfr * products derived from this software without specific prior written 5341681Sdfr * permission. 5441681Sdfr * 5541681Sdfr * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY 5641681Sdfr * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5741681Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5841681Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE 5941681Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 6041681Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 6141681Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 6241681Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 6341681Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 6441681Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 6541681Sdfr * SUCH DAMAGE. 6641681Sdfr * 6741681Sdfr */ 6841681Sdfr#include <sys/param.h> 6941681Sdfr#include <sys/systm.h> 7041681Sdfr#include <sys/ioccom.h> 7141681Sdfr#include "cdev.h" 7241681Sdfr 7341681Sdfr/* 7441681Sdfr * This is the actual code for the system call... it can't be static because 7541681Sdfr * it is exported to another part of the module... the only place it needs 7641681Sdfr * to be referenced is the sysent we are interested in. 7741681Sdfr * 7841681Sdfr * To write your own system call using this as a template, you could strip 7941681Sdfr * out this code and use the rest as a prototype module, changing only the 8041681Sdfr * function names and the number of arguments to the call in the module 8141681Sdfr * specific "sysent". 8241681Sdfr * 8341681Sdfr * You would have to use the "-R" option of "ld" to ensure a linkable file 8441681Sdfr * if you were to do this, since you would need to combine multiple ".o" 8541681Sdfr * files into a single ".o" file for use by "modload". 8641681Sdfr */ 8741681Sdfr 8841681Sdfr#define CDEV_IOCTL1 _IOR('C', 1, u_int) 8941681Sdfr 9041681Sdfrint 9141681Sdfrmydev_open(dev_t dev, int flag, int otyp, struct proc *procp) 9241681Sdfr{ 9341681Sdfr printf("mydev_open: dev_t=%d, flag=%x, otyp=%x, procp=%p\n", 9441681Sdfr dev, flag, otyp, procp); 9541681Sdfr return (0); 9641681Sdfr} 9741681Sdfr 9841681Sdfrint 9941681Sdfrmydev_close(dev_t dev, int flag, int otyp, struct proc *procp) 10041681Sdfr{ 10141681Sdfr printf("mydev_close: dev_t=%d, flag=%x, otyp=%x, procp=%p\n", 10241681Sdfr dev, flag, otyp, procp); 10341681Sdfr return (0); 10441681Sdfr} 10541681Sdfr 10641681Sdfrint 10741681Sdfrmydev_ioctl(dev_t dev, u_long cmd, caddr_t arg, int mode, struct proc *procp) 10841681Sdfr{ 10941681Sdfr int error = 0; 11041681Sdfr 11141681Sdfr printf("mydev_ioctl: dev_t=%d, cmd=%lx, arg=%p, mode=%x procp=%p\n", 11241681Sdfr dev, cmd, arg, mode, procp); 11341681Sdfr 11441681Sdfr switch(cmd) { 11541681Sdfr case CDEV_IOCTL1: 11641681Sdfr printf("you called mydev_ioctl CDEV_IOCTL1\n"); 11741681Sdfr break; 11841681Sdfr default: 11941681Sdfr printf("No such ioctl for me!\n"); 12041681Sdfr error = EINVAL; 12141681Sdfr break; 12241681Sdfr } 12341681Sdfr return error; 12441681Sdfr} 125