summaryrefslogtreecommitdiffstats
path: root/arch/mips/kernel/irixioctl.c
blob: e0230f9f0440661948605a0a7aa7e5cfab5a090a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/* $Id: irixioctl.c,v 1.4 1996/07/14 09:36:16 dm Exp $
 * irixioctl.c: A fucking mess...
 *
 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
 */

#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/smp.h>
#include <linux/smp_lock.h>
#include <linux/tty.h>

#include <asm/uaccess.h>
#include <asm/ioctl.h>
#include <asm/ioctls.h>

#undef DEBUG_IOCTLS

struct irix_termios {
	tcflag_t c_iflag, c_oflag, c_cflag, c_lflag;
	cc_t c_cc[NCCS];
};

extern asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd,
				unsigned long arg);
extern asmlinkage int sys_write(unsigned int fd,char * buf,unsigned int count);
extern void start_tty(struct tty_struct *tty);

static struct tty_struct *get_tty(int fd)
{
	struct file *filp;

	if(fd >= NR_OPEN || !(filp = current->files->fd[fd]))
		return ((struct tty_struct *) 0);
	if(filp->private_data) {
		struct tty_struct *ttyp = (struct tty_struct *) filp->private_data;

		if(ttyp->magic == TTY_MAGIC)
			return ttyp;
	}
	return ((struct tty_struct *) 0);
}

static struct tty_struct *get_real_tty(struct tty_struct *tp)
{
	if(tp->driver.type == TTY_DRIVER_TYPE_PTY &&
	   tp->driver.subtype == PTY_TYPE_MASTER)
		return tp->link;
	else
		return tp;
}

