[BACK]Return to svr4_ttold.c CVS log [TXT][DIR] Up to [local] / sys / compat / svr4

Annotation of sys/compat/svr4/svr4_ttold.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: svr4_ttold.c,v 1.7 2002/03/14 01:26:51 millert Exp $   */
        !             2: /*     $NetBSD: svr4_ttold.c,v 1.9 1996/04/11 12:54:45 christos Exp $   */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1994 Christos Zoulas
        !             6:  * All rights reserved.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms, with or without
        !             9:  * modification, are permitted provided that the following conditions
        !            10:  * are met:
        !            11:  * 1. Redistributions of source code must retain the above copyright
        !            12:  *    notice, this list of conditions and the following disclaimer.
        !            13:  * 2. Redistributions in binary form must reproduce the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer in the
        !            15:  *    documentation and/or other materials provided with the distribution.
        !            16:  * 3. The name of the author may not be used to endorse or promote products
        !            17:  *    derived from this software without specific prior written permission
        !            18:  *
        !            19:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            20:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            21:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            22:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            23:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            24:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            25:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            26:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            27:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
        !            28:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            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/ioctl.h>
        !            37: #include <sys/termios.h>
        !            38: #include <sys/tty.h>
        !            39: #include <sys/socket.h>
        !            40: #include <sys/mount.h>
        !            41: #include <net/if.h>
        !            42: #include <sys/malloc.h>
        !            43:
        !            44: #include <sys/syscallargs.h>
        !            45:
        !            46: #include <compat/svr4/svr4_types.h>
        !            47: #include <compat/svr4/svr4_util.h>
        !            48: #include <compat/svr4/svr4_signal.h>
        !            49: #include <compat/svr4/svr4_syscallargs.h>
        !            50: #include <compat/svr4/svr4_stropts.h>
        !            51: #include <compat/svr4/svr4_ttold.h>
        !            52: #include <compat/svr4/svr4_ioctl.h>
        !            53:
        !            54: static void svr4_tchars_to_bsd_tchars(const struct svr4_tchars *st,
        !            55:                                           struct tchars *bt);
        !            56: static void bsd_tchars_to_svr4_tchars(const struct tchars *bt,
        !            57:                                           struct svr4_tchars *st);
        !            58: static void svr4_sgttyb_to_bsd_sgttyb(const struct svr4_sgttyb *ss,
        !            59:                                           struct sgttyb *bs);
        !            60: static void bsd_sgttyb_to_svr4_sgttyb(const struct sgttyb *bs,
        !            61:                                           struct svr4_sgttyb *ss);
        !            62: static void svr4_ltchars_to_bsd_ltchars(const struct svr4_ltchars *sl,
        !            63:                                             struct ltchars *bl);
        !            64: static void bsd_ltchars_to_svr4_ltchars(const struct ltchars *bl,
        !            65:                                             struct svr4_ltchars *sl);
        !            66:
        !            67: #ifdef DEBUG_SVR4
        !            68: static void print_svr4_sgttyb(const char *, struct svr4_sgttyb *);
        !            69: static void print_svr4_tchars(const char *, struct svr4_tchars *);
        !            70: static void print_svr4_ltchars(const char *, struct svr4_ltchars *);
        !            71:
        !            72: static void
        !            73: print_svr4_sgttyb(str, ss)
        !            74:        const char *str;
        !            75:        struct svr4_sgttyb *ss;
        !            76: {
        !            77:        uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
        !            78:        uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
        !            79:            ss->sg_flags);
        !            80: }
        !            81:
        !            82: static void
        !            83: print_svr4_tchars(str, st)
        !            84:        const char *str;
        !            85:        struct svr4_tchars *st;
        !            86: {
        !            87:        uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
        !            88:        uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
        !            89:            st->t_stopc, st->t_eofc, st->t_brkc);
        !            90: }
        !            91:
        !            92: static void
        !            93: print_svr4_ltchars(str, sl)
        !            94:        const char *str;
        !            95:        struct svr4_ltchars *sl;
        !            96: {
        !            97:        uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
        !            98:        uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
        !            99:            sl->t_flushc, sl->t_werasc, sl->t_lnextc);
        !           100: }
        !           101: #endif /* DEBUG_SVR4 */
        !           102:
        !           103: static void
        !           104: svr4_tchars_to_bsd_tchars(st, bt)
        !           105:        const struct svr4_tchars        *st;
        !           106:        struct tchars                   *bt;
        !           107: {
        !           108:        bt->t_intrc  = st->t_intrc;
        !           109:        bt->t_quitc  = st->t_quitc;
        !           110:        bt->t_startc = st->t_startc;
        !           111:        bt->t_stopc  = st->t_stopc;
        !           112:        bt->t_eofc   = st->t_eofc;
        !           113:        bt->t_brkc   = st->t_brkc;
        !           114: }
        !           115:
        !           116:
        !           117: static void
        !           118: bsd_tchars_to_svr4_tchars(bt, st)
        !           119:        const struct tchars     *bt;
        !           120:        struct svr4_tchars      *st;
        !           121: {
        !           122:        st->t_intrc  = bt->t_intrc;
        !           123:        st->t_quitc  = bt->t_quitc;
        !           124:        st->t_startc = bt->t_startc;
        !           125:        st->t_stopc  = bt->t_stopc;
        !           126:        st->t_eofc   = bt->t_eofc;
        !           127:        st->t_brkc   = bt->t_brkc;
        !           128: }
        !           129:
        !           130:
        !           131: static void
        !           132: svr4_sgttyb_to_bsd_sgttyb(ss, bs)
        !           133:        const struct svr4_sgttyb        *ss;
        !           134:        struct sgttyb                   *bs;
        !           135: {
        !           136:        bs->sg_ispeed = ss->sg_ispeed;
        !           137:        bs->sg_ospeed = ss->sg_ospeed;
        !           138:        bs->sg_erase  = ss->sg_erase;
        !           139:        bs->sg_kill   = ss->sg_kill;
        !           140:        bs->sg_flags  = ss->sg_flags;
        !           141: };
        !           142:
        !           143:
        !           144: static void
        !           145: bsd_sgttyb_to_svr4_sgttyb(bs, ss)
        !           146:        const struct sgttyb     *bs;
        !           147:        struct svr4_sgttyb      *ss;
        !           148: {
        !           149:        ss->sg_ispeed = bs->sg_ispeed;
        !           150:        ss->sg_ospeed = bs->sg_ospeed;
        !           151:        ss->sg_erase  = bs->sg_erase;
        !           152:        ss->sg_kill   = bs->sg_kill;
        !           153:        ss->sg_flags  = bs->sg_flags;
        !           154: }
        !           155:
        !           156:
        !           157: static void
        !           158: svr4_ltchars_to_bsd_ltchars(sl, bl)
        !           159:        const struct svr4_ltchars       *sl;
        !           160:        struct ltchars                  *bl;
        !           161: {
        !           162:        bl->t_suspc  = sl->t_suspc;
        !           163:        bl->t_dsuspc = sl->t_dsuspc;
        !           164:        bl->t_rprntc = sl->t_rprntc;
        !           165:        bl->t_flushc = sl->t_flushc;
        !           166:        bl->t_werasc = sl->t_werasc;
        !           167:        bl->t_lnextc = sl->t_lnextc;
        !           168: }
        !           169:
        !           170:
        !           171: static void
        !           172: bsd_ltchars_to_svr4_ltchars(bl, sl)
        !           173:        const struct ltchars    *bl;
        !           174:        struct svr4_ltchars     *sl;
        !           175: {
        !           176:        sl->t_suspc  = bl->t_suspc;
        !           177:        sl->t_dsuspc = bl->t_dsuspc;
        !           178:        sl->t_rprntc = bl->t_rprntc;
        !           179:        sl->t_flushc = bl->t_flushc;
        !           180:        sl->t_werasc = bl->t_werasc;
        !           181:        sl->t_lnextc = bl->t_lnextc;
        !           182: }
        !           183:
        !           184:
        !           185: int
        !           186: svr4_ttold_ioctl(fp, p, retval, fd, cmd, data)
        !           187:        struct file *fp;
        !           188:        struct proc *p;
        !           189:        register_t *retval;
        !           190:        int fd;
        !           191:        u_long cmd;
        !           192:        caddr_t data;
        !           193: {
        !           194:        int                     error;
        !           195:        int (*ctl)(struct file *, u_long,  caddr_t, struct proc *) =
        !           196:                        fp->f_ops->fo_ioctl;
        !           197:
        !           198:        *retval = 0;
        !           199:
        !           200:        switch (cmd) {
        !           201:        case SVR4_TIOCGPGRP:
        !           202:                {
        !           203:                        pid_t pid;
        !           204:
        !           205:                        if ((error = (*ctl)(fp, TIOCGPGRP,
        !           206:                                            (caddr_t) &pid, p)) != 0)
        !           207:                            return error;
        !           208:
        !           209:                        DPRINTF(("TIOCGPGRP %d\n", pid));
        !           210:
        !           211:                        if ((error = copyout(&pid, data, sizeof(pid))) != 0)
        !           212:                                return error;
        !           213:
        !           214:                }
        !           215:
        !           216:        case SVR4_TIOCSPGRP:
        !           217:                {
        !           218:                        pid_t pid;
        !           219:
        !           220:                        if ((error = copyin(data, &pid, sizeof(pid))) != 0)
        !           221:                                return error;
        !           222:
        !           223:                        DPRINTF(("TIOCSPGRP %d\n", pid));
        !           224:
        !           225:                        return (*ctl)(fp, TIOCSPGRP, (caddr_t) &pid, p);
        !           226:                }
        !           227:
        !           228:        case SVR4_TIOCGSID:
        !           229:                {
        !           230:                        pid_t pid;
        !           231:
        !           232:                        if ((error = (*ctl)(fp, TIOCGSID,
        !           233:                                            (caddr_t) &pid, p)) != 0)
        !           234:                                return error;
        !           235:
        !           236:                        DPRINTF(("TIOCGSID %d\n", pid));
        !           237:
        !           238:                        return copyout(&pid, data, sizeof(pid));
        !           239:                }
        !           240:
        !           241:        case SVR4_TIOCGETP:
        !           242:                {
        !           243:                        struct sgttyb bs;
        !           244:                        struct svr4_sgttyb ss;
        !           245:
        !           246:                        error = (*ctl)(fp, TIOCGETP, (caddr_t) &bs, p);
        !           247:                        if (error)
        !           248:                                return error;
        !           249:
        !           250:                        bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
        !           251: #ifdef DEBUG_SVR4
        !           252:                        print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
        !           253: #endif /* DEBUG_SVR4 */
        !           254:                        return copyout(&ss, data, sizeof(ss));
        !           255:                }
        !           256:
        !           257:        case SVR4_TIOCSETP:
        !           258:        case SVR4_TIOCSETN:
        !           259:                {
        !           260:                        struct sgttyb bs;
        !           261:                        struct svr4_sgttyb ss;
        !           262:
        !           263:                        if ((error = copyin(data, &ss, sizeof(ss))) != 0)
        !           264:                                return error;
        !           265:
        !           266:                        svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
        !           267: #ifdef DEBUG_SVR4
        !           268:                        print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
        !           269: #endif /* DEBUG_SVR4 */
        !           270:                        cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
        !           271:                        return (*ctl)(fp, cmd, (caddr_t) &bs, p);
        !           272:                }
        !           273:
        !           274:        case SVR4_TIOCGETC:
        !           275:                {
        !           276:                        struct tchars bt;
        !           277:                        struct svr4_tchars st;
        !           278:
        !           279:                        error = (*ctl)(fp, TIOCGETC, (caddr_t) &bt, p);
        !           280:                        if (error)
        !           281:                                return error;
        !           282:
        !           283:                        bsd_tchars_to_svr4_tchars(&bt, &st);
        !           284: #ifdef DEBUG_SVR4
        !           285:                        print_svr4_tchars("SVR4_TIOCGETC", &st);
        !           286: #endif /* DEBUG_SVR4 */
        !           287:                        return copyout(&st, data, sizeof(st));
        !           288:                }
        !           289:
        !           290:        case SVR4_TIOCSETC:
        !           291:                {
        !           292:                        struct tchars bt;
        !           293:                        struct svr4_tchars st;
        !           294:
        !           295:                        if ((error = copyin(data, &st, sizeof(st))) != 0)
        !           296:                                return error;
        !           297:
        !           298:                        svr4_tchars_to_bsd_tchars(&st, &bt);
        !           299: #ifdef DEBUG_SVR4
        !           300:                        print_svr4_tchars("SVR4_TIOCSETC", &st);
        !           301: #endif /* DEBUG_SVR4 */
        !           302:                        return (*ctl)(fp, TIOCSETC, (caddr_t) &bt, p);
        !           303:                }
        !           304:
        !           305:        case SVR4_TIOCGLTC:
        !           306:                {
        !           307:                        struct ltchars bl;
        !           308:                        struct svr4_ltchars sl;
        !           309:
        !           310:                        error = (*ctl)(fp, TIOCGLTC, (caddr_t) &bl, p);
        !           311:                        if (error)
        !           312:                                return error;
        !           313:
        !           314:                        bsd_ltchars_to_svr4_ltchars(&bl, &sl);
        !           315: #ifdef DEBUG_SVR4
        !           316:                        print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
        !           317: #endif /* DEBUG_SVR4 */
        !           318:                        return copyout(&sl, data, sizeof(sl));
        !           319:                }
        !           320:
        !           321:        case SVR4_TIOCSLTC:
        !           322:                {
        !           323:                        struct ltchars bl;
        !           324:                        struct svr4_ltchars sl;
        !           325:
        !           326:                        if ((error = copyin(data, &sl, sizeof(sl))) != 0)
        !           327:                                return error;
        !           328:
        !           329:                        svr4_ltchars_to_bsd_ltchars(&sl, &bl);
        !           330: #ifdef DEBUG_SVR4
        !           331:                        print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
        !           332: #endif /* DEBUG_SVR4 */
        !           333:                        return (*ctl)(fp, TIOCSLTC, (caddr_t) &bl, p);
        !           334:                }
        !           335:
        !           336:        case SVR4_TIOCLGET:
        !           337:                {
        !           338:                        int flags;
        !           339:                        if ((error = (*ctl)(fp, cmd, (caddr_t) &flags, p)) !=
        !           340:                            0)
        !           341:                                return error;
        !           342:                        DPRINTF(("SVR4_TIOCLGET %o\n", flags));
        !           343:                        return copyout(&flags, data, sizeof(flags));
        !           344:                }
        !           345:
        !           346:        case SVR4_TIOCLSET:
        !           347:        case SVR4_TIOCLBIS:
        !           348:        case SVR4_TIOCLBIC:
        !           349:                {
        !           350:                        int flags;
        !           351:
        !           352:                        if ((error = copyin(data, &flags, sizeof(flags))) != 0)
        !           353:                                return error;
        !           354:
        !           355:                        switch (cmd) {
        !           356:                        case SVR4_TIOCLSET:
        !           357:                                cmd = TIOCLSET;
        !           358:                                break;
        !           359:                        case SVR4_TIOCLBIS:
        !           360:                                cmd = TIOCLBIS;
        !           361:                                break;
        !           362:                        case SVR4_TIOCLBIC:
        !           363:                                cmd = TIOCLBIC;
        !           364:                                break;
        !           365:                        }
        !           366:
        !           367:                        DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
        !           368:                        return (*ctl)(fp, cmd, (caddr_t) &flags, p);
        !           369:                }
        !           370:
        !           371:        default:
        !           372:                DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
        !           373:                return 0;       /* ENOSYS really */
        !           374:        }
        !           375: }

CVSweb