]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/svr4/svr4_ttold.c
Add $Id$ tags
[FreeBSD/FreeBSD.git] / sys / svr4 / svr4_ttold.c
1 /*
2  * Copyright (c) 1998 Mark Newton
3  * Copyright (c) 1994 Christos Zoulas
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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
16  *
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.
27  * 
28  * $Id$
29  */
30
31 #include <sys/param.h>
32 #include <sys/proc.h>
33 #include <sys/systm.h>
34 #include <sys/file.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>
40 #include <sys/tty.h>
41 #include <sys/socket.h>
42 #include <sys/mount.h>
43 #include <net/if.h>
44 #include <sys/malloc.h>
45
46 #include <sys/sysproto.h>
47
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>
55
56
57 static void svr4_tchars_to_bsd_tchars __P((const struct svr4_tchars *st,
58                                            struct tchars *bt));
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,
62                                            struct sgttyb *bs));
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,
66                                              struct ltchars *bl));
67 static void bsd_ltchars_to_svr4_ltchars __P((const struct ltchars *bl,
68                                              struct svr4_ltchars *sl));
69
70 #ifdef DEBUG_SVR4
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 *));
74
75 static void
76 print_svr4_sgttyb(str, ss)
77         const char *str;
78         struct svr4_sgttyb *ss;
79 {
80
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,
83             ss->sg_flags);
84 }
85
86 static void
87 print_svr4_tchars(str, st)
88         const char *str;
89         struct svr4_tchars *st;
90 {
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);
94 }
95
96 static void
97 print_svr4_ltchars(str, sl)
98         const char *str;
99         struct svr4_ltchars *sl;
100 {
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);
104 }
105 #endif /* DEBUG_SVR4 */
106
107 static void
108 svr4_tchars_to_bsd_tchars(st, bt)
109         const struct svr4_tchars        *st;
110         struct tchars                   *bt;
111 {
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;
118 }
119
120
121 static void
122 bsd_tchars_to_svr4_tchars(bt, st)
123         const struct tchars     *bt;
124         struct svr4_tchars      *st;
125 {
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;
132 }
133
134
135 static void
136 svr4_sgttyb_to_bsd_sgttyb(ss, bs)
137         const struct svr4_sgttyb        *ss;
138         struct sgttyb                   *bs;
139 {
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;
145 };
146
147
148 static void
149 bsd_sgttyb_to_svr4_sgttyb(bs, ss)
150         const struct sgttyb     *bs;
151         struct svr4_sgttyb      *ss;
152 {
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;
158 }
159
160
161 static void
162 svr4_ltchars_to_bsd_ltchars(sl, bl)
163         const struct svr4_ltchars       *sl;
164         struct ltchars                  *bl;
165 {
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;
172 }
173
174
175 static void
176 bsd_ltchars_to_svr4_ltchars(bl, sl)
177         const struct ltchars    *bl;
178         struct svr4_ltchars     *sl;
179 {
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;
186 }
187
188
189 int
190 svr4_ttold_ioctl(fp, p, retval, fd, cmd, data)
191         struct file *fp;
192         struct proc *p;
193         register_t *retval;
194         int fd;
195         u_long cmd;
196         caddr_t data;
197 {
198         int                     error;
199         int (*ctl) __P((struct file *, u_long,  caddr_t, struct proc *)) =
200                         fp->f_ops->fo_ioctl;
201
202         *retval = 0;
203
204         switch (cmd) {
205         case SVR4_TIOCGPGRP:
206                 {
207                         pid_t pid;
208
209                         if ((error = (*ctl)(fp, TIOCGPGRP,
210                                             (caddr_t) &pid, p)) != 0)
211                             return error;
212
213                         DPRINTF(("TIOCGPGRP %d\n", pid));
214
215                         if ((error = copyout(&pid, data, sizeof(pid))) != 0)
216                                 return error;
217
218                 }
219
220         case SVR4_TIOCSPGRP:
221                 {
222                         pid_t pid;
223
224                         if ((error = copyin(data, &pid, sizeof(pid))) != 0)
225                                 return error;
226
227                         DPRINTF(("TIOCSPGRP %d\n", pid));
228
229                         return (*ctl)(fp, TIOCSPGRP, (caddr_t) &pid, p);
230                 }
231
232         case SVR4_TIOCGSID:
233                 {
234 #if defined(TIOCGSID)
235                         pid_t pid;
236                         if ((error = (*ctl)(fp, TIOCGSID,
237                                             (caddr_t) &pid, p)) != 0)
238                                 return error;
239
240                         DPRINTF(("TIOCGSID %d\n", pid));
241
242                         return copyout(&pid, data, sizeof(pid));
243 #else
244                         uprintf("ioctl(TIOCGSID) for pid %d unsupported\n", p->p_pid);
245                         return EINVAL;
246 #endif
247                 }
248
249         case SVR4_TIOCGETP:
250                 {
251                         struct sgttyb bs;
252                         struct svr4_sgttyb ss;
253
254                         error = (*ctl)(fp, TIOCGETP, (caddr_t) &bs, p);
255                         if (error)
256                                 return error;
257
258                         bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
259 #ifdef DEBUG_SVR4
260                         print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
261 #endif /* DEBUG_SVR4 */
262                         return copyout(&ss, data, sizeof(ss));
263                 }
264
265         case SVR4_TIOCSETP:
266         case SVR4_TIOCSETN:
267                 {
268                         struct sgttyb bs;
269                         struct svr4_sgttyb ss;
270
271                         if ((error = copyin(data, &ss, sizeof(ss))) != 0)
272                                 return error;
273
274                         svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
275 #ifdef DEBUG_SVR4
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);
280                 }
281
282         case SVR4_TIOCGETC:
283                 {
284                         struct tchars bt;
285                         struct svr4_tchars st;
286
287                         error = (*ctl)(fp, TIOCGETC, (caddr_t) &bt, p);
288                         if (error)
289                                 return error;
290
291                         bsd_tchars_to_svr4_tchars(&bt, &st);
292 #ifdef DEBUG_SVR4
293                         print_svr4_tchars("SVR4_TIOCGETC", &st);
294 #endif /* DEBUG_SVR4 */
295                         return copyout(&st, data, sizeof(st));
296                 }
297
298         case SVR4_TIOCSETC:
299                 {
300                         struct tchars bt;
301                         struct svr4_tchars st;
302
303                         if ((error = copyin(data, &st, sizeof(st))) != 0)
304                                 return error;
305
306                         svr4_tchars_to_bsd_tchars(&st, &bt);
307 #ifdef DEBUG_SVR4
308                         print_svr4_tchars("SVR4_TIOCSETC", &st);
309 #endif /* DEBUG_SVR4 */
310                         return (*ctl)(fp, TIOCSETC, (caddr_t) &bt, p);
311                 }
312
313         case SVR4_TIOCGLTC:
314                 {
315                         struct ltchars bl;
316                         struct svr4_ltchars sl;
317
318                         error = (*ctl)(fp, TIOCGLTC, (caddr_t) &bl, p);
319                         if (error)
320                                 return error;
321
322                         bsd_ltchars_to_svr4_ltchars(&bl, &sl);
323 #ifdef DEBUG_SVR4
324                         print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
325 #endif /* DEBUG_SVR4 */
326                         return copyout(&sl, data, sizeof(sl));
327                 }
328
329         case SVR4_TIOCSLTC:
330                 {
331                         struct ltchars bl;
332                         struct svr4_ltchars sl;
333
334                         if ((error = copyin(data, &sl, sizeof(sl))) != 0)
335                                 return error;
336
337                         svr4_ltchars_to_bsd_ltchars(&sl, &bl);
338 #ifdef DEBUG_SVR4
339                         print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
340 #endif /* DEBUG_SVR4 */
341                         return (*ctl)(fp, TIOCSLTC, (caddr_t) &bl, p);
342                 }
343
344         case SVR4_TIOCLGET:
345                 {
346                         int flags;
347                         if ((error = (*ctl)(fp, TIOCLGET,
348                                             (caddr_t) &flags, p)) != 0)
349                                 return error;
350                         DPRINTF(("SVR4_TIOCLGET %o\n", flags));
351                         return copyout(&flags, data, sizeof(flags));
352                 }
353
354         case SVR4_TIOCLSET:
355         case SVR4_TIOCLBIS:
356         case SVR4_TIOCLBIC:
357                 {
358                         int flags;
359
360                         if ((error = copyin(data, &flags, sizeof(flags))) != 0)
361                                 return error;
362
363                         switch (cmd) {
364                         case SVR4_TIOCLSET:
365                                 cmd = TIOCLSET;
366                                 break;
367                         case SVR4_TIOCLBIS:
368                                 cmd = TIOCLBIS;
369                                 break;
370                         case SVR4_TIOCLBIC:
371                                 cmd = TIOCLBIC;
372                                 break;
373                         }
374
375                         DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
376                         return (*ctl)(fp, cmd, (caddr_t) &flags, p);
377                 }
378
379         default:
380                 DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
381                 return 0;       /* ENOSYS really */
382         }
383 }