static int configure(char* spec, DevConf* cf) { SDev *s, *sdev; char *p; int i; if(sdindex(*spec) < 0) error("bad sd spec"); if((p = strchr(cf->type, '/')) != nil) *p++ = '\0'; for(i = 0; sdifc[i] != nil; i++) if(strcmp(sdifc[i]->name, cf->type) == 0) break; if(sdifc[i] == nil) error("sd type not found"); if(p) *(p-1) = '/'; if(sdifc[i]->probe == nil) error("sd type cannot probe"); sdev = sdifc[i]->probe(cf); for(s=sdev; s; s=s->next) s->idno = *spec; sdadddevs(sdev); return 0; }
static void sdreset(void) { int i; /* * Probe all known controller types and register any devices found. */ for(i = 0; sdifc[i] != nil; i++){ if(sdifc[i]->pnp == nil) continue; sdadddevs(sdifc[i]->pnp()); } }
void loopdev(char *name, int mode) { Chan *c; Ctlr *volatile ctlr; SDev *volatile sdev; c = namec(name, Aopen, mode, 0); ctlr = nil; sdev = nil; if(waserror()){ cclose(c); if(ctlr) free(ctlr); if(sdev) free(sdev); nexterror(); } ctlr = smalloc(sizeof *ctlr); sdev = smalloc(sizeof *sdev); sdev->ifc = &sdloopifc; sdev->ctlr = ctlr; sdev->nunit = 1; sdev->idno = '0'; ctlr->sdev = sdev; ctlr->c = c; ctlr->mode = mode; poperror(); lock(&ctlrlock); ctlr->next = nil; ctlr->prev = ctlrtail; ctlrtail = ctlr; if(ctlr->prev) ctlr->prev->next = ctlr; else ctlrhead = ctlr; unlock(&ctlrlock); sdadddevs(sdev); }