aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64/solaris/ioctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sparc64/solaris/ioctl.c')
-rw-r--r--arch/sparc64/solaris/ioctl.c820
1 files changed, 820 insertions, 0 deletions
diff --git a/arch/sparc64/solaris/ioctl.c b/arch/sparc64/solaris/ioctl.c
new file mode 100644
index 000000000000..cac0a1cf0050
--- /dev/null
+++ b/arch/sparc64/solaris/ioctl.c
@@ -0,0 +1,820 @@
1/* $Id: ioctl.c,v 1.17 2002/02/08 03:57:14 davem Exp $
2 * ioctl.c: Solaris ioctl emulation.
3 *
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997,1998 Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)
6 *
7 * Streams & timod emulation based on code
8 * Copyright (C) 1995, 1996 Mike Jagdis (jaggy@purplet.demon.co.uk)
9 *
10 * 1999-08-19 Implemented solaris 'm' (mag tape) and
11 * 'O' (openprom) ioctls, by Jason Rappleye
12 * (rappleye@ccr.buffalo.edu)
13 */
14
15#include <linux/types.h>
16#include <linux/kernel.h>
17#include <linux/sched.h>
18#include <linux/smp.h>
19#include <linux/smp_lock.h>
20#include <linux/syscalls.h>
21#include <linux/ioctl.h>
22#include <linux/fs.h>
23#include <linux/file.h>
24#include <linux/netdevice.h>
25#include <linux/mtio.h>
26#include <linux/time.h>
27#include <linux/compat.h>
28
29#include <net/sock.h>
30
31#include <asm/uaccess.h>
32#include <asm/termios.h>
33#include <asm/openpromio.h>
34
35#include "conv.h"
36#include "socksys.h"
37
38extern asmlinkage int compat_sys_ioctl(unsigned int fd, unsigned int cmd,
39 u32 arg);
40asmlinkage int solaris_ioctl(unsigned int fd, unsigned int cmd, u32 arg);
41
42extern int timod_putmsg(unsigned int fd, char __user *ctl_buf, int ctl_len,
43 char __user *data_buf, int data_len, int flags);
44extern int timod_getmsg(unsigned int fd, char __user *ctl_buf, int ctl_maxlen, int __user *ctl_len,
45 char __user *data_buf, int data_maxlen, int __user *data_len, int *flags);
46
47/* termio* stuff {{{ */
48
49struct solaris_termios {
50 u32 c_iflag;
51 u32 c_oflag;
52 u32 c_cflag;
53 u32 c_lflag;
54 u8 c_cc[19];
55};
56
57struct solaris_termio {
58 u16 c_iflag;
59 u16 c_oflag;
60 u16 c_cflag;
61 u16 c_lflag;
62 s8 c_line;
63 u8 c_cc[8];
64};
65
66struct solaris_termiox {
67 u16 x_hflag;
68 u16 x_cflag;
69 u16 x_rflag[5];
70 u16 x_sflag;
71};
72
73static u32 solaris_to_linux_cflag(u32 cflag)
74{
75 cflag &= 0x7fdff000;
76 if (cflag & 0x200000) {
77 int baud = cflag & 0xf;
78 cflag &= ~0x20000f;
79 switch (baud) {
80 case 0: baud = B57600; break;
81 case 1: baud = B76800; break;
82 case 2: baud = B115200; break;
83 case 3: baud = B153600; break;
84 case 4: baud = B230400; break;
85 case 5: baud = B307200; break;
86 case 6: baud = B460800; break;
87 }
88 cflag |= CBAUDEX | baud;
89 }
90 return cflag;
91}
92
93static u32 linux_to_solaris_cflag(u32 cflag)
94{
95 cflag &= ~(CMSPAR | CIBAUD);
96 if (cflag & CBAUDEX) {
97 int baud = cflag & CBAUD;
98 cflag &= ~CBAUD;
99 switch (baud) {
100 case B57600: baud = 0; break;
101 case B76800: baud = 1; break;
102 case B115200: baud = 2; break;
103 case B153600: baud = 3; break;
104 case B230400: baud = 4; break;
105 case B307200: baud = 5; break;
106 case B460800: baud = 6; break;
107 case B614400: baud = 7; break;
108 case B921600: baud = 8; break;
109#if 0
110 case B1843200: baud = 9; break;
111#endif
112 }
113 cflag |= 0x200000 | baud;
114 }
115 return cflag;
116}
117
118static inline int linux_to_solaris_termio(unsigned int fd, unsigned int cmd, u32 arg)
119{
120 struct solaris_termio __user *p = A(arg);
121 int ret;
122
123 ret = sys_ioctl(fd, cmd, (unsigned long)p);
124 if (!ret) {
125 u32 cflag;
126
127 if (__get_user (cflag, &p->c_cflag))
128 return -EFAULT;
129 cflag = linux_to_solaris_cflag(cflag);
130 if (__put_user (cflag, &p->c_cflag))
131 return -EFAULT;
132 }
133 return ret;
134}
135
136static int solaris_to_linux_termio(unsigned int fd, unsigned int cmd, u32 arg)
137{
138 int ret;
139 struct solaris_termio s;
140 mm_segment_t old_fs = get_fs();
141
142 if (copy_from_user (&s, (struct solaris_termio __user *)A(arg), sizeof(struct solaris_termio)))
143 return -EFAULT;
144 s.c_cflag = solaris_to_linux_cflag(s.c_cflag);
145 set_fs(KERNEL_DS);
146 ret = sys_ioctl(fd, cmd, (unsigned long)&s);
147 set_fs(old_fs);
148 return ret;
149}
150
151static inline int linux_to_solaris_termios(unsigned int fd, unsigned int cmd, u32 arg)
152{
153 int ret;
154 struct solaris_termios s;
155 mm_segment_t old_fs = get_fs();
156
157 set_fs(KERNEL_DS);
158 ret = sys_ioctl(fd, cmd, (unsigned long)&s);
159 set_fs(old_fs);
160 if (!ret) {
161 struct solaris_termios __user *p = A(arg);
162 if (put_user (s.c_iflag, &p->c_iflag) ||
163 __put_user (s.c_oflag, &p->c_oflag) ||
164 __put_user (linux_to_solaris_cflag(s.c_cflag), &p->c_cflag) ||
165 __put_user (s.c_lflag, &p->c_lflag) ||
166 __copy_to_user (p->c_cc, s.c_cc, 16) ||
167 __clear_user (p->c_cc + 16, 2))
168 return -EFAULT;
169 }
170 return ret;
171}
172
173static int solaris_to_linux_termios(unsigned int fd, unsigned int cmd, u32 arg)
174{
175 int ret;
176 struct solaris_termios s;
177 struct solaris_termios __user *p = A(arg);
178 mm_segment_t old_fs = get_fs();
179
180 set_fs(KERNEL_DS);
181 ret = sys_ioctl(fd, TCGETS, (unsigned long)&s);
182 set_fs(old_fs);
183 if (ret) return ret;
184 if (put_user (s.c_iflag, &p->c_iflag) ||
185 __put_user (s.c_oflag, &p->c_oflag) ||
186 __put_user (s.c_cflag, &p->c_cflag) ||
187 __put_user (s.c_lflag, &p->c_lflag) ||
188 __copy_from_user (s.c_cc, p->c_cc, 16))
189 return -EFAULT;
190 s.c_cflag = solaris_to_linux_cflag(s.c_cflag);
191 set_fs(KERNEL_DS);
192 ret = sys_ioctl(fd, cmd, (unsigned long)&s);
193 set_fs(old_fs);
194 return ret;
195}
196
197static inline int solaris_T(unsigned int fd, unsigned int cmd, u32 arg)
198{
199 switch (cmd & 0xff) {
200 case 1: /* TCGETA */
201 return linux_to_solaris_termio(fd, TCGETA, arg);
202 case 2: /* TCSETA */
203 return solaris_to_linux_termio(fd, TCSETA, arg);
204 case 3: /* TCSETAW */
205 return solaris_to_linux_termio(fd, TCSETAW, arg);
206 case 4: /* TCSETAF */
207 return solaris_to_linux_termio(fd, TCSETAF, arg);
208 case 5: /* TCSBRK */
209 return sys_ioctl(fd, TCSBRK, arg);
210 case 6: /* TCXONC */
211 return sys_ioctl(fd, TCXONC, arg);
212 case 7: /* TCFLSH */
213 return sys_ioctl(fd, TCFLSH, arg);
214 case 13: /* TCGETS */
215 return linux_to_solaris_termios(fd, TCGETS, arg);
216 case 14: /* TCSETS */
217 return solaris_to_linux_termios(fd, TCSETS, arg);
218 case 15: /* TCSETSW */
219 return solaris_to_linux_termios(fd, TCSETSW, arg);
220 case 16: /* TCSETSF */
221 return solaris_to_linux_termios(fd, TCSETSF, arg);
222 case 103: /* TIOCSWINSZ */
223 return sys_ioctl(fd, TIOCSWINSZ, arg);
224 case 104: /* TIOCGWINSZ */
225 return sys_ioctl(fd, TIOCGWINSZ, arg);
226 }
227 return -ENOSYS;
228}
229
230static inline int solaris_t(unsigned int fd, unsigned int cmd, u32 arg)
231{
232 switch (cmd & 0xff) {
233 case 20: /* TIOCGPGRP */
234 return sys_ioctl(fd, TIOCGPGRP, arg);
235 case 21: /* TIOCSPGRP */
236 return sys_ioctl(fd, TIOCSPGRP, arg);
237 }
238 return -ENOSYS;
239}
240
241/* }}} */
242
243/* A pseudo STREAMS support {{{ */
244
245struct strioctl {
246 int cmd, timeout, len;
247 u32 data;
248};
249
250struct solaris_si_sockparams {
251 int sp_family;
252 int sp_type;
253 int sp_protocol;
254};
255
256struct solaris_o_si_udata {
257 int tidusize;
258 int addrsize;
259 int optsize;
260 int etsdusize;
261 int servtype;
262 int so_state;
263 int so_options;
264 int tsdusize;
265};
266
267struct solaris_si_udata {
268 int tidusize;
269 int addrsize;
270 int optsize;
271 int etsdusize;
272 int servtype;
273 int so_state;
274 int so_options;
275 int tsdusize;
276 struct solaris_si_sockparams sockparams;
277};
278
279#define SOLARIS_MODULE_TIMOD 0
280#define SOLARIS_MODULE_SOCKMOD 1
281#define SOLARIS_MODULE_MAX 2
282
283static struct module_info {
284 const char *name;
285 /* can be expanded further if needed */
286} module_table[ SOLARIS_MODULE_MAX + 1 ] = {
287 /* the ordering here must match the module numbers above! */
288 { "timod" },
289 { "sockmod" },
290 { NULL }
291};
292
293static inline int solaris_sockmod(unsigned int fd, unsigned int cmd, u32 arg)
294{
295 struct inode *ino;
296 /* I wonder which of these tests are superfluous... --patrik */
297 spin_lock(&current->files->file_lock);
298 if (! current->files->fd[fd] ||
299 ! current->files->fd[fd]->f_dentry ||
300 ! (ino = current->files->fd[fd]->f_dentry->d_inode) ||
301 ! S_ISSOCK(ino->i_mode)) {
302 spin_unlock(&current->files->file_lock);
303 return TBADF;
304 }
305 spin_unlock(&current->files->file_lock);
306
307 switch (cmd & 0xff) {
308 case 109: /* SI_SOCKPARAMS */
309 {
310 struct solaris_si_sockparams si;
311 if (copy_from_user (&si, A(arg), sizeof(si)))
312 return (EFAULT << 8) | TSYSERR;
313
314 /* Should we modify socket ino->socket_i.ops and type? */
315 return 0;
316 }
317 case 110: /* SI_GETUDATA */
318 {
319 int etsdusize, servtype;
320 struct solaris_si_udata __user *p = A(arg);
321 switch (SOCKET_I(ino)->type) {
322 case SOCK_STREAM:
323 etsdusize = 1;
324 servtype = 2;
325 break;
326 default:
327 etsdusize = -2;
328 servtype = 3;
329 break;
330 }
331 if (put_user(16384, &p->tidusize) ||
332 __put_user(sizeof(struct sockaddr), &p->addrsize) ||
333 __put_user(-1, &p->optsize) ||
334 __put_user(etsdusize, &p->etsdusize) ||
335 __put_user(servtype, &p->servtype) ||
336 __put_user(0, &p->so_state) ||
337 __put_user(0, &p->so_options) ||
338 __put_user(16384, &p->tsdusize) ||
339 __put_user(SOCKET_I(ino)->ops->family, &p->sockparams.sp_family) ||
340 __put_user(SOCKET_I(ino)->type, &p->sockparams.sp_type) ||
341 __put_user(SOCKET_I(ino)->ops->family, &p->sockparams.sp_protocol))
342 return (EFAULT << 8) | TSYSERR;
343 return 0;
344 }
345 case 101: /* O_SI_GETUDATA */
346 {
347 int etsdusize, servtype;
348 struct solaris_o_si_udata __user *p = A(arg);
349 switch (SOCKET_I(ino)->type) {
350 case SOCK_STREAM:
351 etsdusize = 1;
352 servtype = 2;
353 break;
354 default:
355 etsdusize = -2;
356 servtype = 3;
357 break;
358 }
359 if (put_user(16384, &p->tidusize) ||
360 __put_user(sizeof(struct sockaddr), &p->addrsize) ||
361 __put_user(-1, &p->optsize) ||
362 __put_user(etsdusize, &p->etsdusize) ||
363 __put_user(servtype, &p->servtype) ||
364 __put_user(0, &p->so_state) ||
365 __put_user(0, &p->so_options) ||
366 __put_user(16384, &p->tsdusize))
367 return (EFAULT << 8) | TSYSERR;
368 return 0;
369 }
370 case 102: /* SI_SHUTDOWN */
371 case 103: /* SI_LISTEN */
372 case 104: /* SI_SETMYNAME */
373 case 105: /* SI_SETPEERNAME */
374 case 106: /* SI_GETINTRANSIT */
375 case 107: /* SI_TCL_LINK */
376 case 108: /* SI_TCL_UNLINK */
377 ;
378 }
379 return TNOTSUPPORT;
380}
381
382static inline int solaris_timod(unsigned int fd, unsigned int cmd, u32 arg,
383 int len, int __user *len_p)
384{
385 int ret;
386
387 switch (cmd & 0xff) {
388 case 141: /* TI_OPTMGMT */
389 {
390 int i;
391 u32 prim;
392 SOLD("TI_OPMGMT entry");
393 ret = timod_putmsg(fd, A(arg), len, NULL, -1, 0);
394 SOLD("timod_putmsg() returned");
395 if (ret)
396 return (-ret << 8) | TSYSERR;
397 i = MSG_HIPRI;
398 SOLD("calling timod_getmsg()");
399 ret = timod_getmsg(fd, A(arg), len, len_p, NULL, -1, NULL, &i);
400 SOLD("timod_getmsg() returned");
401 if (ret)
402 return (-ret << 8) | TSYSERR;
403 SOLD("ret ok");
404 if (get_user(prim, (u32 __user *)A(arg)))
405 return (EFAULT << 8) | TSYSERR;
406 SOLD("got prim");
407 if (prim == T_ERROR_ACK) {
408 u32 tmp, tmp2;
409 SOLD("prim is T_ERROR_ACK");
410 if (get_user(tmp, (u32 __user *)A(arg)+3) ||
411 get_user(tmp2, (u32 __user *)A(arg)+2))
412 return (EFAULT << 8) | TSYSERR;
413 return (tmp2 << 8) | tmp;
414 }
415 SOLD("TI_OPMGMT return 0");
416 return 0;
417 }
418 case 142: /* TI_BIND */
419 {
420 int i;
421 u32 prim;
422 SOLD("TI_BIND entry");
423 ret = timod_putmsg(fd, A(arg), len, NULL, -1, 0);
424 SOLD("timod_putmsg() returned");
425 if (ret)
426 return (-ret << 8) | TSYSERR;
427 len = 1024; /* Solaris allows arbitrary return size */
428 i = MSG_HIPRI;
429 SOLD("calling timod_getmsg()");
430 ret = timod_getmsg(fd, A(arg), len, len_p, NULL, -1, NULL, &i);
431 SOLD("timod_getmsg() returned");
432 if (ret)
433 return (-ret << 8) | TSYSERR;
434 SOLD("ret ok");
435 if (get_user(prim, (u32 __user *)A(arg)))
436 return (EFAULT << 8) | TSYSERR;
437 SOLD("got prim");
438 if (prim == T_ERROR_ACK) {
439 u32 tmp, tmp2;
440 SOLD("prim is T_ERROR_ACK");
441 if (get_user(tmp, (u32 __user *)A(arg)+3) ||
442 get_user(tmp2, (u32 __user *)A(arg)+2))
443 return (EFAULT << 8) | TSYSERR;
444 return (tmp2 << 8) | tmp;
445 }
446 SOLD("no ERROR_ACK requested");
447 if (prim != T_OK_ACK)
448 return TBADSEQ;
449 SOLD("OK_ACK requested");
450 i = MSG_HIPRI;
451 SOLD("calling timod_getmsg()");
452 ret = timod_getmsg(fd, A(arg), len, len_p, NULL, -1, NULL, &i);
453 SOLD("timod_getmsg() returned");
454 if (ret)
455 return (-ret << 8) | TSYSERR;
456 SOLD("TI_BIND return ok");
457 return 0;
458 }
459 case 140: /* TI_GETINFO */
460 case 143: /* TI_UNBIND */
461 case 144: /* TI_GETMYNAME */
462 case 145: /* TI_GETPEERNAME */
463 case 146: /* TI_SETMYNAME */
464 case 147: /* TI_SETPEERNAME */
465 ;
466 }
467 return TNOTSUPPORT;
468}
469
470static inline int solaris_S(struct file *filp, unsigned int fd, unsigned int cmd, u32 arg)
471{
472 char *p;
473 int ret;
474 mm_segment_t old_fs;
475 struct strioctl si;
476 struct inode *ino;
477 struct sol_socket_struct *sock;
478 struct module_info *mi;
479
480 ino = filp->f_dentry->d_inode;
481 if (!S_ISSOCK(ino->i_mode))
482 return -EBADF;
483 sock = filp->private_data;
484 if (! sock) {
485 printk("solaris_S: NULL private_data\n");
486 return -EBADF;
487 }
488 if (sock->magic != SOLARIS_SOCKET_MAGIC) {
489 printk("solaris_S: invalid magic\n");
490 return -EBADF;
491 }
492
493
494 switch (cmd & 0xff) {
495 case 1: /* I_NREAD */
496 return -ENOSYS;
497 case 2: /* I_PUSH */
498 {
499 p = getname (A(arg));
500 if (IS_ERR (p))
501 return PTR_ERR(p);
502 ret = -EINVAL;
503 for (mi = module_table; mi->name; mi++) {
504 if (strcmp(mi->name, p) == 0) {
505 sol_module m;
506 if (sock->modcount >= MAX_NR_STREAM_MODULES) {
507 ret = -ENXIO;
508 break;
509 }
510 m = (sol_module) (mi - module_table);
511 sock->module[sock->modcount++] = m;
512 ret = 0;
513 break;
514 }
515 }
516 putname (p);
517 return ret;
518 }
519 case 3: /* I_POP */
520 if (sock->modcount <= 0) return -EINVAL;
521 sock->modcount--;
522 return 0;
523 case 4: /* I_LOOK */
524 {
525 const char *p;
526 if (sock->modcount <= 0) return -EINVAL;
527 p = module_table[(unsigned)sock->module[sock->modcount]].name;
528 if (copy_to_user (A(arg), p, strlen(p)))
529 return -EFAULT;
530 return 0;
531 }
532 case 5: /* I_FLUSH */
533 return 0;
534 case 8: /* I_STR */
535 if (copy_from_user(&si, A(arg), sizeof(struct strioctl)))
536 return -EFAULT;
537 /* We ignore what module is actually at the top of stack. */
538 switch ((si.cmd >> 8) & 0xff) {
539 case 'I':
540 return solaris_sockmod(fd, si.cmd, si.data);
541 case 'T':
542 return solaris_timod(fd, si.cmd, si.data, si.len,
543 &((struct strioctl __user *)A(arg))->len);
544 default:
545 return solaris_ioctl(fd, si.cmd, si.data);
546 }
547 case 9: /* I_SETSIG */
548 return sys_ioctl(fd, FIOSETOWN, current->pid);
549 case 10: /* I_GETSIG */
550 old_fs = get_fs();
551 set_fs(KERNEL_DS);
552 sys_ioctl(fd, FIOGETOWN, (unsigned long)&ret);
553 set_fs(old_fs);
554 if (ret == current->pid) return 0x3ff;
555 else return -EINVAL;
556 case 11: /* I_FIND */
557 {
558 int i;
559 p = getname (A(arg));
560 if (IS_ERR (p))
561 return PTR_ERR(p);
562 ret = 0;
563 for (i = 0; i < sock->modcount; i++) {
564 unsigned m = sock->module[i];
565 if (strcmp(module_table[m].name, p) == 0) {
566 ret = 1;
567 break;
568 }
569 }
570 putname (p);
571 return ret;
572 }
573 case 19: /* I_SWROPT */
574 case 32: /* I_SETCLTIME */
575 return 0; /* Lie */
576 }
577 return -ENOSYS;
578}
579
580static inline int solaris_s(unsigned int fd, unsigned int cmd, u32 arg)
581{
582 switch (cmd & 0xff) {
583 case 0: /* SIOCSHIWAT */
584 case 2: /* SIOCSLOWAT */
585 return 0; /* We don't support them */
586 case 1: /* SIOCGHIWAT */
587 case 3: /* SIOCGLOWAT */
588 if (put_user (0, (u32 __user *)A(arg)))
589 return -EFAULT;
590 return 0; /* Lie */
591 case 7: /* SIOCATMARK */
592 return sys_ioctl(fd, SIOCATMARK, arg);
593 case 8: /* SIOCSPGRP */
594 return sys_ioctl(fd, SIOCSPGRP, arg);
595 case 9: /* SIOCGPGRP */
596 return sys_ioctl(fd, SIOCGPGRP, arg);
597 }
598 return -ENOSYS;
599}
600
601static inline int solaris_r(unsigned int fd, unsigned int cmd, u32 arg)
602{
603 switch (cmd & 0xff) {
604 case 10: /* SIOCADDRT */
605 return compat_sys_ioctl(fd, SIOCADDRT, arg);
606 case 11: /* SIOCDELRT */
607 return compat_sys_ioctl(fd, SIOCDELRT, arg);
608 }
609 return -ENOSYS;
610}
611
612static inline int solaris_i(unsigned int fd, unsigned int cmd, u32 arg)
613{
614 switch (cmd & 0xff) {
615 case 12: /* SIOCSIFADDR */
616 return compat_sys_ioctl(fd, SIOCSIFADDR, arg);
617 case 13: /* SIOCGIFADDR */
618 return compat_sys_ioctl(fd, SIOCGIFADDR, arg);
619 case 14: /* SIOCSIFDSTADDR */
620 return compat_sys_ioctl(fd, SIOCSIFDSTADDR, arg);
621 case 15: /* SIOCGIFDSTADDR */
622 return compat_sys_ioctl(fd, SIOCGIFDSTADDR, arg);
623 case 16: /* SIOCSIFFLAGS */
624 return compat_sys_ioctl(fd, SIOCSIFFLAGS, arg);
625 case 17: /* SIOCGIFFLAGS */
626 return compat_sys_ioctl(fd, SIOCGIFFLAGS, arg);
627 case 18: /* SIOCSIFMEM */
628 return compat_sys_ioctl(fd, SIOCSIFMEM, arg);
629 case 19: /* SIOCGIFMEM */
630 return compat_sys_ioctl(fd, SIOCGIFMEM, arg);
631 case 20: /* SIOCGIFCONF */
632 return compat_sys_ioctl(fd, SIOCGIFCONF, arg);
633 case 21: /* SIOCSIFMTU */
634 return compat_sys_ioctl(fd, SIOCSIFMTU, arg);
635 case 22: /* SIOCGIFMTU */
636 return compat_sys_ioctl(fd, SIOCGIFMTU, arg);
637 case 23: /* SIOCGIFBRDADDR */
638 return compat_sys_ioctl(fd, SIOCGIFBRDADDR, arg);
639 case 24: /* SIOCSIFBRDADDR */
640 return compat_sys_ioctl(fd, SIOCSIFBRDADDR, arg);
641 case 25: /* SIOCGIFNETMASK */
642 return compat_sys_ioctl(fd, SIOCGIFNETMASK, arg);
643 case 26: /* SIOCSIFNETMASK */
644 return compat_sys_ioctl(fd, SIOCSIFNETMASK, arg);
645 case 27: /* SIOCGIFMETRIC */
646 return compat_sys_ioctl(fd, SIOCGIFMETRIC, arg);
647 case 28: /* SIOCSIFMETRIC */
648 return compat_sys_ioctl(fd, SIOCSIFMETRIC, arg);
649 case 30: /* SIOCSARP */
650 return compat_sys_ioctl(fd, SIOCSARP, arg);
651 case 31: /* SIOCGARP */
652 return compat_sys_ioctl(fd, SIOCGARP, arg);
653 case 32: /* SIOCDARP */
654 return compat_sys_ioctl(fd, SIOCDARP, arg);
655 case 52: /* SIOCGETNAME */
656 case 53: /* SIOCGETPEER */
657 {
658 struct sockaddr uaddr;
659 int uaddr_len = sizeof(struct sockaddr), ret;
660 long args[3];
661 mm_segment_t old_fs = get_fs();
662 int (*sys_socketcall)(int, unsigned long *) =
663 (int (*)(int, unsigned long *))SYS(socketcall);
664
665 args[0] = fd; args[1] = (long)&uaddr; args[2] = (long)&uaddr_len;
666 set_fs(KERNEL_DS);
667 ret = sys_socketcall(((cmd & 0xff) == 52) ? SYS_GETSOCKNAME : SYS_GETPEERNAME,
668 args);
669 set_fs(old_fs);
670 if (ret >= 0) {
671 if (copy_to_user(A(arg), &uaddr, uaddr_len))
672 return -EFAULT;
673 }
674 return ret;
675 }
676#if 0
677 case 86: /* SIOCSOCKSYS */
678 return socksys_syscall(fd, arg);
679#endif
680 case 87: /* SIOCGIFNUM */
681 {
682 struct net_device *d;
683 int i = 0;
684
685 read_lock_bh(&dev_base_lock);
686 for (d = dev_base; d; d = d->next) i++;
687 read_unlock_bh(&dev_base_lock);
688
689 if (put_user (i, (int __user *)A(arg)))
690 return -EFAULT;
691 return 0;
692 }
693 }
694 return -ENOSYS;
695}
696
697static int solaris_m(unsigned int fd, unsigned int cmd, u32 arg)
698{
699 int ret;
700
701 switch (cmd & 0xff) {
702 case 1: /* MTIOCTOP */
703 ret = sys_ioctl(fd, MTIOCTOP, (unsigned long)&arg);
704 break;
705 case 2: /* MTIOCGET */
706 ret = sys_ioctl(fd, MTIOCGET, (unsigned long)&arg);
707 break;
708 case 3: /* MTIOCGETDRIVETYPE */
709 case 4: /* MTIOCPERSISTENT */
710 case 5: /* MTIOCPERSISTENTSTATUS */
711 case 6: /* MTIOCLRERR */
712 case 7: /* MTIOCGUARANTEEDORDER */
713 case 8: /* MTIOCRESERVE */
714 case 9: /* MTIOCRELEASE */
715 case 10: /* MTIOCFORCERESERVE */
716 case 13: /* MTIOCSTATE */
717 case 14: /* MTIOCREADIGNOREILI */
718 case 15: /* MTIOCREADIGNOREEOFS */
719 case 16: /* MTIOCSHORTFMK */
720 default:
721 ret = -ENOSYS; /* linux doesn't support these */
722 break;
723 };
724
725 return ret;
726}
727
728static int solaris_O(unsigned int fd, unsigned int cmd, u32 arg)
729{
730 int ret = -EINVAL;
731
732 switch (cmd & 0xff) {
733 case 1: /* OPROMGETOPT */
734 ret = sys_ioctl(fd, OPROMGETOPT, arg);
735 break;
736 case 2: /* OPROMSETOPT */
737 ret = sys_ioctl(fd, OPROMSETOPT, arg);
738 break;
739 case 3: /* OPROMNXTOPT */
740 ret = sys_ioctl(fd, OPROMNXTOPT, arg);
741 break;
742 case 4: /* OPROMSETOPT2 */
743 ret = sys_ioctl(fd, OPROMSETOPT2, arg);
744 break;
745 case 5: /* OPROMNEXT */
746 ret = sys_ioctl(fd, OPROMNEXT, arg);
747 break;
748 case 6: /* OPROMCHILD */
749 ret = sys_ioctl(fd, OPROMCHILD, arg);
750 break;
751 case 7: /* OPROMGETPROP */
752 ret = sys_ioctl(fd, OPROMGETPROP, arg);
753 break;
754 case 8: /* OPROMNXTPROP */
755 ret = sys_ioctl(fd, OPROMNXTPROP, arg);
756 break;
757 case 9: /* OPROMU2P */
758 ret = sys_ioctl(fd, OPROMU2P, arg);
759 break;
760 case 10: /* OPROMGETCONS */
761 ret = sys_ioctl(fd, OPROMGETCONS, arg);
762 break;
763 case 11: /* OPROMGETFBNAME */
764 ret = sys_ioctl(fd, OPROMGETFBNAME, arg);
765 break;
766 case 12: /* OPROMGETBOOTARGS */
767 ret = sys_ioctl(fd, OPROMGETBOOTARGS, arg);
768 break;
769 case 13: /* OPROMGETVERSION */
770 case 14: /* OPROMPATH2DRV */
771 case 15: /* OPROMDEV2PROMNAME */
772 case 16: /* OPROMPROM2DEVNAME */
773 case 17: /* OPROMGETPROPLEN */
774 default:
775 ret = -EINVAL;
776 break;
777 };
778 return ret;
779}
780
781/* }}} */
782
783asmlinkage int solaris_ioctl(unsigned int fd, unsigned int cmd, u32 arg)
784{
785 struct file *filp;
786 int error = -EBADF;
787
788 filp = fget(fd);
789 if (!filp)
790 goto out;
791
792 lock_kernel();
793 error = -EFAULT;
794 switch ((cmd >> 8) & 0xff) {
795 case 'S': error = solaris_S(filp, fd, cmd, arg); break;
796 case 'T': error = solaris_T(fd, cmd, arg); break;
797 case 'i': error = solaris_i(fd, cmd, arg); break;
798 case 'r': error = solaris_r(fd, cmd, arg); break;
799 case 's': error = solaris_s(fd, cmd, arg); break;
800 case 't': error = solaris_t(fd, cmd, arg); break;
801 case 'f': error = sys_ioctl(fd, cmd, arg); break;
802 case 'm': error = solaris_m(fd, cmd, arg); break;
803 case 'O': error = solaris_O(fd, cmd, arg); break;
804 default:
805 error = -ENOSYS;
806 break;
807 }
808 unlock_kernel();
809 fput(filp);
810out:
811 if (error == -ENOSYS) {
812 unsigned char c = cmd>>8;
813
814 if (c < ' ' || c > 126) c = '.';
815 printk("solaris_ioctl: Unknown cmd fd(%d) cmd(%08x '%c') arg(%08x)\n",
816 (int)fd, (unsigned int)cmd, c, (unsigned int)arg);
817 error = -EINVAL;
818 }
819 return error;
820}