]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/sparc64/solaris/ioctl.c
[PATCH] files: break up files struct
[linux-2.6-omap-h63xx.git] / arch / sparc64 / solaris / ioctl.c
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
38 extern asmlinkage int compat_sys_ioctl(unsigned int fd, unsigned int cmd,
39         u32 arg);
40 asmlinkage int solaris_ioctl(unsigned int fd, unsigned int cmd, u32 arg);
41
42 extern int timod_putmsg(unsigned int fd, char __user *ctl_buf, int ctl_len,
43                         char __user *data_buf, int data_len, int flags);
44 extern 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
49 struct 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
57 struct 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
66 struct solaris_termiox {
67         u16     x_hflag;
68         u16     x_cflag;
69         u16     x_rflag[5];
70         u16     x_sflag;
71 };
72
73 static 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
93 static 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
118 static 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
136 static 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
151 static 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
173 static 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
197 static 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
230 static 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
245 struct strioctl {
246         int cmd, timeout, len;
247         u32 data;
248 };
249
250 struct solaris_si_sockparams {
251         int sp_family;
252         int sp_type;
253         int sp_protocol;
254 };
255
256 struct 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
267 struct 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
283 static 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
293 static inline int solaris_sockmod(unsigned int fd, unsigned int cmd, u32 arg)
294 {
295         struct inode *ino;
296         struct fdtable *fdt;
297         /* I wonder which of these tests are superfluous... --patrik */
298         spin_lock(&current->files->file_lock);
299         fdt = files_fdtable(current->files);
300         if (! fdt->fd[fd] ||
301             ! fdt->fd[fd]->f_dentry ||
302             ! (ino = fdt->fd[fd]->f_dentry->d_inode) ||
303             ! S_ISSOCK(ino->i_mode)) {
304                 spin_unlock(&current->files->file_lock);
305                 return TBADF;
306         }
307         spin_unlock(&current->files->file_lock);
308         
309         switch (cmd & 0xff) {
310         case 109: /* SI_SOCKPARAMS */
311         {
312                 struct solaris_si_sockparams si;
313                 if (copy_from_user (&si, A(arg), sizeof(si)))
314                         return (EFAULT << 8) | TSYSERR;
315
316                 /* Should we modify socket ino->socket_i.ops and type? */
317                 return 0;
318         }
319         case 110: /* SI_GETUDATA */
320         {
321                 int etsdusize, servtype;
322                 struct solaris_si_udata __user *p = A(arg);
323                 switch (SOCKET_I(ino)->type) {
324                 case SOCK_STREAM:
325                         etsdusize = 1;
326                         servtype = 2;
327                         break;
328                 default:
329                         etsdusize = -2;
330                         servtype = 3;
331                         break;
332                 }
333                 if (put_user(16384, &p->tidusize) ||
334                     __put_user(sizeof(struct sockaddr), &p->addrsize) ||
335                     __put_user(-1, &p->optsize) ||
336                     __put_user(etsdusize, &p->etsdusize) ||
337                     __put_user(servtype, &p->servtype) ||
338                     __put_user(0, &p->so_state) ||
339                     __put_user(0, &p->so_options) ||
340                     __put_user(16384, &p->tsdusize) ||
341                     __put_user(SOCKET_I(ino)->ops->family, &p->sockparams.sp_family) ||
342                     __put_user(SOCKET_I(ino)->type, &p->sockparams.sp_type) ||
343                     __put_user(SOCKET_I(ino)->ops->family, &p->sockparams.sp_protocol))
344                         return (EFAULT << 8) | TSYSERR;
345                 return 0;
346         }
347         case 101: /* O_SI_GETUDATA */
348         {
349                 int etsdusize, servtype;
350                 struct solaris_o_si_udata __user *p = A(arg);
351                 switch (SOCKET_I(ino)->type) {
352                 case SOCK_STREAM:
353                         etsdusize = 1;
354                         servtype = 2;
355                         break;
356                 default:
357                         etsdusize = -2;
358                         servtype = 3;
359                         break;
360                 }
361                 if (put_user(16384, &p->tidusize) ||
362                     __put_user(sizeof(struct sockaddr), &p->addrsize) ||
363                     __put_user(-1, &p->optsize) ||
364                     __put_user(etsdusize, &p->etsdusize) ||
365                     __put_user(servtype, &p->servtype) ||
366                     __put_user(0, &p->so_state) ||
367                     __put_user(0, &p->so_options) ||
368                     __put_user(16384, &p->tsdusize))
369                         return (EFAULT << 8) | TSYSERR;
370                 return 0;
371         }
372         case 102: /* SI_SHUTDOWN */
373         case 103: /* SI_LISTEN */
374         case 104: /* SI_SETMYNAME */
375         case 105: /* SI_SETPEERNAME */
376         case 106: /* SI_GETINTRANSIT */
377         case 107: /* SI_TCL_LINK */
378         case 108: /* SI_TCL_UNLINK */
379                 ;
380         }
381         return TNOTSUPPORT;
382 }
383
384 static inline int solaris_timod(unsigned int fd, unsigned int cmd, u32 arg,
385                                     int len, int __user *len_p)
386 {
387         int ret;
388                 
389         switch (cmd & 0xff) {
390         case 141: /* TI_OPTMGMT */
391         {
392                 int i;
393                 u32 prim;
394                 SOLD("TI_OPMGMT entry");
395                 ret = timod_putmsg(fd, A(arg), len, NULL, -1, 0);
396                 SOLD("timod_putmsg() returned");
397                 if (ret)
398                         return (-ret << 8) | TSYSERR;
399                 i = MSG_HIPRI;
400                 SOLD("calling timod_getmsg()");
401                 ret = timod_getmsg(fd, A(arg), len, len_p, NULL, -1, NULL, &i);
402                 SOLD("timod_getmsg() returned");
403                 if (ret)
404                         return (-ret << 8) | TSYSERR;
405                 SOLD("ret ok");
406                 if (get_user(prim, (u32 __user *)A(arg)))
407                         return (EFAULT << 8) | TSYSERR;
408                 SOLD("got prim");
409                 if (prim == T_ERROR_ACK) {
410                         u32 tmp, tmp2;
411                         SOLD("prim is T_ERROR_ACK");
412                         if (get_user(tmp, (u32 __user *)A(arg)+3) ||
413                             get_user(tmp2, (u32 __user *)A(arg)+2))
414                                 return (EFAULT << 8) | TSYSERR;
415                         return (tmp2 << 8) | tmp;
416                 }
417                 SOLD("TI_OPMGMT return 0");
418                 return 0;
419         }
420         case 142: /* TI_BIND */
421         {
422                 int i;
423                 u32 prim;
424                 SOLD("TI_BIND entry");
425                 ret = timod_putmsg(fd, A(arg), len, NULL, -1, 0);
426                 SOLD("timod_putmsg() returned");
427                 if (ret)
428                         return (-ret << 8) | TSYSERR;
429                 len = 1024; /* Solaris allows arbitrary return size */
430                 i = MSG_HIPRI;
431                 SOLD("calling timod_getmsg()");
432                 ret = timod_getmsg(fd, A(arg), len, len_p, NULL, -1, NULL, &i);
433                 SOLD("timod_getmsg() returned");
434                 if (ret)
435                         return (-ret << 8) | TSYSERR;
436                 SOLD("ret ok");
437                 if (get_user(prim, (u32 __user *)A(arg)))
438                         return (EFAULT << 8) | TSYSERR;
439                 SOLD("got prim");
440                 if (prim == T_ERROR_ACK) {
441                         u32 tmp, tmp2;
442                         SOLD("prim is T_ERROR_ACK");
443                         if (get_user(tmp, (u32 __user *)A(arg)+3) ||
444                             get_user(tmp2, (u32 __user *)A(arg)+2))
445                                 return (EFAULT << 8) | TSYSERR;
446                         return (tmp2 << 8) | tmp;
447                 }
448                 SOLD("no ERROR_ACK requested");
449                 if (prim != T_OK_ACK)
450                         return TBADSEQ;
451                 SOLD("OK_ACK requested");
452                 i = MSG_HIPRI;
453                 SOLD("calling timod_getmsg()");
454                 ret = timod_getmsg(fd, A(arg), len, len_p, NULL, -1, NULL, &i);
455                 SOLD("timod_getmsg() returned");
456                 if (ret)
457                         return (-ret << 8) | TSYSERR;
458                 SOLD("TI_BIND return ok");
459                 return 0;
460         }
461         case 140: /* TI_GETINFO */
462         case 143: /* TI_UNBIND */
463         case 144: /* TI_GETMYNAME */
464         case 145: /* TI_GETPEERNAME */
465         case 146: /* TI_SETMYNAME */
466         case 147: /* TI_SETPEERNAME */
467                 ;
468         }
469         return TNOTSUPPORT;
470 }
471
472 static inline int solaris_S(struct file *filp, unsigned int fd, unsigned int cmd, u32 arg)
473 {
474         char *p;
475         int ret;
476         mm_segment_t old_fs;
477         struct strioctl si;
478         struct inode *ino;
479         struct sol_socket_struct *sock;
480         struct module_info *mi;
481
482         ino = filp->f_dentry->d_inode;
483         if (!S_ISSOCK(ino->i_mode))
484                 return -EBADF;
485         sock = filp->private_data;
486         if (! sock) {
487                 printk("solaris_S: NULL private_data\n");
488                 return -EBADF;
489         }
490         if (sock->magic != SOLARIS_SOCKET_MAGIC) {
491                 printk("solaris_S: invalid magic\n");
492                 return -EBADF;
493         }
494         
495
496         switch (cmd & 0xff) {
497         case 1: /* I_NREAD */
498                 return -ENOSYS;
499         case 2: /* I_PUSH */
500         {
501                 p = getname (A(arg));
502                 if (IS_ERR (p))
503                         return PTR_ERR(p);
504                 ret = -EINVAL;
505                 for (mi = module_table; mi->name; mi++) {
506                         if (strcmp(mi->name, p) == 0) {
507                                 sol_module m;
508                                 if (sock->modcount >= MAX_NR_STREAM_MODULES) {
509                                         ret = -ENXIO;
510                                         break;
511                                 }
512                                 m = (sol_module) (mi - module_table);
513                                 sock->module[sock->modcount++] = m;
514                                 ret = 0;
515                                 break;
516                         }
517                 }
518                 putname (p);
519                 return ret;
520         }
521         case 3: /* I_POP */
522                 if (sock->modcount <= 0) return -EINVAL;
523                 sock->modcount--;
524                 return 0;
525         case 4: /* I_LOOK */
526         {
527                 const char *p;
528                 if (sock->modcount <= 0) return -EINVAL;
529                 p = module_table[(unsigned)sock->module[sock->modcount]].name;
530                 if (copy_to_user (A(arg), p, strlen(p)))
531                         return -EFAULT;
532                 return 0;
533         }
534         case 5: /* I_FLUSH */
535                 return 0;
536         case 8: /* I_STR */
537                 if (copy_from_user(&si, A(arg), sizeof(struct strioctl)))
538                         return -EFAULT;
539                 /* We ignore what module is actually at the top of stack. */
540                 switch ((si.cmd >> 8) & 0xff) {
541                 case 'I':
542                         return solaris_sockmod(fd, si.cmd, si.data);
543                 case 'T':
544                         return solaris_timod(fd, si.cmd, si.data, si.len,
545                                 &((struct strioctl __user *)A(arg))->len);
546                 default:
547                         return solaris_ioctl(fd, si.cmd, si.data);
548                 }
549         case 9: /* I_SETSIG */
550                 return sys_ioctl(fd, FIOSETOWN, current->pid);
551         case 10: /* I_GETSIG */
552                 old_fs = get_fs();
553                 set_fs(KERNEL_DS);
554                 sys_ioctl(fd, FIOGETOWN, (unsigned long)&ret);
555                 set_fs(old_fs);
556                 if (ret == current->pid) return 0x3ff;
557                 else return -EINVAL;
558         case 11: /* I_FIND */
559         {
560                 int i;
561                 p = getname (A(arg));
562                 if (IS_ERR (p))
563                         return PTR_ERR(p);
564                 ret = 0;
565                 for (i = 0; i < sock->modcount; i++) {
566                         unsigned m = sock->module[i];
567                         if (strcmp(module_table[m].name, p) == 0) {
568                                 ret = 1;
569                                 break;
570                         } 
571                 }
572                 putname (p);
573                 return ret;
574         }
575         case 19: /* I_SWROPT */
576         case 32: /* I_SETCLTIME */
577                 return 0;       /* Lie */
578         }
579         return -ENOSYS;
580 }
581
582 static inline int solaris_s(unsigned int fd, unsigned int cmd, u32 arg)
583 {
584         switch (cmd & 0xff) {
585         case 0: /* SIOCSHIWAT */
586         case 2: /* SIOCSLOWAT */
587                 return 0; /* We don't support them */
588         case 1: /* SIOCGHIWAT */
589         case 3: /* SIOCGLOWAT */
590                 if (put_user (0, (u32 __user *)A(arg)))
591                         return -EFAULT;
592                 return 0; /* Lie */
593         case 7: /* SIOCATMARK */
594                 return sys_ioctl(fd, SIOCATMARK, arg);
595         case 8: /* SIOCSPGRP */
596                 return sys_ioctl(fd, SIOCSPGRP, arg);
597         case 9: /* SIOCGPGRP */
598                 return sys_ioctl(fd, SIOCGPGRP, arg);
599         }
600         return -ENOSYS;
601 }
602
603 static inline int solaris_r(unsigned int fd, unsigned int cmd, u32 arg)
604 {
605         switch (cmd & 0xff) {
606         case 10: /* SIOCADDRT */
607                 return compat_sys_ioctl(fd, SIOCADDRT, arg);
608         case 11: /* SIOCDELRT */
609                 return compat_sys_ioctl(fd, SIOCDELRT, arg);
610         }
611         return -ENOSYS;
612 }
613
614 static inline int solaris_i(unsigned int fd, unsigned int cmd, u32 arg)
615 {
616         switch (cmd & 0xff) {
617         case 12: /* SIOCSIFADDR */
618                 return compat_sys_ioctl(fd, SIOCSIFADDR, arg);
619         case 13: /* SIOCGIFADDR */
620                 return compat_sys_ioctl(fd, SIOCGIFADDR, arg);
621         case 14: /* SIOCSIFDSTADDR */
622                 return compat_sys_ioctl(fd, SIOCSIFDSTADDR, arg);
623         case 15: /* SIOCGIFDSTADDR */
624                 return compat_sys_ioctl(fd, SIOCGIFDSTADDR, arg);
625         case 16: /* SIOCSIFFLAGS */
626                 return compat_sys_ioctl(fd, SIOCSIFFLAGS, arg);
627         case 17: /* SIOCGIFFLAGS */
628                 return compat_sys_ioctl(fd, SIOCGIFFLAGS, arg);
629         case 18: /* SIOCSIFMEM */
630                 return compat_sys_ioctl(fd, SIOCSIFMEM, arg);
631         case 19: /* SIOCGIFMEM */
632                 return compat_sys_ioctl(fd, SIOCGIFMEM, arg);
633         case 20: /* SIOCGIFCONF */
634                 return compat_sys_ioctl(fd, SIOCGIFCONF, arg);
635         case 21: /* SIOCSIFMTU */
636                 return compat_sys_ioctl(fd, SIOCSIFMTU, arg);
637         case 22: /* SIOCGIFMTU */
638                 return compat_sys_ioctl(fd, SIOCGIFMTU, arg);
639         case 23: /* SIOCGIFBRDADDR */
640                 return compat_sys_ioctl(fd, SIOCGIFBRDADDR, arg);
641         case 24: /* SIOCSIFBRDADDR */
642                 return compat_sys_ioctl(fd, SIOCSIFBRDADDR, arg);
643         case 25: /* SIOCGIFNETMASK */
644                 return compat_sys_ioctl(fd, SIOCGIFNETMASK, arg);
645         case 26: /* SIOCSIFNETMASK */
646                 return compat_sys_ioctl(fd, SIOCSIFNETMASK, arg);
647         case 27: /* SIOCGIFMETRIC */
648                 return compat_sys_ioctl(fd, SIOCGIFMETRIC, arg);
649         case 28: /* SIOCSIFMETRIC */
650                 return compat_sys_ioctl(fd, SIOCSIFMETRIC, arg);
651         case 30: /* SIOCSARP */
652                 return compat_sys_ioctl(fd, SIOCSARP, arg);
653         case 31: /* SIOCGARP */
654                 return compat_sys_ioctl(fd, SIOCGARP, arg);
655         case 32: /* SIOCDARP */
656                 return compat_sys_ioctl(fd, SIOCDARP, arg);
657         case 52: /* SIOCGETNAME */
658         case 53: /* SIOCGETPEER */
659                 {
660                         struct sockaddr uaddr;
661                         int uaddr_len = sizeof(struct sockaddr), ret;
662                         long args[3];
663                         mm_segment_t old_fs = get_fs();
664                         int (*sys_socketcall)(int, unsigned long *) =
665                                 (int (*)(int, unsigned long *))SYS(socketcall);
666                         
667                         args[0] = fd; args[1] = (long)&uaddr; args[2] = (long)&uaddr_len;
668                         set_fs(KERNEL_DS);
669                         ret = sys_socketcall(((cmd & 0xff) == 52) ? SYS_GETSOCKNAME : SYS_GETPEERNAME,
670                                         args);
671                         set_fs(old_fs);
672                         if (ret >= 0) {
673                                 if (copy_to_user(A(arg), &uaddr, uaddr_len))
674                                         return -EFAULT;
675                         }
676                         return ret;
677                 }
678 #if 0           
679         case 86: /* SIOCSOCKSYS */
680                 return socksys_syscall(fd, arg);
681 #endif          
682         case 87: /* SIOCGIFNUM */
683                 {
684                         struct net_device *d;
685                         int i = 0;
686                         
687                         read_lock_bh(&dev_base_lock);
688                         for (d = dev_base; d; d = d->next) i++;
689                         read_unlock_bh(&dev_base_lock);
690
691                         if (put_user (i, (int __user *)A(arg)))
692                                 return -EFAULT;
693                         return 0;
694                 }
695         }
696         return -ENOSYS;
697 }
698
699 static int solaris_m(unsigned int fd, unsigned int cmd, u32 arg)
700 {
701         int ret;
702
703         switch (cmd & 0xff) {
704         case 1: /* MTIOCTOP */
705                 ret = sys_ioctl(fd, MTIOCTOP, (unsigned long)&arg);
706                 break;
707         case 2: /* MTIOCGET */
708                 ret = sys_ioctl(fd, MTIOCGET, (unsigned long)&arg);
709                 break;
710         case 3: /* MTIOCGETDRIVETYPE */
711         case 4: /* MTIOCPERSISTENT */
712         case 5: /* MTIOCPERSISTENTSTATUS */
713         case 6: /* MTIOCLRERR */
714         case 7: /* MTIOCGUARANTEEDORDER */
715         case 8: /* MTIOCRESERVE */
716         case 9: /* MTIOCRELEASE */
717         case 10: /* MTIOCFORCERESERVE */
718         case 13: /* MTIOCSTATE */
719         case 14: /* MTIOCREADIGNOREILI */
720         case 15: /* MTIOCREADIGNOREEOFS */
721         case 16: /* MTIOCSHORTFMK */
722         default:
723                 ret = -ENOSYS; /* linux doesn't support these */
724                 break;
725         };
726
727         return ret;
728 }
729
730 static int solaris_O(unsigned int fd, unsigned int cmd, u32 arg)
731 {
732         int ret = -EINVAL;
733
734         switch (cmd & 0xff) {
735         case 1: /* OPROMGETOPT */
736                 ret = sys_ioctl(fd, OPROMGETOPT, arg);
737                 break;
738         case 2: /* OPROMSETOPT */
739                 ret = sys_ioctl(fd, OPROMSETOPT, arg);
740                 break;
741         case 3: /* OPROMNXTOPT */
742                 ret = sys_ioctl(fd, OPROMNXTOPT, arg);
743                 break;
744         case 4: /* OPROMSETOPT2 */
745                 ret = sys_ioctl(fd, OPROMSETOPT2, arg);
746                 break;
747         case 5: /* OPROMNEXT */
748                 ret = sys_ioctl(fd, OPROMNEXT, arg);
749                 break;
750         case 6: /* OPROMCHILD */
751                 ret = sys_ioctl(fd, OPROMCHILD, arg);
752                 break;
753         case 7: /* OPROMGETPROP */
754                 ret = sys_ioctl(fd, OPROMGETPROP, arg);
755                 break;
756         case 8: /* OPROMNXTPROP */
757                 ret = sys_ioctl(fd, OPROMNXTPROP, arg);
758                 break;
759         case 9: /* OPROMU2P */
760                 ret = sys_ioctl(fd, OPROMU2P, arg);
761                 break;
762         case 10: /* OPROMGETCONS */
763                 ret = sys_ioctl(fd, OPROMGETCONS, arg);
764                 break;
765         case 11: /* OPROMGETFBNAME */
766                 ret = sys_ioctl(fd, OPROMGETFBNAME, arg);
767                 break;
768         case 12: /* OPROMGETBOOTARGS */
769                 ret = sys_ioctl(fd, OPROMGETBOOTARGS, arg);
770                 break;
771         case 13: /* OPROMGETVERSION */
772         case 14: /* OPROMPATH2DRV */
773         case 15: /* OPROMDEV2PROMNAME */
774         case 16: /* OPROMPROM2DEVNAME */
775         case 17: /* OPROMGETPROPLEN */
776         default:
777                 ret = -EINVAL;
778                 break;
779         };
780         return ret;
781 }
782
783 /* }}} */
784
785 asmlinkage int solaris_ioctl(unsigned int fd, unsigned int cmd, u32 arg)
786 {
787         struct file *filp;
788         int error = -EBADF;
789
790         filp = fget(fd);
791         if (!filp)
792                 goto out;
793
794         lock_kernel();
795         error = -EFAULT;
796         switch ((cmd >> 8) & 0xff) {
797         case 'S': error = solaris_S(filp, fd, cmd, arg); break;
798         case 'T': error = solaris_T(fd, cmd, arg); break;
799         case 'i': error = solaris_i(fd, cmd, arg); break;
800         case 'r': error = solaris_r(fd, cmd, arg); break;
801         case 's': error = solaris_s(fd, cmd, arg); break;
802         case 't': error = solaris_t(fd, cmd, arg); break;
803         case 'f': error = sys_ioctl(fd, cmd, arg); break;
804         case 'm': error = solaris_m(fd, cmd, arg); break;
805         case 'O': error = solaris_O(fd, cmd, arg); break;
806         default:
807                 error = -ENOSYS;
808                 break;
809         }
810         unlock_kernel();
811         fput(filp);
812 out:
813         if (error == -ENOSYS) {
814                 unsigned char c = cmd>>8;
815                 
816                 if (c < ' ' || c > 126) c = '.';
817                 printk("solaris_ioctl: Unknown cmd fd(%d) cmd(%08x '%c') arg(%08x)\n",
818                        (int)fd, (unsigned int)cmd, c, (unsigned int)arg);
819                 error = -EINVAL;
820         }
821         return error;
822 }