static int ukopen(dev_t dev, int flag, int fmt, struct lwp *l) { int unit, error; struct uk_softc *uk; struct scsipi_periph *periph; struct scsipi_adapter *adapt; unit = minor(dev); uk = device_lookup_private(&uk_cd, unit); if (uk == NULL) return ENXIO; periph = uk->sc_periph; adapt = periph->periph_channel->chan_adapter; SC_DEBUG(periph, SCSIPI_DB1, ("ukopen: dev=0x%"PRIx64" (unit %d (of %d))\n", dev, unit, uk_cd.cd_ndevs)); /* Only allow one at a time */ if (periph->periph_flags & PERIPH_OPEN) { aprint_error_dev(uk->sc_dev, "already open\n"); return EBUSY; } if ((error = scsipi_adapter_addref(adapt)) != 0) return error; periph->periph_flags |= PERIPH_OPEN; SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n")); return 0; }
static int chopen(dev_t dev, int flags, int fmt, struct lwp *l) { struct ch_softc *sc; struct scsipi_periph *periph; struct scsipi_adapter *adapt; int unit, error; unit = CHUNIT(dev); sc = device_lookup_private(&ch_cd, unit); if (sc == NULL) return (ENXIO); periph = sc->sc_periph; adapt = periph->periph_channel->chan_adapter; /* * Only allow one open at a time. */ if (periph->periph_flags & PERIPH_OPEN) return (EBUSY); if ((error = scsipi_adapter_addref(adapt)) != 0) return (error); /* * Make sure the unit is on-line. If a UNIT ATTENTION * occurs, we will mark that an Init-Element-Status is * needed in ch_get_params(). * * We ignore NOT READY in case e.g a magazine isn't actually * loaded into the changer or a tape isn't in the drive. */ error = scsipi_test_unit_ready(periph, XS_CTL_IGNORE_NOT_READY); if (error) goto bad; periph->periph_flags |= PERIPH_OPEN; /* * Make sure our parameters are up to date. */ if ((error = ch_get_params(sc, 0)) != 0) goto bad; return (0); bad: scsipi_adapter_delref(adapt); periph->periph_flags &= ~PERIPH_OPEN; return (error); }
/* open the device. */ static int ssopen(dev_t dev, int flag, int mode, struct lwp *l) { int unit; u_int ssmode; int error; struct ss_softc *ss; struct scsipi_periph *periph; struct scsipi_adapter *adapt; unit = SSUNIT(dev); ss = device_lookup_private(&ss_cd, unit); if (ss == NULL) return ENXIO; if (!device_is_active(ss->sc_dev)) return ENODEV; ssmode = SSMODE(dev); periph = ss->sc_periph; adapt = periph->periph_channel->chan_adapter; SC_DEBUG(periph, SCSIPI_DB1, ("open: dev=0x%"PRIx64" (unit %d (of %d))\n", dev, unit, ss_cd.cd_ndevs)); if (periph->periph_flags & PERIPH_OPEN) { aprint_error_dev(ss->sc_dev, "already open\n"); return EBUSY; } if ((error = scsipi_adapter_addref(adapt)) != 0) return error; /* * Catch any unit attention errors. * * XS_CTL_IGNORE_MEDIA_CHANGE: when you have an ADF, some scanners * consider paper to be a changeable media * */ error = scsipi_test_unit_ready(periph, XS_CTL_IGNORE_MEDIA_CHANGE | XS_CTL_IGNORE_ILLEGAL_REQUEST | (ssmode == MODE_CONTROL ? XS_CTL_IGNORE_NOT_READY : 0)); if (error) goto bad; periph->periph_flags |= PERIPH_OPEN; /* unit attn now errors */ /* * If the mode is 3 (e.g. minor = 3,7,11,15) * then the device has been opened to set defaults * This mode does NOT ALLOW I/O, only ioctls */ if (ssmode == MODE_CONTROL) return 0; SC_DEBUG(periph, SCSIPI_DB2, ("open complete\n")); return 0; bad: scsipi_adapter_delref(adapt); periph->periph_flags &= ~PERIPH_OPEN; return error; }