Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / emulation / 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  * $FreeBSD: src/sys/svr4/svr4_ttold.c,v 1.7 1999/12/08 12:00:49 newton Exp $
29  * $DragonFly: src/sys/emulation/svr4/Attic/svr4_ttold.c,v 1.2 2003/06/17 04:28:58 dillon Exp $
30  */
31
32 #include <sys/param.h>
33 #include <sys/proc.h>
34 #include <sys/systm.h>
35 #include <sys/file.h>
36 #include <sys/filedesc.h>
37 #include <sys/ioctl_compat.h>
38 #include <sys/termios.h>
39
40 #include <svr4/svr4.h>
41 #include <svr4/svr4_util.h>
42 #include <svr4/svr4_ttold.h>
43 #include <svr4/svr4_ioctl.h>
44
45
46 static void svr4_tchars_to_bsd_tchars __P((const struct svr4_tchars *st,
47                                            struct tchars *bt));
48 static void bsd_tchars_to_svr4_tchars __P((const struct tchars *bt,
49                                            struct svr4_tchars *st));
50 static void svr4_sgttyb_to_bsd_sgttyb __P((const struct svr4_sgttyb *ss,
51                                            struct sgttyb *bs));
52 static void bsd_sgttyb_to_svr4_sgttyb __P((const struct sgttyb *bs,
53                                            struct svr4_sgttyb *ss));
54 static void svr4_ltchars_to_bsd_ltchars __P((const struct svr4_ltchars *sl,
55                                              struct ltchars *bl));
56 static void bsd_ltchars_to_svr4_ltchars __P((const struct ltchars *bl,
57                                              struct svr4_ltchars *sl));
58
59 #ifdef DEBUG_SVR4
60 static void print_svr4_sgttyb __P((const char *, struct svr4_sgttyb *));
61 static void print_svr4_tchars __P((const char *, struct svr4_tchars *));
62 static void print_svr4_ltchars __P((const char *, struct svr4_ltchars *));
63
64 static void
65 print_svr4_sgttyb(str, ss)
66         const char *str;
67         struct svr4_sgttyb *ss;
68 {
69
70         uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
71         uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
72             ss->sg_flags);
73 }
74
75 static void
76 print_svr4_tchars(str, st)
77         const char *str;
78         struct svr4_tchars *st;
79 {
80         uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
81         uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
82             st->t_stopc, st->t_eofc, st->t_brkc);
83 }
84
85 static void
86 print_svr4_ltchars(str, sl)
87         const char *str;
88         struct svr4_ltchars *sl;
89 {
90         uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
91         uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
92             sl->t_flushc, sl->t_werasc, sl->t_lnextc);
93 }
94 #endif /* DEBUG_SVR4 */
95
96 static void
97 svr4_tchars_to_bsd_tchars(st, bt)
98         const struct svr4_tchars        *st;
99         struct tchars                   *bt;
100 {
101         bt->t_intrc  = st->t_intrc;
102         bt->t_quitc  = st->t_quitc;
103         bt->t_startc = st->t_startc;
104         bt->t_stopc  = st->t_stopc;
105         bt->t_eofc   = st->t_eofc;
106         bt->t_brkc   = st->t_brkc;
107 }
108
109
110 static void
111 bsd_tchars_to_svr4_tchars(bt, st)
112         const struct tchars     *bt;
113         struct svr4_tchars      *st;
114 {
115         st->t_intrc  = bt->t_intrc;
116         st->t_quitc  = bt->t_quitc;
117         st->t_startc = bt->t_startc;
118         st->t_stopc  = bt->t_stopc;
119         st->t_eofc   = bt->t_eofc;
120         st->t_brkc   = bt->t_brkc;
121 }
122
123
124 static void
125 svr4_sgttyb_to_bsd_sgttyb(ss, bs)
126         const struct svr4_sgttyb        *ss;
127         struct sgttyb                   *bs;
128 {
129         bs->sg_ispeed = ss->sg_ispeed;
130         bs->sg_ospeed = ss->sg_ospeed;
131         bs->sg_erase  = ss->sg_erase;   
132         bs->sg_kill   = ss->sg_kill;
133         bs->sg_flags  = ss->sg_flags;
134 };
135
136
137 static void
138 bsd_sgttyb_to_svr4_sgttyb(bs, ss)
139         const struct sgttyb     *bs;
140         struct svr4_sgttyb      *ss;
141 {
142         ss->sg_ispeed = bs->sg_ispeed;
143         ss->sg_ospeed = bs->sg_ospeed;
144         ss->sg_erase  = bs->sg_erase;   
145         ss->sg_kill   = bs->sg_kill;
146         ss->sg_flags  = bs->sg_flags;
147 }
148
149
150 static void
151 svr4_ltchars_to_bsd_ltchars(sl, bl)
152         const struct svr4_ltchars       *sl;
153         struct ltchars                  *bl;
154 {
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;
161 }
162
163
164 static void
165 bsd_ltchars_to_svr4_ltchars(bl, sl)
166         const struct ltchars    *bl;
167         struct svr4_ltchars     *sl;
168 {
169         sl->t_suspc  = bl->t_suspc;
170         sl->t_dsuspc = bl->t_dsuspc;
171         sl->t_rprntc = bl->t_rprntc;
172         sl->t_flushc = bl->t_flushc;
173         sl->t_werasc = bl->t_werasc;
174         sl->t_lnextc = bl->t_lnextc;
175 }
176
177
178 int
179 svr4_ttold_ioctl(fp, p, retval, fd, cmd, data)
180         struct file *fp;
181         struct proc *p;
182         register_t *retval;
183         int fd;
184         u_long cmd;
185         caddr_t data;
186 {
187         int                     error;
188
189         *retval = 0;
190
191         switch (cmd) {
192         case SVR4_TIOCGPGRP:
193                 {
194                         pid_t pid;
195
196                         if ((error = fo_ioctl(fp, TIOCGPGRP, (caddr_t) &pid, p)) != 0)
197                             return error;
198
199                         DPRINTF(("TIOCGPGRP %d\n", pid));
200
201                         if ((error = copyout(&pid, data, sizeof(pid))) != 0)
202                                 return error;
203
204                 }
205
206         case SVR4_TIOCSPGRP:
207                 {
208                         pid_t pid;
209
210                         if ((error = copyin(data, &pid, sizeof(pid))) != 0)
211                                 return error;
212
213                         DPRINTF(("TIOCSPGRP %d\n", pid));
214
215                         return fo_ioctl(fp, TIOCSPGRP, (caddr_t) &pid, p);
216                 }
217
218         case SVR4_TIOCGSID:
219                 {
220 #if defined(TIOCGSID)
221                         pid_t pid;
222                         if ((error = fo_ioctl(fp, TIOCGSID, (caddr_t) &pid, p)) != 0)
223                                 return error;
224
225                         DPRINTF(("TIOCGSID %d\n", pid));
226
227                         return copyout(&pid, data, sizeof(pid));
228 #else
229                         uprintf("ioctl(TIOCGSID) for pid %d unsupported\n", p->p_pid);
230                         return EINVAL;
231 #endif
232                 }
233
234         case SVR4_TIOCGETP:
235                 {
236                         struct sgttyb bs;
237                         struct svr4_sgttyb ss;
238
239                         error = fo_ioctl(fp, TIOCGETP, (caddr_t) &bs, p);
240                         if (error)
241                                 return error;
242
243                         bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
244 #ifdef DEBUG_SVR4
245                         print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
246 #endif /* DEBUG_SVR4 */
247                         return copyout(&ss, data, sizeof(ss));
248                 }
249
250         case SVR4_TIOCSETP:
251         case SVR4_TIOCSETN:
252                 {
253                         struct sgttyb bs;
254                         struct svr4_sgttyb ss;
255
256                         if ((error = copyin(data, &ss, sizeof(ss))) != 0)
257                                 return error;
258
259                         svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
260 #ifdef DEBUG_SVR4
261                         print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
262 #endif /* DEBUG_SVR4 */
263                         cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
264                         return fo_ioctl(fp, cmd, (caddr_t) &bs, p);
265                 }
266
267         case SVR4_TIOCGETC:
268                 {
269                         struct tchars bt;
270                         struct svr4_tchars st;
271
272                         error = fo_ioctl(fp, TIOCGETC, (caddr_t) &bt, p);
273                         if (error)
274                                 return error;
275
276                         bsd_tchars_to_svr4_tchars(&bt, &st);
277 #ifdef DEBUG_SVR4
278                         print_svr4_tchars("SVR4_TIOCGETC", &st);
279 #endif /* DEBUG_SVR4 */
280                         return copyout(&st, data, sizeof(st));
281                 }
282
283         case SVR4_TIOCSETC:
284                 {
285                         struct tchars bt;
286                         struct svr4_tchars st;
287
288                         if ((error = copyin(data, &st, sizeof(st))) != 0)
289                                 return error;
290
291                         svr4_tchars_to_bsd_tchars(&st, &bt);
292 #ifdef DEBUG_SVR4
293                         print_svr4_tchars("SVR4_TIOCSETC", &st);
294 #endif /* DEBUG_SVR4 */
295                         return fo_ioctl(fp, TIOCSETC, (caddr_t) &bt, p);
296                 }
297
298         case SVR4_TIOCGLTC:
299                 {
300                         struct ltchars bl;
301                         struct svr4_ltchars sl;
302
303                         error = fo_ioctl(fp, TIOCGLTC, (caddr_t) &bl, p);
304                         if (error)
305                                 return error;
306
307                         bsd_ltchars_to_svr4_ltchars(&bl, &sl);
308 #ifdef DEBUG_SVR4
309                         print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
310 #endif /* DEBUG_SVR4 */
311                         return copyout(&sl, data, sizeof(sl));
312                 }
313
314         case SVR4_TIOCSLTC:
315                 {
316                         struct ltchars bl;
317                         struct svr4_ltchars sl;
318
319                         if ((error = copyin(data, &sl, sizeof(sl))) != 0)
320                                 return error;
321
322                         svr4_ltchars_to_bsd_ltchars(&sl, &bl);
323 #ifdef DEBUG_SVR4
324                         print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
325 #endif /* DEBUG_SVR4 */
326                         return fo_ioctl(fp, TIOCSLTC, (caddr_t) &bl, p);
327                 }
328
329         case SVR4_TIOCLGET:
330                 {
331                         int flags;
332                         if ((error = fo_ioctl(fp, TIOCLGET, (caddr_t) &flags, p)) != 0)
333                                 return error;
334                         DPRINTF(("SVR4_TIOCLGET %o\n", flags));
335                         return copyout(&flags, data, sizeof(flags));
336                 }
337
338         case SVR4_TIOCLSET:
339         case SVR4_TIOCLBIS:
340         case SVR4_TIOCLBIC:
341                 {
342                         int flags;
343
344                         if ((error = copyin(data, &flags, sizeof(flags))) != 0)
345                                 return error;
346
347                         switch (cmd) {
348                         case SVR4_TIOCLSET:
349                                 cmd = TIOCLSET;
350                                 break;
351                         case SVR4_TIOCLBIS:
352                                 cmd = TIOCLBIS;
353                                 break;
354                         case SVR4_TIOCLBIC:
355                                 cmd = TIOCLBIC;
356                                 break;
357                         }
358
359                         DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
360                         return fo_ioctl(fp, cmd, (caddr_t) &flags, p);
361                 }
362
363         default:
364                 DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
365                 return 0;       /* ENOSYS really */
366         }
367 }