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.
31 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/filedesc.h>
36 #include <sys/fcntl.h>
37 #include <sys/ioctl_compat.h>
38 #include <sys/unistd.h>
39 #include <sys/termios.h>
41 #include <sys/socket.h>
42 #include <sys/mount.h>
44 #include <sys/malloc.h>
46 #include <sys/sysproto.h>
48 #include <svr4/svr4_types.h>
49 #include <svr4/svr4_util.h>
50 #include <svr4/svr4_signal.h>
51 #include <svr4/svr4_proto.h>
52 #include <svr4/svr4_stropts.h>
53 #include <svr4/svr4_ttold.h>
54 #include <svr4/svr4_ioctl.h>
57 static void svr4_tchars_to_bsd_tchars __P((const struct svr4_tchars *st,
59 static void bsd_tchars_to_svr4_tchars __P((const struct tchars *bt,
60 struct svr4_tchars *st));
61 static void svr4_sgttyb_to_bsd_sgttyb __P((const struct svr4_sgttyb *ss,
63 static void bsd_sgttyb_to_svr4_sgttyb __P((const struct sgttyb *bs,
64 struct svr4_sgttyb *ss));
65 static void svr4_ltchars_to_bsd_ltchars __P((const struct svr4_ltchars *sl,
67 static void bsd_ltchars_to_svr4_ltchars __P((const struct ltchars *bl,
68 struct svr4_ltchars *sl));
71 static void print_svr4_sgttyb __P((const char *, struct svr4_sgttyb *));
72 static void print_svr4_tchars __P((const char *, struct svr4_tchars *));
73 static void print_svr4_ltchars __P((const char *, struct svr4_ltchars *));
76 print_svr4_sgttyb(str, ss)
78 struct svr4_sgttyb *ss;
81 uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
82 uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
87 print_svr4_tchars(str, st)
89 struct svr4_tchars *st;
91 uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
92 uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
93 st->t_stopc, st->t_eofc, st->t_brkc);
97 print_svr4_ltchars(str, sl)
99 struct svr4_ltchars *sl;
101 uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
102 uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
103 sl->t_flushc, sl->t_werasc, sl->t_lnextc);
105 #endif /* DEBUG_SVR4 */
108 svr4_tchars_to_bsd_tchars(st, bt)
109 const struct svr4_tchars *st;
112 bt->t_intrc = st->t_intrc;
113 bt->t_quitc = st->t_quitc;
114 bt->t_startc = st->t_startc;
115 bt->t_stopc = st->t_stopc;
116 bt->t_eofc = st->t_eofc;
117 bt->t_brkc = st->t_brkc;
122 bsd_tchars_to_svr4_tchars(bt, st)
123 const struct tchars *bt;
124 struct svr4_tchars *st;
126 st->t_intrc = bt->t_intrc;
127 st->t_quitc = bt->t_quitc;
128 st->t_startc = bt->t_startc;
129 st->t_stopc = bt->t_stopc;
130 st->t_eofc = bt->t_eofc;
131 st->t_brkc = bt->t_brkc;
136 svr4_sgttyb_to_bsd_sgttyb(ss, bs)
137 const struct svr4_sgttyb *ss;
140 bs->sg_ispeed = ss->sg_ispeed;
141 bs->sg_ospeed = ss->sg_ospeed;
142 bs->sg_erase = ss->sg_erase;
143 bs->sg_kill = ss->sg_kill;
144 bs->sg_flags = ss->sg_flags;
149 bsd_sgttyb_to_svr4_sgttyb(bs, ss)
150 const struct sgttyb *bs;
151 struct svr4_sgttyb *ss;
153 ss->sg_ispeed = bs->sg_ispeed;
154 ss->sg_ospeed = bs->sg_ospeed;
155 ss->sg_erase = bs->sg_erase;
156 ss->sg_kill = bs->sg_kill;
157 ss->sg_flags = bs->sg_flags;
162 svr4_ltchars_to_bsd_ltchars(sl, bl)
163 const struct svr4_ltchars *sl;
166 bl->t_suspc = sl->t_suspc;
167 bl->t_dsuspc = sl->t_dsuspc;
168 bl->t_rprntc = sl->t_rprntc;
169 bl->t_flushc = sl->t_flushc;
170 bl->t_werasc = sl->t_werasc;
171 bl->t_lnextc = sl->t_lnextc;
176 bsd_ltchars_to_svr4_ltchars(bl, sl)
177 const struct ltchars *bl;
178 struct svr4_ltchars *sl;
180 sl->t_suspc = bl->t_suspc;
181 sl->t_dsuspc = bl->t_dsuspc;
182 sl->t_rprntc = bl->t_rprntc;
183 sl->t_flushc = bl->t_flushc;
184 sl->t_werasc = bl->t_werasc;
185 sl->t_lnextc = bl->t_lnextc;
190 svr4_ttold_ioctl(fp, p, retval, fd, cmd, data)
199 int (*ctl) __P((struct file *, u_long, caddr_t, struct proc *)) =
209 if ((error = (*ctl)(fp, TIOCGPGRP,
210 (caddr_t) &pid, p)) != 0)
213 DPRINTF(("TIOCGPGRP %d\n", pid));
215 if ((error = copyout(&pid, data, sizeof(pid))) != 0)
224 if ((error = copyin(data, &pid, sizeof(pid))) != 0)
227 DPRINTF(("TIOCSPGRP %d\n", pid));
229 return (*ctl)(fp, TIOCSPGRP, (caddr_t) &pid, p);
234 #if defined(TIOCGSID)
236 if ((error = (*ctl)(fp, TIOCGSID,
237 (caddr_t) &pid, p)) != 0)
240 DPRINTF(("TIOCGSID %d\n", pid));
242 return copyout(&pid, data, sizeof(pid));
244 uprintf("ioctl(TIOCGSID) for pid %d unsupported\n", p->p_pid);
252 struct svr4_sgttyb ss;
254 error = (*ctl)(fp, TIOCGETP, (caddr_t) &bs, p);
258 bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
260 print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
261 #endif /* DEBUG_SVR4 */
262 return copyout(&ss, data, sizeof(ss));
269 struct svr4_sgttyb ss;
271 if ((error = copyin(data, &ss, sizeof(ss))) != 0)
274 svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
276 print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
277 #endif /* DEBUG_SVR4 */
278 cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
279 return (*ctl)(fp, cmd, (caddr_t) &bs, p);
285 struct svr4_tchars st;
287 error = (*ctl)(fp, TIOCGETC, (caddr_t) &bt, p);
291 bsd_tchars_to_svr4_tchars(&bt, &st);
293 print_svr4_tchars("SVR4_TIOCGETC", &st);
294 #endif /* DEBUG_SVR4 */
295 return copyout(&st, data, sizeof(st));
301 struct svr4_tchars st;
303 if ((error = copyin(data, &st, sizeof(st))) != 0)
306 svr4_tchars_to_bsd_tchars(&st, &bt);
308 print_svr4_tchars("SVR4_TIOCSETC", &st);
309 #endif /* DEBUG_SVR4 */
310 return (*ctl)(fp, TIOCSETC, (caddr_t) &bt, p);
316 struct svr4_ltchars sl;
318 error = (*ctl)(fp, TIOCGLTC, (caddr_t) &bl, p);
322 bsd_ltchars_to_svr4_ltchars(&bl, &sl);
324 print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
325 #endif /* DEBUG_SVR4 */
326 return copyout(&sl, data, sizeof(sl));
332 struct svr4_ltchars sl;
334 if ((error = copyin(data, &sl, sizeof(sl))) != 0)
337 svr4_ltchars_to_bsd_ltchars(&sl, &bl);
339 print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
340 #endif /* DEBUG_SVR4 */
341 return (*ctl)(fp, TIOCSLTC, (caddr_t) &bl, p);
347 if ((error = (*ctl)(fp, TIOCLGET,
348 (caddr_t) &flags, p)) != 0)
350 DPRINTF(("SVR4_TIOCLGET %o\n", flags));
351 return copyout(&flags, data, sizeof(flags));
360 if ((error = copyin(data, &flags, sizeof(flags))) != 0)
375 DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
376 return (*ctl)(fp, cmd, (caddr_t) &flags, p);
380 DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
381 return 0; /* ENOSYS really */