2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1994 Christos Zoulas
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/filedesc.h>
39 #include <sys/ioctl_compat.h>
40 #include <sys/termios.h>
42 #include <compat/svr4/svr4.h>
43 #include <compat/svr4/svr4_util.h>
44 #include <compat/svr4/svr4_ttold.h>
45 #include <compat/svr4/svr4_ioctl.h>
48 static void svr4_tchars_to_bsd_tchars(const struct svr4_tchars *st,
50 static void bsd_tchars_to_svr4_tchars(const struct tchars *bt,
51 struct svr4_tchars *st);
52 static void svr4_sgttyb_to_bsd_sgttyb(const struct svr4_sgttyb *ss,
54 static void bsd_sgttyb_to_svr4_sgttyb(const struct sgttyb *bs,
55 struct svr4_sgttyb *ss);
56 static void svr4_ltchars_to_bsd_ltchars(const struct svr4_ltchars *sl,
58 static void bsd_ltchars_to_svr4_ltchars(const struct ltchars *bl,
59 struct svr4_ltchars *sl);
62 static void print_svr4_sgttyb(const char *, struct svr4_sgttyb *);
63 static void print_svr4_tchars(const char *, struct svr4_tchars *);
64 static void print_svr4_ltchars(const char *, struct svr4_ltchars *);
67 print_svr4_sgttyb(str, ss)
69 struct svr4_sgttyb *ss;
72 uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
73 uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
78 print_svr4_tchars(str, st)
80 struct svr4_tchars *st;
82 uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
83 uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
84 st->t_stopc, st->t_eofc, st->t_brkc);
88 print_svr4_ltchars(str, sl)
90 struct svr4_ltchars *sl;
92 uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
93 uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
94 sl->t_flushc, sl->t_werasc, sl->t_lnextc);
96 #endif /* DEBUG_SVR4 */
99 svr4_tchars_to_bsd_tchars(st, bt)
100 const struct svr4_tchars *st;
103 bt->t_intrc = st->t_intrc;
104 bt->t_quitc = st->t_quitc;
105 bt->t_startc = st->t_startc;
106 bt->t_stopc = st->t_stopc;
107 bt->t_eofc = st->t_eofc;
108 bt->t_brkc = st->t_brkc;
113 bsd_tchars_to_svr4_tchars(bt, st)
114 const struct tchars *bt;
115 struct svr4_tchars *st;
117 st->t_intrc = bt->t_intrc;
118 st->t_quitc = bt->t_quitc;
119 st->t_startc = bt->t_startc;
120 st->t_stopc = bt->t_stopc;
121 st->t_eofc = bt->t_eofc;
122 st->t_brkc = bt->t_brkc;
127 svr4_sgttyb_to_bsd_sgttyb(ss, bs)
128 const struct svr4_sgttyb *ss;
131 bs->sg_ispeed = ss->sg_ispeed;
132 bs->sg_ospeed = ss->sg_ospeed;
133 bs->sg_erase = ss->sg_erase;
134 bs->sg_kill = ss->sg_kill;
135 bs->sg_flags = ss->sg_flags;
140 bsd_sgttyb_to_svr4_sgttyb(bs, ss)
141 const struct sgttyb *bs;
142 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;
153 svr4_ltchars_to_bsd_ltchars(sl, bl)
154 const struct svr4_ltchars *sl;
157 bl->t_suspc = sl->t_suspc;
158 bl->t_dsuspc = sl->t_dsuspc;
159 bl->t_rprntc = sl->t_rprntc;
160 bl->t_flushc = sl->t_flushc;
161 bl->t_werasc = sl->t_werasc;
162 bl->t_lnextc = sl->t_lnextc;
167 bsd_ltchars_to_svr4_ltchars(bl, sl)
168 const struct ltchars *bl;
169 struct svr4_ltchars *sl;
171 sl->t_suspc = bl->t_suspc;
172 sl->t_dsuspc = bl->t_dsuspc;
173 sl->t_rprntc = bl->t_rprntc;
174 sl->t_flushc = bl->t_flushc;
175 sl->t_werasc = bl->t_werasc;
176 sl->t_lnextc = bl->t_lnextc;
181 svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
198 if ((error = fo_ioctl(fp, TIOCGPGRP, (caddr_t) &pid,
199 td->td_ucred, td)) != 0)
202 DPRINTF(("TIOCGPGRP %d\n", pid));
204 if ((error = copyout(&pid, data, sizeof(pid))) != 0)
213 if ((error = copyin(data, &pid, sizeof(pid))) != 0)
216 DPRINTF(("TIOCSPGRP %d\n", pid));
218 return fo_ioctl(fp, TIOCSPGRP, (caddr_t) &pid,
224 #if defined(TIOCGSID)
226 if ((error = fo_ioctl(fp, TIOCGSID, (caddr_t) &pid,
227 td->td_ucred, td)) != 0)
230 DPRINTF(("TIOCGSID %d\n", pid));
232 return copyout(&pid, data, sizeof(pid));
234 uprintf("ioctl(TIOCGSID) for pid %d unsupported\n", td->td_proc->p_pid);
242 struct svr4_sgttyb ss;
244 error = fo_ioctl(fp, TIOCGETP, (caddr_t) &bs,
249 bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
251 print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
252 #endif /* DEBUG_SVR4 */
253 return copyout(&ss, data, sizeof(ss));
260 struct svr4_sgttyb ss;
262 if ((error = copyin(data, &ss, sizeof(ss))) != 0)
265 svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
267 print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
268 #endif /* DEBUG_SVR4 */
269 cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
270 return fo_ioctl(fp, cmd, (caddr_t) &bs,
277 struct svr4_tchars st;
279 error = fo_ioctl(fp, TIOCGETC, (caddr_t) &bt,
284 bsd_tchars_to_svr4_tchars(&bt, &st);
286 print_svr4_tchars("SVR4_TIOCGETC", &st);
287 #endif /* DEBUG_SVR4 */
288 return copyout(&st, data, sizeof(st));
294 struct svr4_tchars st;
296 if ((error = copyin(data, &st, sizeof(st))) != 0)
299 svr4_tchars_to_bsd_tchars(&st, &bt);
301 print_svr4_tchars("SVR4_TIOCSETC", &st);
302 #endif /* DEBUG_SVR4 */
303 return fo_ioctl(fp, TIOCSETC, (caddr_t) &bt,
310 struct svr4_ltchars sl;
312 error = fo_ioctl(fp, TIOCGLTC, (caddr_t) &bl,
317 bsd_ltchars_to_svr4_ltchars(&bl, &sl);
319 print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
320 #endif /* DEBUG_SVR4 */
321 return copyout(&sl, data, sizeof(sl));
327 struct svr4_ltchars sl;
329 if ((error = copyin(data, &sl, sizeof(sl))) != 0)
332 svr4_ltchars_to_bsd_ltchars(&sl, &bl);
334 print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
335 #endif /* DEBUG_SVR4 */
336 return fo_ioctl(fp, TIOCSLTC, (caddr_t) &bl,
343 if ((error = fo_ioctl(fp, TIOCLGET, (caddr_t) &flags,
344 td->td_ucred, td)) != 0)
346 DPRINTF(("SVR4_TIOCLGET %o\n", flags));
347 return copyout(&flags, data, sizeof(flags));
356 if ((error = copyin(data, &flags, sizeof(flags))) != 0)
371 DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
372 return fo_ioctl(fp, cmd, (caddr_t) &flags,
377 DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
378 return 0; /* ENOSYS really */
382 #endif /* BURN_BRIDGES */