int openfaxfile(Modem *m, char *file) { if((m->bp = Bopen(file, OREAD)) == 0) return seterror(m, Esys); m->valid &= ~(Vtype); if(gsopen(m) == Eok) return Eok; return picopen(m); }
int gsc_config(dev_t devno, int cmd, struct uio * uiop) { struct gsc_ddsinfo ddsinfo; gsc_softc_t *sp; int result, i, unit; extern int nodev(); static struct devsw gsc_dsw = { gsc_open, /* entry point for open routine */ gsc_close, /* entry point for close routine */ nodev, /* entry point for read routine */ nodev, /* entry point for write routine */ gsc_ioctl, /* entry point for ioctl routine */ nodev, /* entry point for strategy routine */ 0, /* pointer to tty device structure */ nodev, /* entry point for select routine */ gsc_config, /* entry point for config routine */ nodev, /* entry point for print routine */ nodev, /* entry point for dump routine */ nodev, /* entry point for mpx routine */ nodev, /* entry point for revoke routine */ NULL, /* pointer to device specific data */ NULL, /* select pointer */ DEV_MPSAFE }; if (lockl(&config_lock, LOCK_SHORT) != LOCK_SUCC) { return (EINVAL); } unit = minor(devno); if (unit < 0 || unit >= MAX_UNITS) { Trace2(0, "%d: bad unit %d", __LINE__, unit); result = EINVAL; unlockl(&config_lock); return (result); } switch (cmd) { case CFG_INIT: Trace2(2, "CFG_INIT: unit %d nunit %d\n", unit, nunits); /* * Initialize softinfo, first time around. */ if (nunits == 0) { memset(softinfo, 0, sizeof (softinfo)); } /* * Copy in DDS information */ uiomove((caddr_t) &ddsinfo, sizeof ddsinfo, UIO_WRITE, uiop); sp = &softinfo[unit]; if (sp->iscfg) { Trace1(0, "CFG_INIT: unit %d already configd", unit); result = EBUSY; break; } lock_alloc(&sp->dd_lock, LOCK_ALLOC_PIN, DD_LOCK, -1); lock_alloc(&sp->buf_lock, LOCK_ALLOC_PIN, DD_LOCK, -1); simple_lock_init(&sp->dd_lock); sp->dev = ddsinfo.busid; sp->tgt = ddsinfo.target; sp->lun = ddsinfo.lun; sp->cbuf.index = sp->rbuf.index = unit; /* * If this is the first time through: * Add entry to the device switch table to call this driver * Pin driver code. */ if (nunits == 0) { result = devswadd(devno, &gsc_dsw); if (result != 0) { Trace1(0, "CFG_INIT: devswadd result: %d", result); break; } result = pincode((int (*) ()) gscdd_intr); if (result) { Trace1(0, "CFG_INIT: pincode result: %d", result); devswdel(devno); break; } } sp->iscfg = 1; result = gsopen(sp); if (result) { Trace2(0, "CFG_INIT: gsopen returns %d for unit %d", result, unit); sp->iscfg = 0; gsclose(sp, devno); break; } if (nunits <= unit) nunits = unit + 1; sp->iscfg = 1; break; case CFG_TERM: Trace1(2, "CFG_TERM unit %d", unit); result = 0; sp = &softinfo[unit]; if (sp->iscfg == 0) { Trace1(0, "CFG_TERM: unit %d not already configd", unit); result = ENXIO; break; } else if (sp->isopen) { Trace1(0, "CFG_TERM: unit %d open", unit); result = EBUSY; break; } sp->iscfg = 0; /* block further actions */ gsclose(sp, devno); break; default: result = EINVAL; break; } unlockl(&config_lock); return (result); }