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.
28 * $FreeBSD: src/sys/svr4/svr4_ttold.c,v 1.7 1999/12/08 12:00:49 newton Exp $
31 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/filedesc.h>
36 #include <sys/ioctl_compat.h>
37 #include <sys/termios.h>
39 #include <svr4/svr4.h>
40 #include <svr4/svr4_util.h>
41 #include <svr4/svr4_ttold.h>
42 #include <svr4/svr4_ioctl.h>
45 static void svr4_tchars_to_bsd_tchars __P((const struct svr4_tchars *st,
47 static void bsd_tchars_to_svr4_tchars __P((const struct tchars *bt,
48 struct svr4_tchars *st));
49 static void svr4_sgttyb_to_bsd_sgttyb __P((const struct svr4_sgttyb *ss,
51 static void bsd_sgttyb_to_svr4_sgttyb __P((const struct sgttyb *bs,
52 struct svr4_sgttyb *ss));
53 static void svr4_ltchars_to_bsd_ltchars __P((const struct svr4_ltchars *sl,
55 static void bsd_ltchars_to_svr4_ltchars __P((const struct ltchars *bl,
56 struct svr4_ltchars *sl));
59 static void print_svr4_sgttyb __P((const char *, struct svr4_sgttyb *));
60 static void print_svr4_tchars __P((const char *, struct svr4_tchars *));
61 static void print_svr4_ltchars __P((const char *, struct svr4_ltchars *));
64 print_svr4_sgttyb(str, ss)
66 struct svr4_sgttyb *ss;
69 uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
70 uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
75 print_svr4_tchars(str, st)
77 struct svr4_tchars *st;
79 uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
80 uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
81 st->t_stopc, st->t_eofc, st->t_brkc);
85 print_svr4_ltchars(str, sl)
87 struct svr4_ltchars *sl;
89 uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
90 uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
91 sl->t_flushc, sl->t_werasc, sl->t_lnextc);
93 #endif /* DEBUG_SVR4 */
96 svr4_tchars_to_bsd_tchars(st, bt)
97 const struct svr4_tchars *st;
100 bt->t_intrc = st->t_intrc;
101 bt->t_quitc = st->t_quitc;
102 bt->t_startc = st->t_startc;
103 bt->t_stopc = st->t_stopc;
104 bt->t_eofc = st->t_eofc;
105 bt->t_brkc = st->t_brkc;
110 bsd_tchars_to_svr4_tchars(bt, st)
111 const struct tchars *bt;
112 struct svr4_tchars *st;
114 st->t_intrc = bt->t_intrc;
115 st->t_quitc = bt->t_quitc;
116 st->t_startc = bt->t_startc;
117 st->t_stopc = bt->t_stopc;
118 st->t_eofc = bt->t_eofc;
119 st->t_brkc = bt->t_brkc;
124 svr4_sgttyb_to_bsd_sgttyb(ss, bs)
125 const struct svr4_sgttyb *ss;
128 bs->sg_ispeed = ss->sg_ispeed;
129 bs->sg_ospeed = ss->sg_ospeed;
130 bs->sg_erase = ss->sg_erase;
131 bs->sg_kill = ss->sg_kill;
132 bs->sg_flags = ss->sg_flags;
137 bsd_sgttyb_to_svr4_sgttyb(bs, ss)
138 const struct sgttyb *bs;
139 struct svr4_sgttyb *ss;
141 ss->sg_ispeed = bs->sg_ispeed;
142 ss->sg_ospeed = bs->sg_ospeed;
143 ss->sg_erase = bs->sg_erase;
144 ss->sg_kill = bs->sg_kill;
145 ss->sg_flags = bs->sg_flags;
150 svr4_ltchars_to_bsd_ltchars(sl, bl)
151 const struct svr4_ltchars *sl;
154 bl->t_suspc = sl->t_suspc;
155 bl->t_dsuspc = sl->t_dsuspc;
156 bl->t_rprntc = sl->t_rprntc;
157 bl->t_flushc = sl->t_flushc;
158 bl->t_werasc = sl->t_werasc;
159 bl->t_lnextc = sl->t_lnextc;
164 bsd_ltchars_to_svr4_ltchars(bl, sl)
165 const struct ltchars *bl;
166 struct svr4_ltchars *sl;
168 sl->t_suspc = bl->t_suspc;
169 sl->t_dsuspc = bl->t_dsuspc;
170 sl->t_rprntc = bl->t_rprntc;
171 sl->t_flushc = bl->t_flushc;
172 sl->t_werasc = bl->t_werasc;
173 sl->t_lnextc = bl->t_lnextc;
178 svr4_ttold_ioctl(fp, p, retval, fd, cmd, data)
195 if ((error = fo_ioctl(fp, TIOCGPGRP, (caddr_t) &pid, p)) != 0)
198 DPRINTF(("TIOCGPGRP %d\n", pid));
200 if ((error = copyout(&pid, data, sizeof(pid))) != 0)
209 if ((error = copyin(data, &pid, sizeof(pid))) != 0)
212 DPRINTF(("TIOCSPGRP %d\n", pid));
214 return fo_ioctl(fp, TIOCSPGRP, (caddr_t) &pid, p);
219 #if defined(TIOCGSID)
221 if ((error = fo_ioctl(fp, TIOCGSID, (caddr_t) &pid, p)) != 0)
224 DPRINTF(("TIOCGSID %d\n", pid));
226 return copyout(&pid, data, sizeof(pid));
228 uprintf("ioctl(TIOCGSID) for pid %d unsupported\n", p->p_pid);
236 struct svr4_sgttyb ss;
238 error = fo_ioctl(fp, TIOCGETP, (caddr_t) &bs, p);
242 bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
244 print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
245 #endif /* DEBUG_SVR4 */
246 return copyout(&ss, data, sizeof(ss));
253 struct svr4_sgttyb ss;
255 if ((error = copyin(data, &ss, sizeof(ss))) != 0)
258 svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
260 print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
261 #endif /* DEBUG_SVR4 */
262 cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
263 return fo_ioctl(fp, cmd, (caddr_t) &bs, p);
269 struct svr4_tchars st;
271 error = fo_ioctl(fp, TIOCGETC, (caddr_t) &bt, p);
275 bsd_tchars_to_svr4_tchars(&bt, &st);
277 print_svr4_tchars("SVR4_TIOCGETC", &st);
278 #endif /* DEBUG_SVR4 */
279 return copyout(&st, data, sizeof(st));
285 struct svr4_tchars st;
287 if ((error = copyin(data, &st, sizeof(st))) != 0)
290 svr4_tchars_to_bsd_tchars(&st, &bt);
292 print_svr4_tchars("SVR4_TIOCSETC", &st);
293 #endif /* DEBUG_SVR4 */
294 return fo_ioctl(fp, TIOCSETC, (caddr_t) &bt, p);
300 struct svr4_ltchars sl;
302 error = fo_ioctl(fp, TIOCGLTC, (caddr_t) &bl, p);
306 bsd_ltchars_to_svr4_ltchars(&bl, &sl);
308 print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
309 #endif /* DEBUG_SVR4 */
310 return copyout(&sl, data, sizeof(sl));
316 struct svr4_ltchars sl;
318 if ((error = copyin(data, &sl, sizeof(sl))) != 0)
321 svr4_ltchars_to_bsd_ltchars(&sl, &bl);
323 print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
324 #endif /* DEBUG_SVR4 */
325 return fo_ioctl(fp, TIOCSLTC, (caddr_t) &bl, p);
331 if ((error = fo_ioctl(fp, TIOCLGET, (caddr_t) &flags, p)) != 0)
333 DPRINTF(("SVR4_TIOCLGET %o\n", flags));
334 return copyout(&flags, data, sizeof(flags));
343 if ((error = copyin(data, &flags, sizeof(flags))) != 0)
358 DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
359 return fo_ioctl(fp, cmd, (caddr_t) &flags, p);
363 DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
364 return 0; /* ENOSYS really */