blob: e2863821a3dd8472ba194e45367a53f076552155 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * irixioctl.c: A fucking mess...
3 *
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
5 */
6
7#include <linux/kernel.h>
8#include <linux/sched.h>
9#include <linux/fs.h>
10#include <linux/mm.h>
11#include <linux/smp.h>
12#include <linux/smp_lock.h>
13#include <linux/sockios.h>
14#include <linux/syscalls.h>
15#include <linux/tty.h>
16#include <linux/file.h>
Dipankar Sarmab8359962005-09-09 13:04:14 -070017#include <linux/rcupdate.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include <asm/uaccess.h>
20#include <asm/ioctl.h>
21#include <asm/ioctls.h>
22
23#undef DEBUG_IOCTLS
24#undef DEBUG_MISSING_IOCTL
25
26struct irix_termios {
27 tcflag_t c_iflag, c_oflag, c_cflag, c_lflag;
28 cc_t c_cc[NCCS];
29};
30
31extern void start_tty(struct tty_struct *tty);
32static struct tty_struct *get_tty(int fd)
33{
34 struct file *filp;
35 struct tty_struct *ttyp = NULL;
36
Dipankar Sarmab8359962005-09-09 13:04:14 -070037 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 filp = fcheck(fd);
39 if(filp && filp->private_data) {
40 ttyp = (struct tty_struct *) filp->private_data;
41
42 if(ttyp->magic != TTY_MAGIC)
43 ttyp =NULL;
44 }
Dipankar Sarmab8359962005-09-09 13:04:14 -070045 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 return ttyp;
47}
48
49static struct tty_struct *get_real_tty(struct tty_struct *tp)
50{
51 if (tp->driver->type == TTY_DRIVER_TYPE_PTY &&
52 tp->driver->subtype == PTY_TYPE_MASTER)
53 return tp->link;
54 else
55 return tp;
56}
57
58asmlinkage int irix_ioctl(int fd, unsigned long cmd, unsigned long arg)
59{
60 struct tty_struct *tp, *rtp;
61 mm_segment_t old_fs;
Ralf Baechle1592dac2005-03-17 21:50:49 +000062 int i, error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#ifdef DEBUG_IOCTLS
65 printk("[%s:%d] irix_ioctl(%d, ", current->comm, current->pid, fd);
66#endif
67 switch(cmd) {
68 case 0x00005401:
69#ifdef DEBUG_IOCTLS
70 printk("TCGETA, %08lx) ", arg);
71#endif
72 error = sys_ioctl(fd, TCGETA, arg);
73 break;
74
75 case 0x0000540d: {
76 struct termios kt;
Ralf Baechle1592dac2005-03-17 21:50:49 +000077 struct irix_termios __user *it =
78 (struct irix_termios __user *) arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80#ifdef DEBUG_IOCTLS
81 printk("TCGETS, %08lx) ", arg);
82#endif
Ralf Baechle1592dac2005-03-17 21:50:49 +000083 if (!access_ok(VERIFY_WRITE, it, sizeof(*it))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 error = -EFAULT;
85 break;
86 }
87 old_fs = get_fs(); set_fs(get_ds());
88 error = sys_ioctl(fd, TCGETS, (unsigned long) &kt);
89 set_fs(old_fs);
90 if (error)
91 break;
Ralf Baechle1592dac2005-03-17 21:50:49 +000092
93 error = __put_user(kt.c_iflag, &it->c_iflag);
94 error |= __put_user(kt.c_oflag, &it->c_oflag);
95 error |= __put_user(kt.c_cflag, &it->c_cflag);
96 error |= __put_user(kt.c_lflag, &it->c_lflag);
97
98 for (i = 0; i < NCCS; i++)
99 error |= __put_user(kt.c_cc[i], &it->c_cc[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 break;
101 }
102
103 case 0x0000540e: {
104 struct termios kt;
105 struct irix_termios *it = (struct irix_termios *) arg;
106
107#ifdef DEBUG_IOCTLS
108 printk("TCSETS, %08lx) ", arg);
109#endif
110 if (!access_ok(VERIFY_READ, it, sizeof(*it))) {
111 error = -EFAULT;
112 break;
113 }
114 old_fs = get_fs(); set_fs(get_ds());
115 error = sys_ioctl(fd, TCGETS, (unsigned long) &kt);
116 set_fs(old_fs);
Ralf Baechle1592dac2005-03-17 21:50:49 +0000117 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 break;
Ralf Baechle1592dac2005-03-17 21:50:49 +0000119
120 error = __get_user(kt.c_iflag, &it->c_iflag);
121 error |= __get_user(kt.c_oflag, &it->c_oflag);
122 error |= __get_user(kt.c_cflag, &it->c_cflag);
123 error |= __get_user(kt.c_lflag, &it->c_lflag);
124
125 for (i = 0; i < NCCS; i++)
126 error |= __get_user(kt.c_cc[i], &it->c_cc[i]);
127
128 if (error)
129 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 old_fs = get_fs(); set_fs(get_ds());
131 error = sys_ioctl(fd, TCSETS, (unsigned long) &kt);
132 set_fs(old_fs);
133 break;
134 }
135
136 case 0x0000540f:
137#ifdef DEBUG_IOCTLS
138 printk("TCSETSW, %08lx) ", arg);
139#endif
140 error = sys_ioctl(fd, TCSETSW, arg);
141 break;
142
143 case 0x00005471:
144#ifdef DEBUG_IOCTLS
145 printk("TIOCNOTTY, %08lx) ", arg);
146#endif
147 error = sys_ioctl(fd, TIOCNOTTY, arg);
148 break;
149
150 case 0x00007416:
151#ifdef DEBUG_IOCTLS
152 printk("TIOCGSID, %08lx) ", arg);
153#endif
154 tp = get_tty(fd);
155 if(!tp) {
156 error = -EINVAL;
157 break;
158 }
159 rtp = get_real_tty(tp);
160#ifdef DEBUG_IOCTLS
161 printk("rtp->session=%d ", rtp->session);
162#endif
Ralf Baechle1592dac2005-03-17 21:50:49 +0000163 error = put_user(rtp->session, (unsigned long __user *) arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 break;
165
166 case 0x746e:
167 /* TIOCSTART, same effect as hitting ^Q */
168#ifdef DEBUG_IOCTLS
169 printk("TIOCSTART, %08lx) ", arg);
170#endif
171 tp = get_tty(fd);
172 if(!tp) {
173 error = -EINVAL;
174 break;
175 }
176 rtp = get_real_tty(tp);
177 start_tty(rtp);
178 break;
179
180 case 0x20006968:
181#ifdef DEBUG_IOCTLS
182 printk("SIOCGETLABEL, %08lx) ", arg);
183#endif
184 error = -ENOPKG;
185 break;
186
187 case 0x40047477:
188#ifdef DEBUG_IOCTLS
189 printk("TIOCGPGRP, %08lx) ", arg);
190#endif
191 error = sys_ioctl(fd, TIOCGPGRP, arg);
192#ifdef DEBUG_IOCTLS
193 printk("arg=%d ", *(int *)arg);
194#endif
195 break;
196
197 case 0x40087468:
198#ifdef DEBUG_IOCTLS
199 printk("TIOCGWINSZ, %08lx) ", arg);
200#endif
201 error = sys_ioctl(fd, TIOCGWINSZ, arg);
202 break;
203
204 case 0x8004667e:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 error = sys_ioctl(fd, FIONBIO, arg);
206 break;
207
208 case 0x80047476:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 error = sys_ioctl(fd, TIOCSPGRP, arg);
210 break;
211
212 case 0x8020690c:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 error = sys_ioctl(fd, SIOCSIFADDR, arg);
214 break;
215
216 case 0x80206910:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 error = sys_ioctl(fd, SIOCSIFFLAGS, arg);
218 break;
219
220 case 0xc0206911:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 error = sys_ioctl(fd, SIOCGIFFLAGS, arg);
222 break;
223
224 case 0xc020691b:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 error = sys_ioctl(fd, SIOCGIFMETRIC, arg);
226 break;
227
228 default: {
229#ifdef DEBUG_MISSING_IOCTL
Ralf Baechle1592dac2005-03-17 21:50:49 +0000230 char *msg = "Unimplemented IOCTL cmd tell linux-mips@linux-mips.org\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232#ifdef DEBUG_IOCTLS
233 printk("UNIMP_IOCTL, %08lx)\n", arg);
234#endif
235 old_fs = get_fs(); set_fs(get_ds());
236 sys_write(2, msg, strlen(msg));
237 set_fs(old_fs);
238 printk("[%s:%d] Does unimplemented IRIX ioctl cmd %08lx\n",
239 current->comm, current->pid, cmd);
240 do_exit(255);
241#else
242 error = sys_ioctl (fd, cmd, arg);
243#endif
244 }
245
246 };
247#ifdef DEBUG_IOCTLS
248 printk("error=%d\n", error);
249#endif
250 return error;
251}