1 /* $NetBSD: svr4_ttold.c,v 1.32 2008/03/21 21:54:59 ad Exp $ */
4 * Copyright (c) 1994, 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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>
37 #include <sys/systm.h>
39 #include <sys/filedesc.h>
40 #include <sys/ioctl.h>
41 #include <sys/termios.h>
43 #include <sys/socket.h>
44 #include <sys/mount.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
,
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
,
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
,
72 static void bsd_ltchars_to_svr4_ltchars(const struct ltchars
*bl
,
73 struct svr4_ltchars
*sl
);
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
*);
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
,
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
);
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 */
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
;
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
;
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
;
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
;
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
;
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
)
181 int (*ctl
)(file_t
*, u_long
, void *) = fp
->f_ops
->fo_ioctl
;
190 if ((error
= (*ctl
)(fp
, TIOCGPGRP
, &pid
)) != 0)
193 DPRINTF(("TIOCGPGRP %d\n", pid
));
195 if ((error
= copyout(&pid
, data
, sizeof(pid
))) != 0)
204 if ((error
= copyin(data
, &pid
, sizeof(pid
))) != 0)
207 DPRINTF(("TIOCSPGRP %d\n", pid
));
209 return (*ctl
)(fp
, TIOCSPGRP
, &pid
);
216 if ((error
= (*ctl
)(fp
, TIOCGSID
, &pid
)) != 0)
219 DPRINTF(("TIOCGSID %d\n", pid
));
221 return copyout(&pid
, data
, sizeof(pid
));
227 struct svr4_sgttyb ss
;
229 error
= (*ctl
)(fp
, TIOCGETP
, &bs
);
233 bsd_sgttyb_to_svr4_sgttyb(&bs
, &ss
);
235 print_svr4_sgttyb("SVR4_TIOCGETP", &ss
);
236 #endif /* DEBUG_SVR4 */
237 return copyout(&ss
, data
, sizeof(ss
));
244 struct svr4_sgttyb ss
;
246 if ((error
= copyin(data
, &ss
, sizeof(ss
))) != 0)
249 svr4_sgttyb_to_bsd_sgttyb(&ss
, &bs
);
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
);
260 struct svr4_tchars st
;
262 error
= (*ctl
)(fp
, TIOCGETC
, &bt
);
266 bsd_tchars_to_svr4_tchars(&bt
, &st
);
268 print_svr4_tchars("SVR4_TIOCGETC", &st
);
269 #endif /* DEBUG_SVR4 */
270 return copyout(&st
, data
, sizeof(st
));
276 struct svr4_tchars st
;
278 if ((error
= copyin(data
, &st
, sizeof(st
))) != 0)
281 svr4_tchars_to_bsd_tchars(&st
, &bt
);
283 print_svr4_tchars("SVR4_TIOCSETC", &st
);
284 #endif /* DEBUG_SVR4 */
285 return (*ctl
)(fp
, TIOCSETC
, &bt
);
291 struct svr4_ltchars sl
;
293 error
= (*ctl
)(fp
, TIOCGLTC
, &bl
);
297 bsd_ltchars_to_svr4_ltchars(&bl
, &sl
);
299 print_svr4_ltchars("SVR4_TIOCGLTC", &sl
);
300 #endif /* DEBUG_SVR4 */
301 return copyout(&sl
, data
, sizeof(sl
));
307 struct svr4_ltchars sl
;
309 if ((error
= copyin(data
, &sl
, sizeof(sl
))) != 0)
312 svr4_ltchars_to_bsd_ltchars(&sl
, &bl
);
314 print_svr4_ltchars("SVR4_TIOCSLTC", &sl
);
315 #endif /* DEBUG_SVR4 */
316 return (*ctl
)(fp
, TIOCSLTC
, &bl
);
322 if ((error
= (*ctl
)(fp
, TIOCLGET
, &flags
)) != 0)
324 DPRINTF(("SVR4_TIOCLGET %o\n", flags
));
325 return copyout(&flags
, data
, sizeof(flags
));
334 if ((error
= copyin(data
, &flags
, sizeof(flags
))) != 0)
349 DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags
));
350 return (*ctl
)(fp
, cmd
, &flags
);
354 DPRINTF(("Unknown svr4 ttold %lx\n", cmd
));
355 return 0; /* ENOSYS really */