BSD 4_4 release
[unix-history] / usr / src / sys / hp300 / dev / ct.c
index c5b6f95..c597a8e 100644 (file)
@@ -1,10 +1,36 @@
 /*
 /*
- * Copyright (c) 1982, 1990 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)ct.c        7.1 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ct.c        8.1 (Berkeley) 6/10/93
  */
 
 #include "ct.h"
  */
 
 #include "ct.h"
  *     finish support of 9145
  */
 
  *     finish support of 9145
  */
 
-#include "param.h"
-#include "buf.h"
-#include "ioctl.h"
-#include "mtio.h"
-#include "errno.h"
-#include "ctreg.h"
-#include "device.h"
-#include "user.h"
-#include "tty.h"
-#include "proc.h"
+#include <sys/param.h>
+#include <sys/buf.h>
+#include <sys/ioctl.h>
+#include <sys/mtio.h>
+#include <sys/tprintf.h>
+#include <sys/proc.h>
+
+#include <hp/dev/device.h>
+
+#include <hp300/dev/ctreg.h>
 
 /* number of eof marks to remember */
 #define EOFS   128
 
 /* number of eof marks to remember */
 #define EOFS   128
@@ -61,7 +87,7 @@ struct        ct_softc {
        int     sc_flags;
        short   sc_type;
        short   sc_punit;
        int     sc_flags;
        short   sc_type;
        short   sc_punit;
-       caddr_t sc_ctty;
+       tpr_t   sc_tpr;
        struct  devqueue sc_dq;
        int     sc_eofp;
        int     sc_eofs[EOFS];
        struct  devqueue sc_dq;
        int     sc_eofp;
        int     sc_eofs[EOFS];
@@ -111,7 +137,10 @@ ctinit(hd)
        register struct hp_device *hd;
 {
        register struct ct_softc *sc = &ct_softc[hd->hp_unit];
        register struct hp_device *hd;
 {
        register struct ct_softc *sc = &ct_softc[hd->hp_unit];
+       register struct buf *bp;
 
 
+       for (bp = cttab; bp < &cttab[NCT]; bp++)
+               bp->b_actb = &bp->b_actf;
        sc->sc_hd = hd;
        sc->sc_punit = ctpunit(hd->hp_flags);
        if (ctident(sc, hd) < 0)
        sc->sc_hd = hd;
        sc->sc_punit = ctpunit(hd->hp_flags);
        if (ctident(sc, hd) < 0)
@@ -231,8 +260,10 @@ ctreset(sc, hd)
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
-ctopen(dev, flag)
+ctopen(dev, flag, type, p)
        dev_t dev;
        dev_t dev;
+       int flag, type;
+       struct proc *p;
 {
        register struct ct_softc *sc = &ct_softc[UNIT(dev)];
        u_char stat;
 {
        register struct ct_softc *sc = &ct_softc[UNIT(dev)];
        u_char stat;
@@ -263,8 +294,7 @@ ctopen(dev, flag)
                      &stat, sizeof(stat));
        if (cc != sizeof(stat))
                return(EBUSY);
                      &stat, sizeof(stat));
        if (cc != sizeof(stat))
                return(EBUSY);
-       sc->sc_ctty = (caddr_t)(u.u_procp->p_flag&SCTTY ? 
-                       u.u_procp->p_session->s_ttyvp : 0);
+       sc->sc_tpr = tprintf_open(p);
        sc->sc_flags |= CTF_OPEN;
        return(0);
 }
        sc->sc_flags |= CTF_OPEN;
        return(0);
 }
@@ -292,7 +322,7 @@ ctclose(dev, flag)
        if ((minor(dev) & CT_NOREW) == 0)
                ctcommand(dev, MTREW, 1);
        sc->sc_flags &= ~(CTF_OPEN | CTF_WRT | CTF_WRTTN);
        if ((minor(dev) & CT_NOREW) == 0)
                ctcommand(dev, MTREW, 1);
        sc->sc_flags &= ~(CTF_OPEN | CTF_WRT | CTF_WRTTN);
-       sc->sc_ctty = NULL;
+       tprintf_close(sc->sc_tpr);
 #ifdef DEBUG
        if (ctdebug & CDB_FILES)
                printf("ctclose: flags %x\n", sc->sc_flags);
 #ifdef DEBUG
        if (ctdebug & CDB_FILES)
                printf("ctclose: flags %x\n", sc->sc_flags);
@@ -360,13 +390,11 @@ ctstrategy(bp)
 
        unit = UNIT(bp->b_dev);
        dp = &cttab[unit];
 
        unit = UNIT(bp->b_dev);
        dp = &cttab[unit];
-       bp->av_forw = NULL;
+       bp->b_actf = NULL;
        s = splbio();
        s = splbio();
-       if (dp->b_actf == NULL)
-               dp->b_actf = bp;
-       else
-               dp->b_actl->av_forw = bp;
-       dp->b_actl = bp;
+       bp->b_actb = dp->b_actb;
+       *dp->b_actb = bp;
+       dp->b_actb = &bp->b_actf;
        if (dp->b_active == 0) {
                dp->b_active = 1;
                ctustart(unit);
        if (dp->b_active == 0) {
                dp->b_active = 1;
                ctustart(unit);
@@ -391,7 +419,7 @@ ctstart(unit)
        register int unit;
 {
        register struct ct_softc *sc = &ct_softc[unit];
        register int unit;
 {
        register struct ct_softc *sc = &ct_softc[unit];
-       register struct buf *bp;
+       register struct buf *bp, *dp;
        register int i;
 
        bp = cttab[unit].b_actf;
        register int i;
 
        bp = cttab[unit].b_actf;
@@ -476,8 +504,12 @@ mustio:
                        bp->b_resid = bp->b_bcount;
                        iodone(bp);
                        hpibfree(&sc->sc_dq);
                        bp->b_resid = bp->b_bcount;
                        iodone(bp);
                        hpibfree(&sc->sc_dq);
-                       cttab[unit].b_actf = bp = bp->av_forw;
-                       if (bp == NULL) {
+                       if (dp = bp->b_actf)
+                               dp->b_actb = bp->b_actb;
+                       else
+                               cttab[unit].b_actb = bp->b_actb;
+                       *bp->b_actb = dp;
+                       if ((bp = dp) == NULL) {
                                cttab[unit].b_active = 0;
                                return;
                        }
                                cttab[unit].b_active = 0;
                                return;
                        }
@@ -598,7 +630,7 @@ ctintr(unit)
        register int unit;
 {
        register struct ct_softc *sc = &ct_softc[unit];
        register int unit;
 {
        register struct ct_softc *sc = &ct_softc[unit];
-       register struct buf *bp;
+       register struct buf *bp, *dp;
        u_char stat;
 
        bp = cttab[unit].b_actf;
        u_char stat;
 
        bp = cttab[unit].b_actf;
@@ -657,14 +689,14 @@ ctintr(unit)
                        }
                        if (sc->sc_stat.c_aef & 0x5800) {
                                if (sc->sc_stat.c_aef & 0x4000)
                        }
                        if (sc->sc_stat.c_aef & 0x5800) {
                                if (sc->sc_stat.c_aef & 0x4000)
-                                       tprintf(sc->sc_ctty,
+                                       tprintf(sc->sc_tpr,
                                                "ct%d: uninitialized media\n",
                                                unit);
                                if (sc->sc_stat.c_aef & 0x1000)
                                                "ct%d: uninitialized media\n",
                                                unit);
                                if (sc->sc_stat.c_aef & 0x1000)
-                                       tprintf(sc->sc_ctty,
+                                       tprintf(sc->sc_tpr,
                                                "ct%d: not ready\n", unit);
                                if (sc->sc_stat.c_aef & 0x0800)
                                                "ct%d: not ready\n", unit);
                                if (sc->sc_stat.c_aef & 0x0800)
-                                       tprintf(sc->sc_ctty,
+                                       tprintf(sc->sc_tpr,
                                                "ct%d: write protect\n", unit);
                        } else {
                                printf("ct%d err: v%d u%d ru%d bn%d, ",
                                                "ct%d: write protect\n", unit);
                        } else {
                                printf("ct%d err: v%d u%d ru%d bn%d, ",
@@ -728,7 +760,11 @@ done:
        if (ctdebug & CDB_FILES)
                printf("ctintr: after flags %x\n", sc->sc_flags);
 #endif
        if (ctdebug & CDB_FILES)
                printf("ctintr: after flags %x\n", sc->sc_flags);
 #endif
-       cttab[unit].b_actf = bp->av_forw;
+       if (dp = bp->b_actf)
+               dp->b_actb = bp->b_actb;
+       else
+               cttab[unit].b_actb = bp->b_actb;
+       *bp->b_actb = dp;
        iodone(bp);
        hpibfree(&sc->sc_dq);
        if (cttab[unit].b_actf == NULL) {
        iodone(bp);
        hpibfree(&sc->sc_dq);
        if (cttab[unit].b_actf == NULL) {