Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6/libata-dev.git] / arch / mips / kernel / irixioctl.c
blobe2863821a3dd8472ba194e45367a53f076552155
1 /*
2 * irixioctl.c: A fucking mess...
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
5 */
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 #include <linux/rcupdate.h>
19 #include <asm/uaccess.h>
20 #include <asm/ioctl.h>
21 #include <asm/ioctls.h>
23 #undef DEBUG_IOCTLS
24 #undef DEBUG_MISSING_IOCTL
26 struct irix_termios {
27 tcflag_t c_iflag, c_oflag, c_cflag, c_lflag;
28 cc_t c_cc[NCCS];
31 extern void start_tty(struct tty_struct *tty);
32 static struct tty_struct *get_tty(int fd)
34 struct file *filp;
35 struct tty_struct *ttyp = NULL;
37 rcu_read_lock();
38 filp = fcheck(fd);
39 if(filp && filp->private_data) {
40 ttyp = (struct tty_struct *) filp->private_data;
42 if(ttyp->magic != TTY_MAGIC)
43 ttyp =NULL;
45 rcu_read_unlock();
46 return ttyp;
49 static struct tty_struct *get_real_tty(struct tty_struct *tp)
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;
58 asmlinkage int irix_ioctl(int fd, unsigned long cmd, unsigned long arg)
60 struct tty_struct *tp, *rtp;
61 mm_segment_t old_fs;
62 int i, error = 0;
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;
75 case 0x0000540d: {
76 struct termios kt;
77 struct irix_termios __user *it =
78 (struct irix_termios __user *) arg;
80 #ifdef DEBUG_IOCTLS
81 printk("TCGETS, %08lx) ", arg);
82 #endif
83 if (!access_ok(VERIFY_WRITE, it, sizeof(*it))) {
84 error = -EFAULT;
85 break;
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;
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);
98 for (i = 0; i < NCCS; i++)
99 error |= __put_user(kt.c_cc[i], &it->c_cc[i]);
100 break;
103 case 0x0000540e: {
104 struct termios kt;
105 struct irix_termios *it = (struct irix_termios *) arg;
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;
114 old_fs = get_fs(); set_fs(get_ds());
115 error = sys_ioctl(fd, TCGETS, (unsigned long) &kt);
116 set_fs(old_fs);
117 if (error)
118 break;
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);
125 for (i = 0; i < NCCS; i++)
126 error |= __get_user(kt.c_cc[i], &it->c_cc[i]);
128 if (error)
129 break;
130 old_fs = get_fs(); set_fs(get_ds());
131 error = sys_ioctl(fd, TCSETS, (unsigned long) &kt);
132 set_fs(old_fs);
133 break;
136 case 0x0000540f:
137 #ifdef DEBUG_IOCTLS
138 printk("TCSETSW, %08lx) ", arg);
139 #endif
140 error = sys_ioctl(fd, TCSETSW, arg);
141 break;
143 case 0x00005471:
144 #ifdef DEBUG_IOCTLS
145 printk("TIOCNOTTY, %08lx) ", arg);
146 #endif
147 error = sys_ioctl(fd, TIOCNOTTY, arg);
148 break;
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;
159 rtp = get_real_tty(tp);
160 #ifdef DEBUG_IOCTLS
161 printk("rtp->session=%d ", rtp->session);
162 #endif
163 error = put_user(rtp->session, (unsigned long __user *) arg);
164 break;
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;
176 rtp = get_real_tty(tp);
177 start_tty(rtp);
178 break;
180 case 0x20006968:
181 #ifdef DEBUG_IOCTLS
182 printk("SIOCGETLABEL, %08lx) ", arg);
183 #endif
184 error = -ENOPKG;
185 break;
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;
197 case 0x40087468:
198 #ifdef DEBUG_IOCTLS
199 printk("TIOCGWINSZ, %08lx) ", arg);
200 #endif
201 error = sys_ioctl(fd, TIOCGWINSZ, arg);
202 break;
204 case 0x8004667e:
205 error = sys_ioctl(fd, FIONBIO, arg);
206 break;
208 case 0x80047476:
209 error = sys_ioctl(fd, TIOCSPGRP, arg);
210 break;
212 case 0x8020690c:
213 error = sys_ioctl(fd, SIOCSIFADDR, arg);
214 break;
216 case 0x80206910:
217 error = sys_ioctl(fd, SIOCSIFFLAGS, arg);
218 break;
220 case 0xc0206911:
221 error = sys_ioctl(fd, SIOCGIFFLAGS, arg);
222 break;
224 case 0xc020691b:
225 error = sys_ioctl(fd, SIOCGIFMETRIC, arg);
226 break;
228 default: {
229 #ifdef DEBUG_MISSING_IOCTL
230 char *msg = "Unimplemented IOCTL cmd tell linux-mips@linux-mips.org\n";
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
247 #ifdef DEBUG_IOCTLS
248 printk("error=%d\n", error);
249 #endif
250 return error;