diff options
Diffstat (limited to 'arch/mips/kernel/irixioctl.c')
-rw-r--r-- | arch/mips/kernel/irixioctl.c | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/arch/mips/kernel/irixioctl.c b/arch/mips/kernel/irixioctl.c new file mode 100644 index 000000000000..4cd3d38a22c2 --- /dev/null +++ b/arch/mips/kernel/irixioctl.c | |||
@@ -0,0 +1,261 @@ | |||
1 | /* | ||
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> | ||
17 | |||
18 | #include <asm/uaccess.h> | ||
19 | #include <asm/ioctl.h> | ||
20 | #include <asm/ioctls.h> | ||
21 | |||
22 | #undef DEBUG_IOCTLS | ||
23 | #undef DEBUG_MISSING_IOCTL | ||
24 | |||
25 | struct irix_termios { | ||
26 | tcflag_t c_iflag, c_oflag, c_cflag, c_lflag; | ||
27 | cc_t c_cc[NCCS]; | ||
28 | }; | ||
29 | |||
30 | extern void start_tty(struct tty_struct *tty); | ||
31 | static struct tty_struct *get_tty(int fd) | ||
32 | { | ||
33 | struct file *filp; | ||
34 | struct tty_struct *ttyp = NULL; | ||
35 | |||
36 | spin_lock(¤t->files->file_lock); | ||
37 | filp = fcheck(fd); | ||
38 | if(filp && filp->private_data) { | ||
39 | ttyp = (struct tty_struct *) filp->private_data; | ||
40 | |||
41 | if(ttyp->magic != TTY_MAGIC) | ||
42 | ttyp =NULL; | ||
43 | } | ||
44 | spin_unlock(¤t->files->file_lock); | ||
45 | return ttyp; | ||
46 | } | ||
47 | |||
48 | static struct tty_struct *get_real_tty(struct tty_struct *tp) | ||
49 | { | ||
50 | if (tp->driver->type == TTY_DRIVER_TYPE_PTY && | ||
51 | tp->driver->subtype == PTY_TYPE_MASTER) | ||
52 | return tp->link; | ||
53 | else | ||
54 | return tp; | ||
55 | } | ||
56 | |||
57 | asmlinkage int irix_ioctl(int fd, unsigned long cmd, unsigned long arg) | ||
58 | { | ||
59 | struct tty_struct *tp, *rtp; | ||
60 | mm_segment_t old_fs; | ||
61 | int error = 0; | ||
62 | |||
63 | #ifdef DEBUG_IOCTLS | ||
64 | printk("[%s:%d] irix_ioctl(%d, ", current->comm, current->pid, fd); | ||
65 | #endif | ||
66 | switch(cmd) { | ||
67 | case 0x00005401: | ||
68 | #ifdef DEBUG_IOCTLS | ||
69 | printk("TCGETA, %08lx) ", arg); | ||
70 | #endif | ||
71 | error = sys_ioctl(fd, TCGETA, arg); | ||
72 | break; | ||
73 | |||
74 | case 0x0000540d: { | ||
75 | struct termios kt; | ||
76 | struct irix_termios *it = (struct irix_termios *) arg; | ||
77 | |||
78 | #ifdef DEBUG_IOCTLS | ||
79 | printk("TCGETS, %08lx) ", arg); | ||
80 | #endif | ||
81 | if(!access_ok(VERIFY_WRITE, it, sizeof(*it))) { | ||
82 | error = -EFAULT; | ||
83 | break; | ||
84 | } | ||
85 | old_fs = get_fs(); set_fs(get_ds()); | ||
86 | error = sys_ioctl(fd, TCGETS, (unsigned long) &kt); | ||
87 | set_fs(old_fs); | ||
88 | if (error) | ||
89 | break; | ||
90 | __put_user(kt.c_iflag, &it->c_iflag); | ||
91 | __put_user(kt.c_oflag, &it->c_oflag); | ||
92 | __put_user(kt.c_cflag, &it->c_cflag); | ||
93 | __put_user(kt.c_lflag, &it->c_lflag); | ||
94 | for(error = 0; error < NCCS; error++) | ||
95 | __put_user(kt.c_cc[error], &it->c_cc[error]); | ||
96 | error = 0; | ||
97 | break; | ||
98 | } | ||
99 | |||
100 | case 0x0000540e: { | ||
101 | struct termios kt; | ||
102 | struct irix_termios *it = (struct irix_termios *) arg; | ||
103 | |||
104 | #ifdef DEBUG_IOCTLS | ||
105 | printk("TCSETS, %08lx) ", arg); | ||
106 | #endif | ||
107 | if (!access_ok(VERIFY_READ, it, sizeof(*it))) { | ||
108 | error = -EFAULT; | ||
109 | break; | ||
110 | } | ||
111 | old_fs = get_fs(); set_fs(get_ds()); | ||
112 | error = sys_ioctl(fd, TCGETS, (unsigned long) &kt); | ||
113 | set_fs(old_fs); | ||
114 | if(error) | ||
115 | break; | ||
116 | __get_user(kt.c_iflag, &it->c_iflag); | ||
117 | __get_user(kt.c_oflag, &it->c_oflag); | ||
118 | __get_user(kt.c_cflag, &it->c_cflag); | ||
119 | __get_user(kt.c_lflag, &it->c_lflag); | ||
120 | for(error = 0; error < NCCS; error++) | ||
121 | __get_user(kt.c_cc[error], &it->c_cc[error]); | ||
122 | old_fs = get_fs(); set_fs(get_ds()); | ||
123 | error = sys_ioctl(fd, TCSETS, (unsigned long) &kt); | ||
124 | set_fs(old_fs); | ||
125 | break; | ||
126 | } | ||
127 | |||
128 | case 0x0000540f: | ||
129 | #ifdef DEBUG_IOCTLS | ||
130 | printk("TCSETSW, %08lx) ", arg); | ||
131 | #endif | ||
132 | error = sys_ioctl(fd, TCSETSW, arg); | ||
133 | break; | ||
134 | |||
135 | case 0x00005471: | ||
136 | #ifdef DEBUG_IOCTLS | ||
137 | printk("TIOCNOTTY, %08lx) ", arg); | ||
138 | #endif | ||
139 | error = sys_ioctl(fd, TIOCNOTTY, arg); | ||
140 | break; | ||
141 | |||
142 | case 0x00007416: | ||
143 | #ifdef DEBUG_IOCTLS | ||
144 | printk("TIOCGSID, %08lx) ", arg); | ||
145 | #endif | ||
146 | tp = get_tty(fd); | ||
147 | if(!tp) { | ||
148 | error = -EINVAL; | ||
149 | break; | ||
150 | } | ||
151 | rtp = get_real_tty(tp); | ||
152 | #ifdef DEBUG_IOCTLS | ||
153 | printk("rtp->session=%d ", rtp->session); | ||
154 | #endif | ||
155 | error = put_user(rtp->session, (unsigned long *) arg); | ||
156 | break; | ||
157 | |||
158 | case 0x746e: | ||
159 | /* TIOCSTART, same effect as hitting ^Q */ | ||
160 | #ifdef DEBUG_IOCTLS | ||
161 | printk("TIOCSTART, %08lx) ", arg); | ||
162 | #endif | ||
163 | tp = get_tty(fd); | ||
164 | if(!tp) { | ||
165 | error = -EINVAL; | ||
166 | break; | ||
167 | } | ||
168 | rtp = get_real_tty(tp); | ||
169 | start_tty(rtp); | ||
170 | break; | ||
171 | |||
172 | case 0x20006968: | ||
173 | #ifdef DEBUG_IOCTLS | ||
174 | printk("SIOCGETLABEL, %08lx) ", arg); | ||
175 | #endif | ||
176 | error = -ENOPKG; | ||
177 | break; | ||
178 | |||
179 | case 0x40047477: | ||
180 | #ifdef DEBUG_IOCTLS | ||
181 | printk("TIOCGPGRP, %08lx) ", arg); | ||
182 | #endif | ||
183 | error = sys_ioctl(fd, TIOCGPGRP, arg); | ||
184 | #ifdef DEBUG_IOCTLS | ||
185 | printk("arg=%d ", *(int *)arg); | ||
186 | #endif | ||
187 | break; | ||
188 | |||
189 | case 0x40087468: | ||
190 | #ifdef DEBUG_IOCTLS | ||
191 | printk("TIOCGWINSZ, %08lx) ", arg); | ||
192 | #endif | ||
193 | error = sys_ioctl(fd, TIOCGWINSZ, arg); | ||
194 | break; | ||
195 | |||
196 | case 0x8004667e: | ||
197 | #ifdef DEBUG_IOCTLS | ||
198 | printk("FIONBIO, %08lx) arg=%d ", arg, *(int *)arg); | ||
199 | #endif | ||
200 | error = sys_ioctl(fd, FIONBIO, arg); | ||
201 | break; | ||
202 | |||
203 | case 0x80047476: | ||
204 | #ifdef DEBUG_IOCTLS | ||
205 | printk("TIOCSPGRP, %08lx) arg=%d ", arg, *(int *)arg); | ||
206 | #endif | ||
207 | error = sys_ioctl(fd, TIOCSPGRP, arg); | ||
208 | break; | ||
209 | |||
210 | case 0x8020690c: | ||
211 | #ifdef DEBUG_IOCTLS | ||
212 | printk("SIOCSIFADDR, %08lx) arg=%d ", arg, *(int *)arg); | ||
213 | #endif | ||
214 | error = sys_ioctl(fd, SIOCSIFADDR, arg); | ||
215 | break; | ||
216 | |||
217 | case 0x80206910: | ||
218 | #ifdef DEBUG_IOCTLS | ||
219 | printk("SIOCSIFFLAGS, %08lx) arg=%d ", arg, *(int *)arg); | ||
220 | #endif | ||
221 | error = sys_ioctl(fd, SIOCSIFFLAGS, arg); | ||
222 | break; | ||
223 | |||
224 | case 0xc0206911: | ||
225 | #ifdef DEBUG_IOCTLS | ||
226 | printk("SIOCGIFFLAGS, %08lx) arg=%d ", arg, *(int *)arg); | ||
227 | #endif | ||
228 | error = sys_ioctl(fd, SIOCGIFFLAGS, arg); | ||
229 | break; | ||
230 | |||
231 | case 0xc020691b: | ||
232 | #ifdef DEBUG_IOCTLS | ||
233 | printk("SIOCGIFMETRIC, %08lx) arg=%d ", arg, *(int *)arg); | ||
234 | #endif | ||
235 | error = sys_ioctl(fd, SIOCGIFMETRIC, arg); | ||
236 | break; | ||
237 | |||
238 | default: { | ||
239 | #ifdef DEBUG_MISSING_IOCTL | ||
240 | char *msg = "Unimplemented IOCTL cmd tell linux@engr.sgi.com\n"; | ||
241 | |||
242 | #ifdef DEBUG_IOCTLS | ||
243 | printk("UNIMP_IOCTL, %08lx)\n", arg); | ||
244 | #endif | ||
245 | old_fs = get_fs(); set_fs(get_ds()); | ||
246 | sys_write(2, msg, strlen(msg)); | ||
247 | set_fs(old_fs); | ||
248 | printk("[%s:%d] Does unimplemented IRIX ioctl cmd %08lx\n", | ||
249 | current->comm, current->pid, cmd); | ||
250 | do_exit(255); | ||
251 | #else | ||
252 | error = sys_ioctl (fd, cmd, arg); | ||
253 | #endif | ||
254 | } | ||
255 | |||
256 | }; | ||
257 | #ifdef DEBUG_IOCTLS | ||
258 | printk("error=%d\n", error); | ||
259 | #endif | ||
260 | return error; | ||
261 | } | ||