File: sunos_ioctl.c

package info (click to toggle)
kernel-source-2.0.32 2.0.32-5
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 29,648 kB
  • ctags: 86,850
  • sloc: ansic: 542,141; asm: 26,201; makefile: 3,423; sh: 1,195; perl: 727; tcl: 408; cpp: 277; lisp: 211; awk: 134
file content (192 lines) | stat: -rw-r--r-- 5,439 bytes parent folder | download | duplicates (7)
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
/* $Id: sunos_ioctl.c,v 1.20 1996/04/25 06:09:08 davem Exp $
 * sunos_ioctl.c: The Linux Operating system: SunOS ioctl compatibility.
 * 
 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
 */

#include <asm/segment.h>

#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/termios.h>
#include <linux/ioctl.h>
#include <linux/route.h>
#include <linux/sockios.h>
#include <linux/if.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <asm/kbio.h>

#if 0
extern char sunkbd_type;
extern char sunkbd_layout;
#endif

extern asmlinkage int sys_ioctl(unsigned int, unsigned int, unsigned long);
extern asmlinkage int sys_setsid(void);

asmlinkage int sunos_ioctl (int fd, unsigned long cmd, unsigned long arg)
{
	struct file *filp;
	int foo;

	if (fd >= NR_OPEN || !(filp = current->files->fd [fd]))
		return -EBADF;

	/* First handle an easy compat. case for tty ldisc. */
	if(cmd == TIOCSETD) {
		int *p, ntty = N_TTY, old_fs;

		p = (int *) arg;
		foo = verify_area(VERIFY_WRITE, p, sizeof(int));
		if(foo) return foo;
		if(*p == 2) {
			old_fs = get_fs();
			set_fs(KERNEL_DS);
			foo = sys_ioctl(fd, cmd, (int) &ntty);
			set_fs(old_fs);
			return (foo == -EINVAL ? -EOPNOTSUPP : foo);
		}
	}

	/* Binary compatibility is good American knowhow fuckin' up. */
	if(cmd == TIOCNOTTY)
		return sys_setsid();

	/* SunOS networking ioctls. */
	switch (cmd) {
	case _IOW('r', 10, struct rtentry):
		return sys_ioctl(fd, SIOCADDRT, arg);
	case _IOW('r', 11, struct rtentry):
		return sys_ioctl(fd, SIOCDELRT, arg);
	case _IOW('i', 12, struct ifreq):
		return sys_ioctl(fd, SIOCSIFADDR, arg);
	case _IORW('i', 13, struct ifreq):
		return sys_ioctl(fd, SIOCGIFADDR, arg);
	case _IOW('i', 14, struct ifreq):
		return sys_ioctl(fd, SIOCSIFDSTADDR, arg);
	case _IORW('i', 15, struct ifreq):
		return sys_ioctl(fd, SIOCGIFDSTADDR, arg);
	case _IOW('i', 16, struct ifreq):
		return sys_ioctl(fd, SIOCSIFFLAGS, arg);
	case _IORW('i', 17, struct ifreq):
		return sys_ioctl(fd, SIOCGIFFLAGS, arg);
	case _IOW('i', 18, struct ifreq):
		return sys_ioctl(fd, SIOCSIFMEM, arg);
	case _IORW('i', 19, struct ifreq):
		return sys_ioctl(fd, SIOCGIFMEM, arg);
	case _IORW('i', 20, struct ifconf):
		return sys_ioctl(fd, SIOCGIFCONF, arg);
	case _IOW('i', 21, struct ifreq): /* SIOCSIFMTU */
		return sys_ioctl(fd, SIOCSIFMTU, arg);
	case _IORW('i', 22, struct ifreq): /* SIOCGIFMTU */
		return sys_ioctl(fd, SIOCGIFMTU, arg);

	case _IORW('i', 23, struct ifreq):
		return sys_ioctl(fd, SIOCGIFBRDADDR, arg);
	case _IOW('i', 24, struct ifreq):
		return sys_ioctl(fd, SIOCGIFBRDADDR, arg);
	case _IORW('i', 25, struct ifreq):
		return sys_ioctl(fd, SIOCGIFNETMASK, arg);
	case _IOW('i', 26, struct ifreq):
		return sys_ioctl(fd, SIOCSIFNETMASK, arg);
	case _IORW('i', 27, struct ifreq):
		return sys_ioctl(fd, SIOCGIFMETRIC, arg);
	case _IOW('i', 28, struct ifreq):
		return sys_ioctl(fd, SIOCSIFMETRIC, arg);

	case _IOW('i', 30, struct arpreq):
		return sys_ioctl(fd, SIOCSARP, arg);
	case _IOW('i', 31, struct arpreq):
		return sys_ioctl(fd, SIOCGARP, arg);
	case _IOW('i', 32, struct arpreq):
		return sys_ioctl(fd, SIOCGARP, arg);

	case _IOW('i', 40, struct ifreq): /* SIOCUPPER */
	case _IOW('i', 41, struct ifreq): /* SIOCLOWER */
	case _IOW('i', 44, struct ifreq): /* SIOCSETSYNC */
	case _IOW('i', 45, struct ifreq): /* SIOCGETSYNC */
	case _IOW('i', 46, struct ifreq): /* SIOCSSDSTATS */
	case _IOW('i', 47, struct ifreq): /* SIOCSSESTATS */
	case _IOW('i', 48, struct ifreq): /* SIOCSPROMISC */
		return -EOPNOTSUPP;

	case _IOW('i', 49, struct ifreq):
		return sys_ioctl(fd, SIOCADDMULTI, arg);
	case _IOW('i', 50, struct ifreq):
		return sys_ioctl(fd, SIOCDELMULTI, arg);

	/* FDDI interface ioctls, unsupported. */
		
	case _IOW('i', 51, struct ifreq): /* SIOCFDRESET */
	case _IOW('i', 52, struct ifreq): /* SIOCFDSLEEP */
	case _IOW('i', 53, struct ifreq): /* SIOCSTRTFMWAR */
	case _IOW('i', 54, struct ifreq): /* SIOCLDNSTRTFW */
	case _IOW('i', 55, struct ifreq): /* SIOCGETFDSTAT */
	case _IOW('i', 56, struct ifreq): /* SIOCFDNMIINT */
	case _IOW('i', 57, struct ifreq): /* SIOCFDEXUSER */
	case _IOW('i', 58, struct ifreq): /* SIOCFDGNETMAP */
	case _IOW('i', 59, struct ifreq): /* SIOCFDGIOCTL */
		printk("FDDI ioctl, returning EOPNOTSUPP\n");
		return -EOPNOTSUPP;
	case _IOW('t', 125, int):
		/* More stupid tty sunos ioctls, just
		 * say it worked.
		 */
		return 0;
	/* Non posix grp */
	case _IOW('t', 118, int): {
		int oldval, *ptr;

		cmd = TIOCSPGRP;
		ptr = (int *) arg;
		oldval = verify_area(VERIFY_WRITE, ptr, sizeof(int));
		if(oldval)
			return oldval;
		oldval = *ptr;
		foo = sys_ioctl(fd, cmd, arg);
		if(*ptr == -1) {
			*ptr = oldval;
			foo = -EIO;
		}
		if(foo == -ENOTTY)
			foo = -EIO;
		return foo;
	}

	case _IOR('t', 119, int): {
		int oldval, *ptr;

		cmd = TIOCGPGRP;
		ptr = (int *) arg;
		oldval = verify_area(VERIFY_WRITE, ptr, sizeof(int));
		if(oldval)
			return oldval;
		oldval = *ptr;
		foo = sys_ioctl(fd, cmd, arg);
		if(*ptr == -1) {
			*ptr = oldval;
			foo = -EIO;
		}
		if(foo == -ENOTTY)
			foo = -EIO;
		return foo;
	}
	}

#if 0
	if (cmd & 0xff00 == ('k' << 8)){
		printk ("[[KBIO: %8.8x\n", (unsigned int) cmd);
	}
#endif

	foo = sys_ioctl(fd, cmd, arg);
	/* so stupid... */
	return (foo == -EINVAL ? -EOPNOTSUPP : foo);
}