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