PageRenderTime 41ms CodeModel.GetById 18ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/sparc/kernel/sunos_ioctl.c

https://bitbucket.org/evzijst/gittest
C | 231 lines | 191 code | 24 blank | 16 comment | 24 complexity | 22fe28e516c856f54551401bf57f77fe MD5 | raw file
  1/* $Id: sunos_ioctl.c,v 1.34 2000/09/03 14:10:56 anton Exp $
  2 * sunos_ioctl.c: The Linux Operating system: SunOS ioctl compatibility.
  3 * 
  4 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
  5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  6 */
  7
  8#include <asm/uaccess.h>
  9
 10#include <linux/sched.h>
 11#include <linux/errno.h>
 12#include <linux/string.h>
 13#include <linux/termios.h>
 14#include <linux/ioctl.h>
 15#include <linux/route.h>
 16#include <linux/sockios.h>
 17#include <linux/if.h>
 18#include <linux/netdevice.h>
 19#include <linux/if_arp.h>
 20#include <linux/fs.h>
 21#include <linux/mm.h>
 22#include <linux/smp.h>
 23#include <linux/smp_lock.h>
 24#include <linux/syscalls.h>
 25#include <linux/file.h>
 26#include <asm/kbio.h>
 27
 28#if 0
 29extern char sunkbd_type;
 30extern char sunkbd_layout;
 31#endif
 32
 33/* NR_OPEN is now larger and dynamic in recent kernels. */
 34#define SUNOS_NR_OPEN	256
 35
 36asmlinkage int sunos_ioctl (int fd, unsigned long cmd, unsigned long arg)
 37{
 38	int ret = -EBADF;
 39
 40	if (fd >= SUNOS_NR_OPEN || !fcheck(fd))
 41		goto out;
 42
 43	/* First handle an easy compat. case for tty ldisc. */
 44	if (cmd == TIOCSETD) {
 45		int __user *p;
 46		int ntty = N_TTY, tmp;
 47		mm_segment_t oldfs;
 48
 49		p = (int __user *) arg;
 50		ret = -EFAULT;
 51		if (get_user(tmp, p))
 52			goto out;
 53		if (tmp == 2) {
 54			oldfs = get_fs();
 55			set_fs(KERNEL_DS);
 56			ret = sys_ioctl(fd, cmd, (unsigned long) &ntty);
 57			set_fs(oldfs);
 58			ret = (ret == -EINVAL ? -EOPNOTSUPP : ret);
 59			goto out;
 60		}
 61	}
 62
 63	/* Binary compatibility is good American knowhow fuckin' up. */
 64	if (cmd == TIOCNOTTY) {
 65		ret = sys_setsid();
 66		goto out;
 67	}
 68
 69	/* SunOS networking ioctls. */
 70	switch (cmd) {
 71	case _IOW('r', 10, struct rtentry):
 72		ret = sys_ioctl(fd, SIOCADDRT, arg);
 73		goto out;
 74	case _IOW('r', 11, struct rtentry):
 75		ret = sys_ioctl(fd, SIOCDELRT, arg);
 76		goto out;
 77	case _IOW('i', 12, struct ifreq):
 78		ret = sys_ioctl(fd, SIOCSIFADDR, arg);
 79		goto out;
 80	case _IOWR('i', 13, struct ifreq):
 81		ret = sys_ioctl(fd, SIOCGIFADDR, arg);
 82		goto out;
 83	case _IOW('i', 14, struct ifreq):
 84		ret = sys_ioctl(fd, SIOCSIFDSTADDR, arg);
 85		goto out;
 86	case _IOWR('i', 15, struct ifreq):
 87		ret = sys_ioctl(fd, SIOCGIFDSTADDR, arg);
 88		goto out;
 89	case _IOW('i', 16, struct ifreq):
 90		ret = sys_ioctl(fd, SIOCSIFFLAGS, arg);
 91		goto out;
 92	case _IOWR('i', 17, struct ifreq):
 93		ret = sys_ioctl(fd, SIOCGIFFLAGS, arg);
 94		goto out;
 95	case _IOW('i', 18, struct ifreq):
 96		ret = sys_ioctl(fd, SIOCSIFMEM, arg);
 97		goto out;
 98	case _IOWR('i', 19, struct ifreq):
 99		ret = sys_ioctl(fd, SIOCGIFMEM, arg);
100		goto out;
101	case _IOWR('i', 20, struct ifconf):
102		ret = sys_ioctl(fd, SIOCGIFCONF, arg);
103		goto out;
104	case _IOW('i', 21, struct ifreq): /* SIOCSIFMTU */
105		ret = sys_ioctl(fd, SIOCSIFMTU, arg);
106		goto out;
107	case _IOWR('i', 22, struct ifreq): /* SIOCGIFMTU */
108		ret = sys_ioctl(fd, SIOCGIFMTU, arg);
109		goto out;
110
111	case _IOWR('i', 23, struct ifreq):
112		ret = sys_ioctl(fd, SIOCGIFBRDADDR, arg);
113		goto out;
114	case _IOW('i', 24, struct ifreq):
115		ret = sys_ioctl(fd, SIOCSIFBRDADDR, arg);
116		goto out;
117	case _IOWR('i', 25, struct ifreq):
118		ret = sys_ioctl(fd, SIOCGIFNETMASK, arg);
119		goto out;
120	case _IOW('i', 26, struct ifreq):
121		ret = sys_ioctl(fd, SIOCSIFNETMASK, arg);
122		goto out;
123	case _IOWR('i', 27, struct ifreq):
124		ret = sys_ioctl(fd, SIOCGIFMETRIC, arg);
125		goto out;
126	case _IOW('i', 28, struct ifreq):
127		ret = sys_ioctl(fd, SIOCSIFMETRIC, arg);
128		goto out;
129
130	case _IOW('i', 30, struct arpreq):
131		ret = sys_ioctl(fd, SIOCSARP, arg);
132		goto out;
133	case _IOWR('i', 31, struct arpreq):
134		ret = sys_ioctl(fd, SIOCGARP, arg);
135		goto out;
136	case _IOW('i', 32, struct arpreq):
137		ret = sys_ioctl(fd, SIOCDARP, arg);
138		goto out;
139
140	case _IOW('i', 40, struct ifreq): /* SIOCUPPER */
141	case _IOW('i', 41, struct ifreq): /* SIOCLOWER */
142	case _IOW('i', 44, struct ifreq): /* SIOCSETSYNC */
143	case _IOW('i', 45, struct ifreq): /* SIOCGETSYNC */
144	case _IOW('i', 46, struct ifreq): /* SIOCSSDSTATS */
145	case _IOW('i', 47, struct ifreq): /* SIOCSSESTATS */
146	case _IOW('i', 48, struct ifreq): /* SIOCSPROMISC */
147		ret = -EOPNOTSUPP;
148		goto out;
149
150	case _IOW('i', 49, struct ifreq):
151		ret = sys_ioctl(fd, SIOCADDMULTI, arg);
152		goto out;
153	case _IOW('i', 50, struct ifreq):
154		ret = sys_ioctl(fd, SIOCDELMULTI, arg);
155		goto out;
156
157	/* FDDI interface ioctls, unsupported. */
158		
159	case _IOW('i', 51, struct ifreq): /* SIOCFDRESET */
160	case _IOW('i', 52, struct ifreq): /* SIOCFDSLEEP */
161	case _IOW('i', 53, struct ifreq): /* SIOCSTRTFMWAR */
162	case _IOW('i', 54, struct ifreq): /* SIOCLDNSTRTFW */
163	case _IOW('i', 55, struct ifreq): /* SIOCGETFDSTAT */
164	case _IOW('i', 56, struct ifreq): /* SIOCFDNMIINT */
165	case _IOW('i', 57, struct ifreq): /* SIOCFDEXUSER */
166	case _IOW('i', 58, struct ifreq): /* SIOCFDGNETMAP */
167	case _IOW('i', 59, struct ifreq): /* SIOCFDGIOCTL */
168		printk("FDDI ioctl, returning EOPNOTSUPP\n");
169		ret = -EOPNOTSUPP;
170		goto out;
171
172	case _IOW('t', 125, int):
173		/* More stupid tty sunos ioctls, just
174		 * say it worked.
175		 */
176		ret = 0;
177		goto out;
178	/* Non posix grp */
179	case _IOW('t', 118, int): {
180		int oldval, newval, __user *ptr;
181
182		cmd = TIOCSPGRP;
183		ptr = (int __user *) arg;
184		ret = -EFAULT;
185		if (get_user(oldval, ptr))
186			goto out;
187		ret = sys_ioctl(fd, cmd, arg);
188		__get_user(newval, ptr);
189		if (newval == -1) {
190			__put_user(oldval, ptr);
191			ret = -EIO;
192		}
193		if (ret == -ENOTTY)
194			ret = -EIO;
195		goto out;
196	}
197
198	case _IOR('t', 119, int): {
199		int oldval, newval, __user *ptr;
200
201		cmd = TIOCGPGRP;
202		ptr = (int __user *) arg;
203		ret = -EFAULT;
204		if (get_user(oldval, ptr))
205			goto out;
206		ret = sys_ioctl(fd, cmd, arg);
207		__get_user(newval, ptr);
208		if (newval == -1) {
209			__put_user(oldval, ptr);
210			ret = -EIO;
211		}
212		if (ret == -ENOTTY)
213			ret = -EIO;
214		goto out;
215	}
216	}
217
218#if 0
219	if ((cmd & 0xff00) == ('k' << 8)) {
220		printk ("[[KBIO: %8.8x\n", (unsigned int) cmd);
221	}
222#endif
223
224	ret = sys_ioctl(fd, cmd, arg);
225	/* so stupid... */
226	ret = (ret == -EINVAL ? -EOPNOTSUPP : ret);
227out:
228	return ret;
229}
230
231