1 /* $NetBSD: svr4_ttold.c,v 1.26 2006/11/16 01:32:44 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: svr4_ttold.c,v 1.26 2006/11/16 01:32:44 christos Exp $");
41
42 #include <sys/param.h>
43 #include <sys/proc.h>
44 #include <sys/systm.h>
45 #include <sys/file.h>
46 #include <sys/filedesc.h>
47 #include <sys/ioctl.h>
48 #include <sys/termios.h>
49 #include <sys/tty.h>
50 #include <sys/socket.h>
51 #include <sys/ioctl.h>
52 #include <sys/mount.h>
53 #include <net/if.h>
54 #include <sys/malloc.h>
55 #include <sys/ioctl_compat.h>
56
57 #include <sys/sa.h>
58 #include <sys/syscallargs.h>
59
60 #include <compat/svr4/svr4_types.h>
61 #include <compat/svr4/svr4_util.h>
62 #include <compat/svr4/svr4_signal.h>
63 #include <compat/svr4/svr4_lwp.h>
64 #include <compat/svr4/svr4_ucontext.h>
65 #include <compat/svr4/svr4_syscallargs.h>
66 #include <compat/svr4/svr4_stropts.h>
67 #include <compat/svr4/svr4_ttold.h>
68 #include <compat/svr4/svr4_ioctl.h>
69
70
71 static void svr4_tchars_to_bsd_tchars __P((const struct svr4_tchars *st,
72 struct tchars *bt));
73 static void bsd_tchars_to_svr4_tchars __P((const struct tchars *bt,
74 struct svr4_tchars *st));
75 static void svr4_sgttyb_to_bsd_sgttyb __P((const struct svr4_sgttyb *ss,
76 struct sgttyb *bs));
77 static void bsd_sgttyb_to_svr4_sgttyb __P((const struct sgttyb *bs,
78 struct svr4_sgttyb *ss));
79 static void svr4_ltchars_to_bsd_ltchars __P((const struct svr4_ltchars *sl,
80 struct ltchars *bl));
81 static void bsd_ltchars_to_svr4_ltchars __P((const struct ltchars *bl,
82 struct svr4_ltchars *sl));
83
84 #ifdef DEBUG_SVR4
85 static void print_svr4_sgttyb __P((const char *, struct svr4_sgttyb *));
86 static void print_svr4_tchars __P((const char *, struct svr4_tchars *));
87 static void print_svr4_ltchars __P((const char *, struct svr4_ltchars *));
88
89 static void
90 print_svr4_sgttyb(str, ss)
91 const char *str;
92 struct svr4_sgttyb *ss;
93 {
94
95 uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
96 uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
97 ss->sg_flags);
98 }
99
100 static void
101 print_svr4_tchars(str, st)
102 const char *str;
103 struct svr4_tchars *st;
104 {
105 uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
106 uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
107 st->t_stopc, st->t_eofc, st->t_brkc);
108 }
109
110 static void
111 print_svr4_ltchars(str, sl)
112 const char *str;
113 struct svr4_ltchars *sl;
114 {
115 uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
116 uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
117 sl->t_flushc, sl->t_werasc, sl->t_lnextc);
118 }
119 #endif /* DEBUG_SVR4 */
120
121 static void
122 svr4_tchars_to_bsd_tchars(st, bt)
123 const struct svr4_tchars *st;
124 struct tchars *bt;
125 {
126 bt->t_intrc = st->t_intrc;
127 bt->t_quitc = st->t_quitc;
128 bt->t_startc = st->t_startc;
129 bt->t_stopc = st->t_stopc;
130 bt->t_eofc = st->t_eofc;
131 bt->t_brkc = st->t_brkc;
132 }
133
134
135 static void
136 bsd_tchars_to_svr4_tchars(bt, st)
137 const struct tchars *bt;
138 struct svr4_tchars *st;
139 {
140 st->t_intrc = bt->t_intrc;
141 st->t_quitc = bt->t_quitc;
142 st->t_startc = bt->t_startc;
143 st->t_stopc = bt->t_stopc;
144 st->t_eofc = bt->t_eofc;
145 st->t_brkc = bt->t_brkc;
146 }
147
148
149 static void
150 svr4_sgttyb_to_bsd_sgttyb(ss, bs)
151 const struct svr4_sgttyb *ss;
152 struct sgttyb *bs;
153 {
154 bs->sg_ispeed = ss->sg_ispeed;
155 bs->sg_ospeed = ss->sg_ospeed;
156 bs->sg_erase = ss->sg_erase;
157 bs->sg_kill = ss->sg_kill;
158 bs->sg_flags = ss->sg_flags;
159 }
160
161
162 static void
163 bsd_sgttyb_to_svr4_sgttyb(bs, ss)
164 const struct sgttyb *bs;
165 struct svr4_sgttyb *ss;
166 {
167 ss->sg_ispeed = bs->sg_ispeed;
168 ss->sg_ospeed = bs->sg_ospeed;
169 ss->sg_erase = bs->sg_erase;
170 ss->sg_kill = bs->sg_kill;
171 ss->sg_flags = bs->sg_flags;
172 }
173
174
175 static void
176 svr4_ltchars_to_bsd_ltchars(sl, bl)
177 const struct svr4_ltchars *sl;
178 struct ltchars *bl;
179 {
180 bl->t_suspc = sl->t_suspc;
181 bl->t_dsuspc = sl->t_dsuspc;
182 bl->t_rprntc = sl->t_rprntc;
183 bl->t_flushc = sl->t_flushc;
184 bl->t_werasc = sl->t_werasc;
185 bl->t_lnextc = sl->t_lnextc;
186 }
187
188
189 static void
190 bsd_ltchars_to_svr4_ltchars(bl, sl)
191 const struct ltchars *bl;
192 struct svr4_ltchars *sl;
193 {
194 sl->t_suspc = bl->t_suspc;
195 sl->t_dsuspc = bl->t_dsuspc;
196 sl->t_rprntc = bl->t_rprntc;
197 sl->t_flushc = bl->t_flushc;
198 sl->t_werasc = bl->t_werasc;
199 sl->t_lnextc = bl->t_lnextc;
200 }
201
202
203 int
204 svr4_ttold_ioctl(struct file *fp, struct lwp *l, register_t *retval,
205 int fd, u_long cmd, caddr_t data)
206 {
207 int error;
208 int (*ctl)(struct file *, u_long, void *, struct lwp *) =
209 fp->f_ops->fo_ioctl;
210
211 *retval = 0;
212
213 switch (cmd) {
214 case SVR4_TIOCGPGRP:
215 {
216 pid_t pid;
217
218 if ((error = (*ctl)(fp, TIOCGPGRP,
219 (caddr_t) &pid, l)) != 0)
220 return error;
221
222 DPRINTF(("TIOCGPGRP %d\n", pid));
223
224 if ((error = copyout(&pid, data, sizeof(pid))) != 0)
225 return error;
226
227 }
228
229 case SVR4_TIOCSPGRP:
230 {
231 pid_t pid;
232
233 if ((error = copyin(data, &pid, sizeof(pid))) != 0)
234 return error;
235
236 DPRINTF(("TIOCSPGRP %d\n", pid));
237
238 return (*ctl)(fp, TIOCSPGRP, (caddr_t) &pid, l);
239 }
240
241 case SVR4_TIOCGSID:
242 {
243 pid_t pid;
244
245 if ((error = (*ctl)(fp, TIOCGSID,
246 (caddr_t) &pid, l)) != 0)
247 return error;
248
249 DPRINTF(("TIOCGSID %d\n", pid));
250
251 return copyout(&pid, data, sizeof(pid));
252 }
253
254 case SVR4_TIOCGETP:
255 {
256 struct sgttyb bs;
257 struct svr4_sgttyb ss;
258
259 error = (*ctl)(fp, TIOCGETP, (caddr_t) &bs, l);
260 if (error)
261 return error;
262
263 bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
264 #ifdef DEBUG_SVR4
265 print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
266 #endif /* DEBUG_SVR4 */
267 return copyout(&ss, data, sizeof(ss));
268 }
269
270 case SVR4_TIOCSETP:
271 case SVR4_TIOCSETN:
272 {
273 struct sgttyb bs;
274 struct svr4_sgttyb ss;
275
276 if ((error = copyin(data, &ss, sizeof(ss))) != 0)
277 return error;
278
279 svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
280 #ifdef DEBUG_SVR4
281 print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
282 #endif /* DEBUG_SVR4 */
283 cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
284 return (*ctl)(fp, cmd, (caddr_t) &bs, l);
285 }
286
287 case SVR4_TIOCGETC:
288 {
289 struct tchars bt;
290 struct svr4_tchars st;
291
292 error = (*ctl)(fp, TIOCGETC, (caddr_t) &bt, l);
293 if (error)
294 return error;
295
296 bsd_tchars_to_svr4_tchars(&bt, &st);
297 #ifdef DEBUG_SVR4
298 print_svr4_tchars("SVR4_TIOCGETC", &st);
299 #endif /* DEBUG_SVR4 */
300 return copyout(&st, data, sizeof(st));
301 }
302
303 case SVR4_TIOCSETC:
304 {
305 struct tchars bt;
306 struct svr4_tchars st;
307
308 if ((error = copyin(data, &st, sizeof(st))) != 0)
309 return error;
310
311 svr4_tchars_to_bsd_tchars(&st, &bt);
312 #ifdef DEBUG_SVR4
313 print_svr4_tchars("SVR4_TIOCSETC", &st);
314 #endif /* DEBUG_SVR4 */
315 return (*ctl)(fp, TIOCSETC, (caddr_t) &bt, l);
316 }
317
318 case SVR4_TIOCGLTC:
319 {
320 struct ltchars bl;
321 struct svr4_ltchars sl;
322
323 error = (*ctl)(fp, TIOCGLTC, (caddr_t) &bl, l);
324 if (error)
325 return error;
326
327 bsd_ltchars_to_svr4_ltchars(&bl, &sl);
328 #ifdef DEBUG_SVR4
329 print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
330 #endif /* DEBUG_SVR4 */
331 return copyout(&sl, data, sizeof(sl));
332 }
333
334 case SVR4_TIOCSLTC:
335 {
336 struct ltchars bl;
337 struct svr4_ltchars sl;
338
339 if ((error = copyin(data, &sl, sizeof(sl))) != 0)
340 return error;
341
342 svr4_ltchars_to_bsd_ltchars(&sl, &bl);
343 #ifdef DEBUG_SVR4
344 print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
345 #endif /* DEBUG_SVR4 */
346 return (*ctl)(fp, TIOCSLTC, (caddr_t) &bl, l);
347 }
348
349 case SVR4_TIOCLGET:
350 {
351 int flags;
352 if ((error = (*ctl)(fp, TIOCLGET,
353 (caddr_t) &flags, l)) != 0)
354 return error;
355 DPRINTF(("SVR4_TIOCLGET %o\n", flags));
356 return copyout(&flags, data, sizeof(flags));
357 }
358
359 case SVR4_TIOCLSET:
360 case SVR4_TIOCLBIS:
361 case SVR4_TIOCLBIC:
362 {
363 int flags;
364
365 if ((error = copyin(data, &flags, sizeof(flags))) != 0)
366 return error;
367
368 switch (cmd) {
369 case SVR4_TIOCLSET:
370 cmd = TIOCLSET;
371 break;
372 case SVR4_TIOCLBIS:
373 cmd = TIOCLBIS;
374 break;
375 case SVR4_TIOCLBIC:
376 cmd = TIOCLBIC;
377 break;
378 }
379
380 DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
381 return (*ctl)(fp, cmd, (caddr_t) &flags, l);
382 }
383
384 default:
385 DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
386 return 0; /* ENOSYS really */
387 }
388 }
Cache object: 77f1a622b17d95aca22b9586b99d338a
|