/* * Copy a line from user space to a local buffer, then call putc to get the * chars moved to the output queue. */ int lptwrite(dev_t dev, struct uio *uio, int flags) { struct lpt_softc *sc; size_t n; int error; sc = device_lookup_private(&lpt_cd, LPTUNIT(dev)); error = 0; while ((n = min(LPT_BSIZE, uio->uio_resid)) != 0) { uiomove(sc->sc_cp = sc->sc_inbuf->b_data, n, uio); sc->sc_count = n; error = pushbytes(sc); if (error) { /* * Return accurate residual if interrupted or timed * out. */ uio->uio_resid += sc->sc_count; sc->sc_count = 0; return (error); } } return (0); }
static int lptwrite(dev_t dev, struct uio * uio, int ioflag) { register unsigned n; int pl, err; struct lpt_softc *sc; sc = devclass_get_softc(olpt_devclass, LPTUNIT(minor(dev))); if(sc->sc_flags & LP_BYPASS) { /* we can't do writes in bypass mode */ return(EPERM); } sc->sc_state &= ~INTERRUPTED; while ((n = min(BUFSIZE, uio->uio_resid)) != 0) { sc->sc_cp = sc->sc_inbuf->b_data ; uiomove(sc->sc_cp, n, uio); sc->sc_xfercnt = n ; while ((sc->sc_xfercnt > 0)&&(sc->sc_irq & LP_USE_IRQ)) { lprintf(("i")); /* if the printer is ready for a char, */ /* give it one */ if ((sc->sc_state & OBUSY) == 0){ lprintf(("\nC %d. ", sc->sc_xfercnt)); pl = spltty(); lpt_intr(sc); (void) splx(pl); } lprintf(("W ")); if (sc->sc_state & OBUSY) if ((err = tsleep ((caddr_t)sc, LPPRI|PCATCH, "lpwrite", 0))) { sc->sc_state |= INTERRUPTED; return(err); } } /* check to see if we must do a polled write */ if(!(sc->sc_irq & LP_USE_IRQ) && (sc->sc_xfercnt)) { lprintf(("p")); if((err = pushbytes(sc))) return(err); } } return(0); }
/* * Close the device, and free the local line buffer. */ int lptclose(dev_t dev, int flag, int mode, struct lwp *l) { struct lpt_softc *sc; sc = device_lookup_private(&lpt_cd, LPTUNIT(dev)); if (sc->sc_count) (void) pushbytes(sc); if ((sc->sc_flags & LPT_NOINTR) == 0) callout_stop(&sc->sc_wakeup_ch); (sc->sc_funcs->lf_close) (sc); sc->sc_state = 0; brelse(sc->sc_inbuf, 0); LPRINTF((sc->sc_dev, "%s: closed\n")); return (0); }