OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [sparc64/] [solaris/] [ioctl.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.