* better
[mascara-docs.git] / i386 / linux-2.3.21 / arch / sparc64 / kernel / sunos_ioctl32.c
blobd32ea68c2d335de3183a146f3ec7a49e77a12c29
1 /* $Id: sunos_ioctl32.c,v 1.10 1998/08/15 20:42:46 davem Exp $
2 * sunos_ioctl32.c: SunOS ioctl compatability on sparc64.
4 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
5 * Copyright (C) 1995, 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
6 */
8 #include <asm/uaccess.h>
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/file.h>
22 #include <linux/mm.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <asm/kbio.h>
27 /* Use this to get at 32-bit user passed pointers. */
28 #define A(__x) \
29 ({ unsigned long __ret; \
30 __asm__ ("srl %0, 0, %0" \
31 : "=r" (__ret) \
32 : "0" (__x)); \
33 __ret; \
36 #define SUNOS_NR_OPEN 256
38 struct rtentry32 {
39 u32 rt_pad1;
40 struct sockaddr rt_dst; /* target address */
41 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
42 struct sockaddr rt_genmask; /* target network mask (IP) */
43 unsigned short rt_flags;
44 short rt_pad2;
45 u32 rt_pad3;
46 unsigned char rt_tos;
47 unsigned char rt_class;
48 short rt_pad4;
49 short rt_metric; /* +1 for binary compatibility! */
50 /* char * */ u32 rt_dev; /* forcing the device at add */
51 u32 rt_mtu; /* per route MTU/Window */
52 u32 rt_window; /* Window clamping */
53 unsigned short rt_irtt; /* Initial RTT */
57 struct ifmap32 {
58 u32 mem_start;
59 u32 mem_end;
60 unsigned short base_addr;
61 unsigned char irq;
62 unsigned char dma;
63 unsigned char port;
66 struct ifreq32 {
67 #define IFHWADDRLEN 6
68 #define IFNAMSIZ 16
69 union {
70 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
71 } ifr_ifrn;
72 union {
73 struct sockaddr ifru_addr;
74 struct sockaddr ifru_dstaddr;
75 struct sockaddr ifru_broadaddr;
76 struct sockaddr ifru_netmask;
77 struct sockaddr ifru_hwaddr;
78 short ifru_flags;
79 int ifru_ivalue;
80 int ifru_mtu;
81 struct ifmap32 ifru_map;
82 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
83 __kernel_caddr_t32 ifru_data;
84 } ifr_ifru;
87 struct ifconf32 {
88 int ifc_len; /* size of buffer */
89 __kernel_caddr_t32 ifcbuf;
92 extern asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
94 extern asmlinkage int sys32_ioctl(unsigned int, unsigned int, u32);
95 extern asmlinkage int sys_setsid(void);
97 asmlinkage int sunos_ioctl (int fd, u32 cmd, u32 arg)
99 int ret = -EBADF;
101 lock_kernel();
102 if(fd >= SUNOS_NR_OPEN)
103 goto out;
104 if(!fcheck(fd))
105 goto out;
107 if(cmd == TIOCSETD) {
108 mm_segment_t old_fs = get_fs();
109 int *p, ntty = N_TTY;
110 int tmp;
112 p = (int *)A(arg);
113 ret = -EFAULT;
114 if(get_user(tmp, p))
115 goto out;
116 if(tmp == 2) {
117 set_fs(KERNEL_DS);
118 ret = sys_ioctl(fd, cmd, (unsigned long) &ntty);
119 set_fs(old_fs);
120 ret = (ret == -EINVAL ? -EOPNOTSUPP : ret);
121 goto out;
124 if(cmd == TIOCNOTTY) {
125 ret = sys_setsid();
126 goto out;
128 switch(cmd) {
129 case _IOW('r', 10, struct rtentry32):
130 ret = sys32_ioctl(fd, SIOCADDRT, arg);
131 goto out;
132 case _IOW('r', 11, struct rtentry32):
133 ret = sys32_ioctl(fd, SIOCDELRT, arg);
134 goto out;
136 case _IOW('i', 12, struct ifreq32):
137 ret = sys32_ioctl(fd, SIOCSIFADDR, arg);
138 goto out;
139 case _IOWR('i', 13, struct ifreq32):
140 ret = sys32_ioctl(fd, SIOCGIFADDR, arg);
141 goto out;
142 case _IOW('i', 14, struct ifreq32):
143 ret = sys32_ioctl(fd, SIOCSIFDSTADDR, arg);
144 goto out;
145 case _IOWR('i', 15, struct ifreq32):
146 ret = sys32_ioctl(fd, SIOCGIFDSTADDR, arg);
147 goto out;
148 case _IOW('i', 16, struct ifreq32):
149 ret = sys32_ioctl(fd, SIOCSIFFLAGS, arg);
150 goto out;
151 case _IOWR('i', 17, struct ifreq32):
152 ret = sys32_ioctl(fd, SIOCGIFFLAGS, arg);
153 goto out;
154 case _IOW('i', 18, struct ifreq32):
155 ret = sys32_ioctl(fd, SIOCSIFMEM, arg);
156 goto out;
157 case _IOWR('i', 19, struct ifreq32):
158 ret = sys32_ioctl(fd, SIOCGIFMEM, arg);
159 goto out;
161 case _IOWR('i', 20, struct ifconf32):
162 ret = sys32_ioctl(fd, SIOCGIFCONF, arg);
163 goto out;
165 case _IOW('i', 21, struct ifreq): /* SIOCSIFMTU */
166 ret = sys_ioctl(fd, SIOCSIFMTU, arg);
167 goto out;
168 case _IOWR('i', 22, struct ifreq): /* SIOCGIFMTU */
169 ret = sys_ioctl(fd, SIOCGIFMTU, arg);
170 goto out;
172 case _IOWR('i', 23, struct ifreq32):
173 ret = sys32_ioctl(fd, SIOCGIFBRDADDR, arg);
174 goto out;
175 case _IOW('i', 24, struct ifreq32):
176 ret = sys32_ioctl(fd, SIOCSIFBRDADDR, arg);
177 goto out;
178 case _IOWR('i', 25, struct ifreq32):
179 ret = sys32_ioctl(fd, SIOCGIFNETMASK, arg);
180 goto out;
181 case _IOW('i', 26, struct ifreq32):
182 ret = sys32_ioctl(fd, SIOCSIFNETMASK, arg);
183 goto out;
184 case _IOWR('i', 27, struct ifreq32):
185 ret = sys32_ioctl(fd, SIOCGIFMETRIC, arg);
186 goto out;
187 case _IOW('i', 28, struct ifreq32):
188 ret = sys32_ioctl(fd, SIOCSIFMETRIC, arg);
189 goto out;
191 case _IOW('i', 30, struct arpreq):
192 ret = sys32_ioctl(fd, SIOCSARP, arg);
193 goto out;
194 case _IOWR('i', 31, struct arpreq):
195 ret = sys32_ioctl(fd, SIOCGARP, arg);
196 goto out;
197 case _IOW('i', 32, struct arpreq):
198 ret = sys32_ioctl(fd, SIOCDARP, arg);
199 goto out;
201 case _IOW('i', 40, struct ifreq32): /* SIOCUPPER */
202 case _IOW('i', 41, struct ifreq32): /* SIOCLOWER */
203 case _IOW('i', 44, struct ifreq32): /* SIOCSETSYNC */
204 case _IOW('i', 45, struct ifreq32): /* SIOCGETSYNC */
205 case _IOW('i', 46, struct ifreq32): /* SIOCSSDSTATS */
206 case _IOW('i', 47, struct ifreq32): /* SIOCSSESTATS */
207 case _IOW('i', 48, struct ifreq32): /* SIOCSPROMISC */
208 ret = -EOPNOTSUPP;
209 goto out;
211 case _IOW('i', 49, struct ifreq32):
212 ret = sys32_ioctl(fd, SIOCADDMULTI, arg);
213 goto out;
214 case _IOW('i', 50, struct ifreq32):
215 ret = sys32_ioctl(fd, SIOCDELMULTI, arg);
216 goto out;
218 /* FDDI interface ioctls, unsupported. */
220 case _IOW('i', 51, struct ifreq32): /* SIOCFDRESET */
221 case _IOW('i', 52, struct ifreq32): /* SIOCFDSLEEP */
222 case _IOW('i', 53, struct ifreq32): /* SIOCSTRTFMWAR */
223 case _IOW('i', 54, struct ifreq32): /* SIOCLDNSTRTFW */
224 case _IOW('i', 55, struct ifreq32): /* SIOCGETFDSTAT */
225 case _IOW('i', 56, struct ifreq32): /* SIOCFDNMIINT */
226 case _IOW('i', 57, struct ifreq32): /* SIOCFDEXUSER */
227 case _IOW('i', 58, struct ifreq32): /* SIOCFDGNETMAP */
228 case _IOW('i', 59, struct ifreq32): /* SIOCFDGIOCTL */
229 printk("FDDI ioctl, returning EOPNOTSUPP\n");
230 ret = -EOPNOTSUPP;
231 goto out;
233 case _IOW('t', 125, int):
234 /* More stupid tty sunos ioctls, just
235 * say it worked.
237 ret = 0;
238 goto out;
240 /* Non posix grp */
241 case _IOW('t', 118, int): {
242 int oldval, newval, *ptr;
244 cmd = TIOCSPGRP;
245 ptr = (int *) A(arg);
246 ret = -EFAULT;
247 if(get_user(oldval, ptr))
248 goto out;
249 ret = sys32_ioctl(fd, cmd, arg);
250 __get_user(newval, ptr);
251 if(newval == -1) {
252 __put_user(oldval, ptr);
253 ret = -EIO;
255 if(ret == -ENOTTY)
256 ret = -EIO;
257 goto out;
260 case _IOR('t', 119, int): {
261 int oldval, newval, *ptr;
263 cmd = TIOCGPGRP;
264 ptr = (int *) A(arg);
265 ret = -EFAULT;
266 if(get_user(oldval, ptr))
267 goto out;
268 ret = sys32_ioctl(fd, cmd, arg);
269 __get_user(newval, ptr);
270 if(newval == -1) {
271 __put_user(oldval, ptr);
272 ret = -EIO;
274 if(ret == -ENOTTY)
275 ret = -EIO;
276 goto out;
280 ret = sys32_ioctl(fd, cmd, arg);
281 /* so stupid... */
282 ret = (ret == -EINVAL ? -EOPNOTSUPP : ret);
283 out:
284 unlock_kernel();
285 return ret;