int find_devs(struct jlhead *l, const char *base) { DIR *d; char fn[512]; struct dirent *ent; struct stat buf; d = opendir(base); if(!d) return 0; while((ent = readdir(d))) { if(ent->d_name[0] == '.') continue; sprintf(fn ,"%s/%s", base, ent->d_name); if(!strcmp(ent->d_name, "dev")) { jl_append(l, strdup(fn)); } else { if(lstat(fn, &buf)==0) { if(S_ISDIR(buf.st_mode)) find_devs(l, fn); } } } closedir(d); return 0; }
int mkdev(const char *name, int _mode) { char *pattern; if (chdir("/dev")) return 1; pattern = add_pattern(name); patterns = &pattern; mode = _mode; n_patterns = 1; find_devs(true); find_devs(false); chdir("/"); return 0; }
/* * Console initialization: called early on from main, * before vm init or startup. Do enough configuration * to choose and initialize a console. */ consinit() { /* * Set cpuspeed immediately since cninit() called routines * might use delay. Note that we only set it if a custom value * has not already been specified. */ if (cpuspeed == 0) { switch (machineid) { case HP_320: case HP_330: case HP_340: cpuspeed = MHZ_16; break; case HP_350: case HP_360: case HP_380: cpuspeed = MHZ_25; break; case HP_370: case HP_433: cpuspeed = MHZ_33; break; case HP_375: cpuspeed = MHZ_50; break; default: /* assume the fastest */ cpuspeed = MHZ_50; break; } if (mmutype == MMU_68040) cpuspeed *= 2; /* XXX */ } /* * Find what hardware is attached to this machine. */ find_devs(); /* * Initialize the console before we print anything out. */ cninit(); }
int sysblock_scan() { struct jlhead *devs; char *s, *p; char buf[16], fn[64]; ssize_t n; int major, minor, fd; devs = jl_new(); sprintf(fn, "%s/block", conf.sysdir); find_devs(devs, fn); jl_foreach(devs, s) { fd = open(s, O_RDONLY); if(fd != -1) { if((n=read(fd, buf, sizeof(buf)-1))>0) { buf[n] = 0; minor = 0; major = atoi(buf); p = strchr(buf, ':'); if(p) minor = atoi(p+1); s[strlen(s)-3] = 0; p=basename(s); sprintf(fn, "%s/%s", conf.devdir, p); if(conf.debug) printf("%s: major=%d minor=%d\n", fn, major, minor); mknod(fn, 0640|S_IFBLK, makedev(major, minor)); } close(fd); } }
main() { int i, status; int *p; /* * Initialize the console before we print anything out. */ cpuspeed = MHZ_25; /* for DELAY() macro */ nplane = get_plane_numbers(); cninit(); printf("\n\nStinger ver 0.0 [%s]\n\n", VERS_LOCAL); kiff->maxaddr = (caddr_t) (ROM_memsize -1); kiff->dipsw = ~((dipsw2 << 8) | dipsw1) & 0xFFFF; kiff->plane = nplane; i = (int) kiff->maxaddr + 1; printf("Physical Memory = 0x%x ", i); i >>= 20; printf("(%d MB)\n", i); printf("\n"); bcopy(VERS_LOCAL, prompt, sizeof(VERS_LOCAL)); prompt[sizeof(VERS_LOCAL) - 1] = '>'; prompt[sizeof(VERS_LOCAL)] = ' '; prompt[sizeof(VERS_LOCAL) + 1] = 0; /* * IO configuration */ find_devs(); configure(); printf("\n"); howto = reorder_dipsw(dipsw2); if ((howto & 0xFE) == 0) { printf("auto-boot %s\n", default_file); i = open(default_file, 0); if (i >= 0) { bootunix(howto, devtype, i); close(i); } } /* * Main Loop */ do { bzero(buffer, BUFFSIZE); if (getline(prompt, buffer) > 0) { argc = getargs(buffer, argv, sizeof(argv)/sizeof(char *)); status = parse(argc, argv); if (status == ST_NOTFOUND) printf("Command \"%s\" is not found !!\n", argv[0]); } } while(status != ST_EXIT); exit(); }