No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / svr4 / svr4_ttold.c
blobc625869a5479595a8ab80a17bc476028600440f8
1 /* $NetBSD: svr4_ttold.c,v 1.32 2008/03/21 21:54:59 ad Exp $ */
3 /*-
4 * Copyright (c) 1994, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: svr4_ttold.c,v 1.32 2008/03/21 21:54:59 ad Exp $");
35 #include <sys/param.h>
36 #include <sys/proc.h>
37 #include <sys/systm.h>
38 #include <sys/file.h>
39 #include <sys/filedesc.h>
40 #include <sys/ioctl.h>
41 #include <sys/termios.h>
42 #include <sys/tty.h>
43 #include <sys/socket.h>
44 #include <sys/mount.h>
45 #include <net/if.h>
46 #include <sys/malloc.h>
47 #include <sys/ioctl_compat.h>
49 #include <sys/syscallargs.h>
51 #include <compat/svr4/svr4_types.h>
52 #include <compat/svr4/svr4_util.h>
53 #include <compat/svr4/svr4_signal.h>
54 #include <compat/svr4/svr4_lwp.h>
55 #include <compat/svr4/svr4_ucontext.h>
56 #include <compat/svr4/svr4_syscallargs.h>
57 #include <compat/svr4/svr4_stropts.h>
58 #include <compat/svr4/svr4_ttold.h>
59 #include <compat/svr4/svr4_ioctl.h>
62 static void svr4_tchars_to_bsd_tchars(const struct svr4_tchars *st,
63 struct tchars *bt);
64 static void bsd_tchars_to_svr4_tchars(const struct tchars *bt,
65 struct svr4_tchars *st);
66 static void svr4_sgttyb_to_bsd_sgttyb(const struct svr4_sgttyb *ss,
67 struct sgttyb *bs);
68 static void bsd_sgttyb_to_svr4_sgttyb(const struct sgttyb *bs,
69 struct svr4_sgttyb *ss);
70 static void svr4_ltchars_to_bsd_ltchars(const struct svr4_ltchars *sl,
71 struct ltchars *bl);
72 static void bsd_ltchars_to_svr4_ltchars(const struct ltchars *bl,
73 struct svr4_ltchars *sl);
75 #ifdef DEBUG_SVR4
76 static void print_svr4_sgttyb(const char *, struct svr4_sgttyb *);
77 static void print_svr4_tchars(const char *, struct svr4_tchars *);
78 static void print_svr4_ltchars(const char *, struct svr4_ltchars *);
80 static void
81 print_svr4_sgttyb(const char *str, struct svr4_sgttyb *ss)
84 uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
85 uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
86 ss->sg_flags);
89 static void
90 print_svr4_tchars(const char *str, struct svr4_tchars *st)
92 uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
93 uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
94 st->t_stopc, st->t_eofc, st->t_brkc);
97 static void
98 print_svr4_ltchars(const char *str, struct svr4_ltchars *sl)
100 uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
101 uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
102 sl->t_flushc, sl->t_werasc, sl->t_lnextc);
104 #endif /* DEBUG_SVR4 */
106 static void
107 svr4_tchars_to_bsd_tchars(const struct svr4_tchars *st, struct tchars *bt)
109 bt->t_intrc = st->t_intrc;
110 bt->t_quitc = st->t_quitc;
111 bt->t_startc = st->t_startc;
112 bt->t_stopc = st->t_stopc;
113 bt->t_eofc = st->t_eofc;
114 bt->t_brkc = st->t_brkc;
118 static void
119 bsd_tchars_to_svr4_tchars(const struct tchars *bt, struct svr4_tchars *st)
121 st->t_intrc = bt->t_intrc;
122 st->t_quitc = bt->t_quitc;
123 st->t_startc = bt->t_startc;
124 st->t_stopc = bt->t_stopc;
125 st->t_eofc = bt->t_eofc;
126 st->t_brkc = bt->t_brkc;
130 static void
131 svr4_sgttyb_to_bsd_sgttyb(const struct svr4_sgttyb *ss, struct sgttyb *bs)
133 bs->sg_ispeed = ss->sg_ispeed;
134 bs->sg_ospeed = ss->sg_ospeed;
135 bs->sg_erase = ss->sg_erase;
136 bs->sg_kill = ss->sg_kill;
137 bs->sg_flags = ss->sg_flags;
141 static void
142 bsd_sgttyb_to_svr4_sgttyb(const struct sgttyb *bs, struct svr4_sgttyb *ss)
144 ss->sg_ispeed = bs->sg_ispeed;
145 ss->sg_ospeed = bs->sg_ospeed;
146 ss->sg_erase = bs->sg_erase;
147 ss->sg_kill = bs->sg_kill;
148 ss->sg_flags = bs->sg_flags;
152 static void
153 svr4_ltchars_to_bsd_ltchars(const struct svr4_ltchars *sl, struct ltchars *bl)
155 bl->t_suspc = sl->t_suspc;
156 bl->t_dsuspc = sl->t_dsuspc;
157 bl->t_rprntc = sl->t_rprntc;
158 bl->t_flushc = sl->t_flushc;
159 bl->t_werasc = sl->t_werasc;
160 bl->t_lnextc = sl->t_lnextc;
164 static void
165 bsd_ltchars_to_svr4_ltchars(const struct ltchars *bl, struct svr4_ltchars *sl)
167 sl->t_suspc = bl->t_suspc;
168 sl->t_dsuspc = bl->t_dsuspc;
169 sl->t_rprntc = bl->t_rprntc;
170 sl->t_flushc = bl->t_flushc;
171 sl->t_werasc = bl->t_werasc;
172 sl->t_lnextc = bl->t_lnextc;
177 svr4_ttold_ioctl(file_t *fp, struct lwp *l, register_t *retval,
178 int fd, u_long cmd, void *data)
180 int error;
181 int (*ctl)(file_t *, u_long, void *) = fp->f_ops->fo_ioctl;
183 *retval = 0;
185 switch (cmd) {
186 case SVR4_TIOCGPGRP:
188 pid_t pid;
190 if ((error = (*ctl)(fp, TIOCGPGRP, &pid)) != 0)
191 return error;
193 DPRINTF(("TIOCGPGRP %d\n", pid));
195 if ((error = copyout(&pid, data, sizeof(pid))) != 0)
196 return error;
200 case SVR4_TIOCSPGRP:
202 pid_t pid;
204 if ((error = copyin(data, &pid, sizeof(pid))) != 0)
205 return error;
207 DPRINTF(("TIOCSPGRP %d\n", pid));
209 return (*ctl)(fp, TIOCSPGRP, &pid);
212 case SVR4_TIOCGSID:
214 pid_t pid;
216 if ((error = (*ctl)(fp, TIOCGSID, &pid)) != 0)
217 return error;
219 DPRINTF(("TIOCGSID %d\n", pid));
221 return copyout(&pid, data, sizeof(pid));
224 case SVR4_TIOCGETP:
226 struct sgttyb bs;
227 struct svr4_sgttyb ss;
229 error = (*ctl)(fp, TIOCGETP, &bs);
230 if (error)
231 return error;
233 bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
234 #ifdef DEBUG_SVR4
235 print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
236 #endif /* DEBUG_SVR4 */
237 return copyout(&ss, data, sizeof(ss));
240 case SVR4_TIOCSETP:
241 case SVR4_TIOCSETN:
243 struct sgttyb bs;
244 struct svr4_sgttyb ss;
246 if ((error = copyin(data, &ss, sizeof(ss))) != 0)
247 return error;
249 svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
250 #ifdef DEBUG_SVR4
251 print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
252 #endif /* DEBUG_SVR4 */
253 cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
254 return (*ctl)(fp, cmd, &bs);
257 case SVR4_TIOCGETC:
259 struct tchars bt;
260 struct svr4_tchars st;
262 error = (*ctl)(fp, TIOCGETC, &bt);
263 if (error)
264 return error;
266 bsd_tchars_to_svr4_tchars(&bt, &st);
267 #ifdef DEBUG_SVR4
268 print_svr4_tchars("SVR4_TIOCGETC", &st);
269 #endif /* DEBUG_SVR4 */
270 return copyout(&st, data, sizeof(st));
273 case SVR4_TIOCSETC:
275 struct tchars bt;
276 struct svr4_tchars st;
278 if ((error = copyin(data, &st, sizeof(st))) != 0)
279 return error;
281 svr4_tchars_to_bsd_tchars(&st, &bt);
282 #ifdef DEBUG_SVR4
283 print_svr4_tchars("SVR4_TIOCSETC", &st);
284 #endif /* DEBUG_SVR4 */
285 return (*ctl)(fp, TIOCSETC, &bt);
288 case SVR4_TIOCGLTC:
290 struct ltchars bl;
291 struct svr4_ltchars sl;
293 error = (*ctl)(fp, TIOCGLTC, &bl);
294 if (error)
295 return error;
297 bsd_ltchars_to_svr4_ltchars(&bl, &sl);
298 #ifdef DEBUG_SVR4
299 print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
300 #endif /* DEBUG_SVR4 */
301 return copyout(&sl, data, sizeof(sl));
304 case SVR4_TIOCSLTC:
306 struct ltchars bl;
307 struct svr4_ltchars sl;
309 if ((error = copyin(data, &sl, sizeof(sl))) != 0)
310 return error;
312 svr4_ltchars_to_bsd_ltchars(&sl, &bl);
313 #ifdef DEBUG_SVR4
314 print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
315 #endif /* DEBUG_SVR4 */
316 return (*ctl)(fp, TIOCSLTC, &bl);
319 case SVR4_TIOCLGET:
321 int flags;
322 if ((error = (*ctl)(fp, TIOCLGET, &flags)) != 0)
323 return error;
324 DPRINTF(("SVR4_TIOCLGET %o\n", flags));
325 return copyout(&flags, data, sizeof(flags));
328 case SVR4_TIOCLSET:
329 case SVR4_TIOCLBIS:
330 case SVR4_TIOCLBIC:
332 int flags;
334 if ((error = copyin(data, &flags, sizeof(flags))) != 0)
335 return error;
337 switch (cmd) {
338 case SVR4_TIOCLSET:
339 cmd = TIOCLSET;
340 break;
341 case SVR4_TIOCLBIS:
342 cmd = TIOCLBIS;
343 break;
344 case SVR4_TIOCLBIC:
345 cmd = TIOCLBIC;
346 break;
349 DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
350 return (*ctl)(fp, cmd, &flags);
353 default:
354 DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
355 return 0; /* ENOSYS really */