* better
[mascara-docs.git] / i386 / linux-2.3.21 / arch / mips / kernel / irixioctl.c
blob10ca5b15e8c40c8b3f43ee6994228815cf05e983
1 /* $Id: irixioctl.c,v 1.6 1999/02/06 05:12:56 adevries Exp $
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/tty.h>
14 #include <linux/file.h>
16 #include <asm/uaccess.h>
17 #include <asm/ioctl.h>
18 #include <asm/ioctls.h>
20 #undef DEBUG_IOCTLS
21 #undef DEBUG_MISSING_IOCTL
23 struct irix_termios {
24 tcflag_t c_iflag, c_oflag, c_cflag, c_lflag;
25 cc_t c_cc[NCCS];
28 extern asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd,
29 unsigned long arg);
30 extern asmlinkage int sys_write(unsigned int fd,char * buf,unsigned int count);
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 read_lock(&current->files->file_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 read_unlock(&current->files->file_lock);
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 error = 0;
64 lock_kernel();
65 #ifdef DEBUG_IOCTLS
66 printk("[%s:%d] irix_ioctl(%d, ", current->comm, current->pid, fd);
67 #endif
68 switch(cmd) {
69 case 0x00005401:
70 #ifdef DEBUG_IOCTLS
71 printk("TCGETA, %08lx) ", arg);
72 #endif
73 error = sys_ioctl(fd, TCGETA, arg);
74 break;
76 case 0x0000540d: {
77 struct termios kt;
78 struct irix_termios *it = (struct irix_termios *) 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;
92 __put_user(kt.c_iflag, &it->c_iflag);
93 __put_user(kt.c_oflag, &it->c_oflag);
94 __put_user(kt.c_cflag, &it->c_cflag);
95 __put_user(kt.c_lflag, &it->c_lflag);
96 for(error = 0; error < NCCS; error++)
97 __put_user(kt.c_cc[error], &it->c_cc[error]);
98 error = 0;
99 break;
102 case 0x0000540e: {
103 struct termios kt;
104 struct irix_termios *it = (struct irix_termios *) arg;
106 #ifdef DEBUG_IOCTLS
107 printk("TCSETS, %08lx) ", arg);
108 #endif
109 if(!access_ok(VERIFY_READ, it, sizeof(*it))) {
110 error = -EFAULT;
111 break;
113 old_fs = get_fs(); set_fs(get_ds());
114 error = sys_ioctl(fd, TCGETS, (unsigned long) &kt);
115 set_fs(old_fs);
116 if(error)
117 break;
118 __get_user(kt.c_iflag, &it->c_iflag);
119 __get_user(kt.c_oflag, &it->c_oflag);
120 __get_user(kt.c_cflag, &it->c_cflag);
121 __get_user(kt.c_lflag, &it->c_lflag);
122 for(error = 0; error < NCCS; error++)
123 __get_user(kt.c_cc[error], &it->c_cc[error]);
124 old_fs = get_fs(); set_fs(get_ds());
125 error = sys_ioctl(fd, TCSETS, (unsigned long) &kt);
126 set_fs(old_fs);
127 break;
130 case 0x0000540f:
131 #ifdef DEBUG_IOCTLS
132 printk("TCSETSW, %08lx) ", arg);
133 #endif
134 error = sys_ioctl(fd, TCSETSW, arg);
135 break;
137 case 0x00005471:
138 #ifdef DEBUG_IOCTLS
139 printk("TIOCNOTTY, %08lx) ", arg);
140 #endif
141 error = sys_ioctl(fd, TIOCNOTTY, arg);
142 break;
144 case 0x00007416:
145 #ifdef DEBUG_IOCTLS
146 printk("TIOCGSID, %08lx) ", arg);
147 #endif
148 tp = get_tty(fd);
149 if(!tp) {
150 error = -EINVAL;
151 break;
153 rtp = get_real_tty(tp);
154 #ifdef DEBUG_IOCTLS
155 printk("rtp->session=%d ", rtp->session);
156 #endif
157 error = put_user(rtp->session, (unsigned long *) arg);
158 break;
160 case 0x746e:
161 /* TIOCSTART, same effect as hitting ^Q */
162 #ifdef DEBUG_IOCTLS
163 printk("TIOCSTART, %08lx) ", arg);
164 #endif
165 tp = get_tty(fd);
166 if(!tp) {
167 error = -EINVAL;
168 break;
170 rtp = get_real_tty(tp);
171 start_tty(rtp);
172 break;
174 case 0x20006968:
175 #ifdef DEBUG_IOCTLS
176 printk("SIOCGETLABEL, %08lx) ", arg);
177 #endif
178 error = -ENOPKG;
179 break;
181 case 0x40047477:
182 #ifdef DEBUG_IOCTLS
183 printk("TIOCGPGRP, %08lx) ", arg);
184 #endif
185 error = sys_ioctl(fd, TIOCGPGRP, arg);
186 #ifdef DEBUG_IOCTLS
187 printk("arg=%d ", *(int *)arg);
188 #endif
189 break;
191 case 0x40087468:
192 #ifdef DEBUG_IOCTLS
193 printk("TIOCGWINSZ, %08lx) ", arg);
194 #endif
195 error = sys_ioctl(fd, TIOCGWINSZ, arg);
196 break;
198 case 0x8004667e:
199 #ifdef DEBUG_IOCTLS
200 printk("FIONBIO, %08lx) arg=%d ", arg, *(int *)arg);
201 #endif
202 error = sys_ioctl(fd, FIONBIO, arg);
203 break;
205 case 0x80047476:
206 #ifdef DEBUG_IOCTLS
207 printk("TIOCSPGRP, %08lx) arg=%d ", arg, *(int *)arg);
208 #endif
209 error = sys_ioctl(fd, TIOCSPGRP, arg);
210 break;
212 case 0x8020690c:
213 #ifdef DEBUG_IOCTLS
214 printk("SIOCSIFADDR, %08lx) arg=%d ", arg, *(int *)arg);
215 #endif
216 error = sys_ioctl(fd, SIOCSIFADDR, arg);
217 break;
219 case 0x80206910:
220 #ifdef DEBUG_IOCTLS
221 printk("SIOCSIFFLAGS, %08lx) arg=%d ", arg, *(int *)arg);
222 #endif
223 error = sys_ioctl(fd, SIOCSIFFLAGS, arg);
224 break;
226 case 0xc0206911:
227 #ifdef DEBUG_IOCTLS
228 printk("SIOCGIFFLAGS, %08lx) arg=%d ", arg, *(int *)arg);
229 #endif
230 error = sys_ioctl(fd, SIOCGIFFLAGS, arg);
231 break;
233 case 0xc020691b:
234 #ifdef DEBUG_IOCTLS
235 printk("SIOCGIFMETRIC, %08lx) arg=%d ", arg, *(int *)arg);
236 #endif
237 error = sys_ioctl(fd, SIOCGIFMETRIC, arg);
238 break;
240 default: {
241 #ifdef DEBUG_MISSING_IOCTL
242 char *msg = "Unimplemented IOCTL cmd tell linux@engr.sgi.com\n";
244 #ifdef DEBUG_IOCTLS
245 printk("UNIMP_IOCTL, %08lx)\n", arg);
246 #endif
247 old_fs = get_fs(); set_fs(get_ds());
248 sys_write(2, msg, strlen(msg));
249 set_fs(old_fs);
250 printk("[%s:%d] Does unimplemented IRIX ioctl cmd %08lx\n",
251 current->comm, current->pid, cmd);
252 do_exit(255);
253 #else
254 error = sys_ioctl (fd, cmd, arg);
255 #endif
259 #ifdef DEBUG_IOCTLS
260 printk("error=%d\n", error);
261 #endif
262 unlock_kernel();
263 return error;