asmlinkage int irix_ioctl(int fd, unsigned long cmd, unsigned long arg)
{
	struct tty_struct *tp, *rtp;
	int error = 0;
	int old_fs;

	lock_kernel();
#ifdef DEBUG_IOCTLS
	printk("[%s:%d] irix_ioctl(%d, ", current->comm, current->pid, fd);
#endif
	switch(cmd) {
	case 0x00005401:
#ifdef DEBUG_IOCTLS
		printk("TCGETA, %08lx) ", arg);
#endif
		error = sys_ioctl(fd, TCGETA, arg);
		break;

	case 0x0000540d: {
		struct termios kt;
		struct irix_termios *it = (struct irix_termios *) arg;

#ifdef DEBUG_IOCTLS
		printk("TCGETS, %08lx) ", arg);
#endif
		if(!access_ok(VERIFY_WRITE, it, sizeof(*it))) {
			error = -EFAULT;
			break;
		}
		old_fs = get_fs(); set_fs(get_ds());
		error = sys_ioctl(fd, TCGETS, (unsigned long) &kt);
		set_fs(old_fs);
		if(error)
			break;
		__put_user(kt.c_iflag, &it->c_iflag);
		__put_user(kt.c_oflag, &it->c_oflag);
		__put_user(kt.c_cflag, &it->c_cflag);
		__put_user(kt.c_lflag, &it->c_lflag);
		for(error = 0; error < NCCS; error++)
			__put_user(kt.c_cc[error], &it->c_cc[error]);
		error = 0;
		break;
	}

	case 0x0000540e: {
		struct termios kt;
		struct irix_termios *it = (struct irix_termios *) arg;

#ifdef DEBUG_IOCTLS
		printk("TCSETS, %08lx) ", arg);
#endif
		if(!access_ok(VERIFY_READ, it, sizeof(*it))) {
			error = -EFAULT;
			break;
		}
		old_fs = get_fs(); set_fs(get_ds());
		error = sys_ioctl(fd, TCGETS, (unsigned long) &kt);
		set_fs(old_fs);
		if(error)
			break;
		__get_user(kt.c_iflag, &it->c_iflag);
		__get_user(kt.c_oflag, &it->c_oflag);
		__get_user(kt.c_cflag, &it->c_cflag);
		__get_user(kt.c_lflag, &it->c_lflag);
		for(error = 0; error < NCCS; error++)
			__get_user(kt.c_cc[error], &it->c_cc[error]);
		old_fs = get_fs(); set_fs(get_ds());
		error = sys_ioctl(fd, TCSETS, (unsigned long) &kt);
		set_fs(old_fs);
		break;
	}

	case 0x0000540f:
#ifdef DEBUG_IOCTLS
		printk("TCSETSW, %08lx) ", arg);
#endif
		error = sys_ioctl(fd, TCSETSW, arg);
		break;

	case 0x00005471:
#ifdef DEBUG_IOCTLS
		printk("TIOCNOTTY, %08lx) ", arg);
#endif
		error = sys_ioctl(fd, TIOCNOTTY, arg);
		break;

	case 0x00007416:
#ifdef DEBUG_IOCTLS
		printk("TIOCGSID, %08lx) ", arg);
#endif
		tp = get_tty(fd);
		if(!tp) {
			error = -EINVAL;
			break;
		}
		rtp = get_real_tty(tp);
#ifdef DEBUG_IOCTLS
		printk("rtp->session=%d ", rtp->session);
#endif
		error = put_user(rtp->session, (unsigned long *) arg);
		break;

	case 0x746e:
		/* TIOCSTART, same effect as hitting ^Q */
#ifdef DEBUG_IOCTLS
		printk("TIOCSTART, %08lx) ", arg);
#endif
		tp = get_tty(fd);
		if(!tp) {
			error = -EINVAL;
			break;
		}
		rtp = get_real_tty(tp);
		start_tty(rtp);
		break;

	case 0x20006968:
#ifdef DEBUG_IOCTLS
		printk("SIOCGETLABEL, %08lx) ", arg);
#endif
		error = -ENOPKG;
		break;

	case 0x40047477:
#ifdef DEBUG_IOCTLS
		printk("TIOCGPGRP, %08lx) ", arg);
#endif
		error = sys_ioctl(fd, TIOCGPGRP, arg);
#ifdef DEBUG_IOCTLS
		printk("arg=%d ", *(int *)arg);
#endif
		break;

	case 0x40087468:
#ifdef DEBUG_IOCTLS
		printk("TIOCGWINSZ, %08lx) ", arg);
#endif
		error = sys_ioctl(fd, TIOCGWINSZ, arg);
		break;

	case 0x8004667e:
#ifdef DEBUG_IOCTLS
		printk("FIONBIO, %08lx) arg=%d ", arg, *(int *)arg);
#endif
		error = sys_ioctl(fd, FIONBIO, arg);
		break;

	case 0x80047476:
#ifdef DEBUG_IOCTLS
		printk("TIOCSPGRP, %08lx) arg=%d ", arg, *(int *)arg);
#endif
		error = sys_ioctl(fd, TIOCSPGRP, arg);
		break;

	case 0x8020690c:
#ifdef DEBUG_IOCTLS
		printk("SIOCSIFADDR, %08lx) arg=%d ", arg, *(int *)arg);
#endif
		error = sys_ioctl(fd, SIOCSIFADDR, arg);
		break;

	case 0x80206910:
#ifdef DEBUG_IOCTLS
		printk("SIOCSIFFLAGS, %08lx) arg=%d ", arg, *(int *)arg);
#endif
		error = sys_ioctl(fd, SIOCSIFFLAGS, arg);
		break;

	case 0xc0206911:
#ifdef DEBUG_IOCTLS
		printk("SIOCGIFFLAGS, %08lx) arg=%d ", arg, *(int *)arg);
#endif
		error = sys_ioctl(fd, SIOCGIFFLAGS, arg);
		break;

	case 0xc020691b:
#ifdef DEBUG_IOCTLS
		printk("SIOCGIFMETRIC, %08lx) arg=%d ", arg, *(int *)arg);
#endif
		error = sys_ioctl(fd, SIOCGIFMETRIC, arg);
		break;

	default: {
		char *msg = "Unimplemented IOCTL cmd tell dm@engr.sgi.com\n";

#ifdef DEBUG_IOCTLS
		printk("UNIMP_IOCTL, %08lx)\n", arg);
#endif
		old_fs = get_fs(); set_fs(get_ds());
		sys_write(2, msg, strlen(msg));
		set_fs(old_fs);
		printk("[%s:%d] Does unimplemented IRIX ioctl cmd %08lx\n",
		       current->comm, current->pid, cmd);
		do_exit(255);
	}

	};
#ifdef DEBUG_IOCTLS
	printk("error=%d\n", error);
#endif
	unlock_kernel();
	return error;
}