Annotation of Net2/dev/cons.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1988 University of Utah.
                      3:  * Copyright (c) 1991 The Regents of the University of California.
                      4:  * All rights reserved.
                      5:  *
                      6:  * This code is derived from software contributed to Berkeley by
                      7:  * the Systems Programming Group of the University of Utah Computer
                      8:  * Science Department.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     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.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *     This product includes software developed by the University of
                     21:  *     California, Berkeley and its contributors.
                     22:  * 4. Neither the name of the University nor the names of its contributors
                     23:  *    may be used to endorse or promote products derived from this software
                     24:  *    without specific prior written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     36:  * SUCH DAMAGE.
                     37:  *
                     38:  *     @(#)cons.c      7.2 (Berkeley) 5/9/91
                     39:  *
                     40:  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
                     41:  * --------------------         -----   ----------------------
                     42:  * CURRENT PATCH LEVEL:         1       00083
                     43:  * --------------------         -----   ----------------------
                     44:  *
                     45:  * 16 Aug 92   Pace Willisson          /dev/console redirect (xterm -C, etc.)
                     46:  * 14 Mar 93   Chris G. Demetriou      Moved pg() here from isa/pccons.c
                     47:  */
                     48: 
                     49: 
                     50: #include "sys/param.h"
                     51: #include "sys/proc.h"
                     52: #include "sys/user.h"
                     53: #include "sys/systm.h"
                     54: #include "sys/buf.h"
                     55: #include "sys/ioctl.h"
                     56: #include "sys/tty.h"
                     57: #include "sys/file.h"
                     58: #include "sys/conf.h"
                     59: 
                     60: #include "cons.h"
                     61: 
                     62: /* XXX - all this could be autoconfig()ed */
                     63: int pccnprobe(), pccninit(), pccngetc(), pccnputc();
                     64: #include "com.h"
                     65: #if NCOM > 0
                     66: int comcnprobe(), comcninit(), comcngetc(), comcnputc();
                     67: #endif
                     68: 
                     69: struct consdev constab[] = {
                     70:        { pccnprobe,    pccninit,       pccngetc,       pccnputc },
                     71: #if NCOM > 0
                     72:        { comcnprobe,   comcninit,      comcngetc,      comcnputc },
                     73: #endif
                     74:        { 0 },
                     75: };
                     76: /* end XXX */
                     77: 
                     78: struct tty *constty = 0;       /* virtual console output device */
                     79: struct consdev *cn_tab;        /* physical console device info */
                     80: struct tty *cn_tty;            /* XXX: console tty struct for tprintf */
                     81: 
                     82: cninit()
                     83: {
                     84:        register struct consdev *cp;
                     85: 
                     86:        /*
                     87:         * Collect information about all possible consoles
                     88:         * and find the one with highest priority
                     89:         */
                     90:        for (cp = constab; cp->cn_probe; cp++) {
                     91:                (*cp->cn_probe)(cp);
                     92:                if (cp->cn_pri > CN_DEAD &&
                     93:                    (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
                     94:                        cn_tab = cp;
                     95:        }
                     96:        /*
                     97:         * No console, we can handle it
                     98:         */
                     99:        if ((cp = cn_tab) == NULL)
                    100:                return;
                    101:        /*
                    102:         * Turn on console
                    103:         */
                    104:        cn_tty = cp->cn_tp;
                    105:        (*cp->cn_init)(cp);
                    106: }
                    107: 
                    108: cnopen(dev, flag, mode, p)
                    109:        dev_t dev;
                    110:        int flag, mode;
                    111:        struct proc *p;
                    112: {
                    113:        if (cn_tab == NULL)
                    114:                return (0);
                    115:        dev = cn_tab->cn_dev;
                    116:        return ((*cdevsw[major(dev)].d_open)(dev, flag, mode, p));
                    117: }
                    118:  
                    119: cnclose(dev, flag, mode, p)
                    120:        dev_t dev;
                    121:        int flag, mode;
                    122:        struct proc *p;
                    123: {
                    124:        if (cn_tab == NULL)
                    125:                return (0);
                    126:        dev = cn_tab->cn_dev;
                    127:        return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, p));
                    128: }
                    129:  
                    130: cnread(dev, uio, flag)
                    131:        dev_t dev;
                    132:        struct uio *uio;
                    133: {
                    134:        if (cn_tab == NULL)
                    135:                return (0);
                    136:        dev = cn_tab->cn_dev;
                    137:        return ((*cdevsw[major(dev)].d_read)(dev, uio, flag));
                    138: }
                    139:  
                    140: cnwrite(dev, uio, flag)
                    141:        dev_t dev;
                    142:        struct uio *uio;
                    143: {
                    144:        if (cn_tab == NULL)
                    145:                return (0);
                    146:        if (constty)                                    /* 16 Aug 92*/
                    147:                dev = constty->t_dev;
                    148:        else
                    149:                dev = cn_tab->cn_dev;
                    150:        return ((*cdevsw[major(dev)].d_write)(dev, uio, flag));
                    151: }
                    152:  
                    153: cnioctl(dev, cmd, data, flag, p)
                    154:        dev_t dev;
                    155:        caddr_t data;
                    156:        struct proc *p;
                    157: {
                    158:        int error;
                    159: 
                    160:        if (cn_tab == NULL)
                    161:                return (0);
                    162:        /*
                    163:         * Superuser can always use this to wrest control of console
                    164:         * output from the "virtual" console.
                    165:         */
                    166:        if (cmd == TIOCCONS && constty) {
                    167:                error = suser(p->p_ucred, (u_short *) NULL);
                    168:                if (error)
                    169:                        return (error);
                    170:                constty = NULL;
                    171:                return (0);
                    172:        }
                    173:        dev = cn_tab->cn_dev;
                    174:        return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag, p));
                    175: }
                    176: 
                    177: /*ARGSUSED*/
                    178: cnselect(dev, rw, p)
                    179:        dev_t dev;
                    180:        int rw;
                    181:        struct proc *p;
                    182: {
                    183:        if (cn_tab == NULL)
                    184:                return (1);
                    185:        return (ttselect(cn_tab->cn_dev, rw, p));
                    186: }
                    187: 
                    188: cngetc()
                    189: {
                    190:        if (cn_tab == NULL)
                    191:                return (0);
                    192:        return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
                    193: }
                    194: 
                    195: cnputc(c)
                    196:        register int c;
                    197: {
                    198:        if (cn_tab == NULL)
                    199:                return;
                    200:        if (c) {
                    201:                (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
                    202:                if (c == '\n')
                    203:                        (*cn_tab->cn_putc)(cn_tab->cn_dev, '\r');
                    204:        }
                    205: }
                    206: 
                    207: pg(p,q,r,s,t,u,v,w,x,y,z) char *p; {
                    208:        printf(p,q,r,s,t,u,v,w,x,y,z);
                    209:        printf("\n>");
                    210:        return(cngetc());
                    211: }
                    212: 
                    213: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.