|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted provided ! 6: * that: (1) source distributions retain this entire copyright notice and ! 7: * comment, and (2) distributions including binaries display the following ! 8: * acknowledgement: ``This product includes software developed by the ! 9: * University of California, Berkeley and its contributors'' in the ! 10: * documentation or other materials provided with the distribution and in ! 11: * all advertising materials mentioning features or use of this software. ! 12: * Neither the name of the University nor the names of its contributors may ! 13: * be used to endorse or promote products derived from this software without ! 14: * specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)mkswapconf.c 5.8 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: /* ! 25: * Build a swap configuration file. ! 26: */ ! 27: #include "config.h" ! 28: ! 29: #include <stdio.h> ! 30: #include <ctype.h> ! 31: ! 32: swapconf() ! 33: { ! 34: register struct file_list *fl; ! 35: struct file_list *do_swap(); ! 36: ! 37: fl = conf_list; ! 38: while (fl) { ! 39: if (fl->f_type != SYSTEMSPEC) { ! 40: fl = fl->f_next; ! 41: continue; ! 42: } ! 43: fl = do_swap(fl); ! 44: } ! 45: } ! 46: ! 47: struct file_list * ! 48: do_swap(fl) ! 49: register struct file_list *fl; ! 50: { ! 51: FILE *fp; ! 52: char swapname[80]; ! 53: register struct file_list *swap; ! 54: dev_t dev; ! 55: ! 56: if (eq(fl->f_fn, "generic")) { ! 57: fl = fl->f_next; ! 58: return (fl->f_next); ! 59: } ! 60: (void) sprintf(swapname, "swap%s.c", fl->f_fn); ! 61: fp = fopen(path(swapname), "w"); ! 62: if (fp == 0) { ! 63: perror(path(swapname)); ! 64: exit(1); ! 65: } ! 66: fprintf(fp, "#include \"../sys/param.h\"\n"); ! 67: fprintf(fp, "#include \"../sys/conf.h\"\n"); ! 68: fprintf(fp, "\n"); ! 69: /* ! 70: * If there aren't any swap devices ! 71: * specified, just return, the error ! 72: * has already been noted. ! 73: */ ! 74: swap = fl->f_next; ! 75: if (swap == 0 || swap->f_type != SWAPSPEC) { ! 76: (void) unlink(path(swapname)); ! 77: fclose(fp); ! 78: return (swap); ! 79: } ! 80: fprintf(fp, "dev_t\trootdev = makedev(%d, %d);\n", ! 81: major(fl->f_rootdev), minor(fl->f_rootdev)); ! 82: fprintf(fp, "dev_t\targdev = makedev(%d, %d);\n", ! 83: major(fl->f_argdev), minor(fl->f_argdev)); ! 84: fprintf(fp, "dev_t\tdumpdev = makedev(%d, %d);\n", ! 85: major(fl->f_dumpdev), minor(fl->f_dumpdev)); ! 86: fprintf(fp, "\n"); ! 87: fprintf(fp, "struct\tswdevt swdevt[] = {\n"); ! 88: do { ! 89: dev = swap->f_swapdev; ! 90: fprintf(fp, "\t{ makedev(%d, %d),\t0,\t%d },\t/* %s */\n", ! 91: major(dev), minor(dev), swap->f_swapsize, swap->f_fn); ! 92: swap = swap->f_next; ! 93: } while (swap && swap->f_type == SWAPSPEC); ! 94: fprintf(fp, "\t{ 0, 0, 0 }\n"); ! 95: fprintf(fp, "};\n"); ! 96: fclose(fp); ! 97: return (swap); ! 98: } ! 99: ! 100: static int devtablenotread = 1; ! 101: static struct devdescription { ! 102: char *dev_name; ! 103: int dev_major; ! 104: struct devdescription *dev_next; ! 105: } *devtable; ! 106: ! 107: /* ! 108: * Given a device name specification figure out: ! 109: * major device number ! 110: * partition ! 111: * device name ! 112: * unit number ! 113: * This is a hack, but the system still thinks in ! 114: * terms of major/minor instead of string names. ! 115: */ ! 116: dev_t ! 117: nametodev(name, defunit, defpartition) ! 118: char *name; ! 119: int defunit; ! 120: char defpartition; ! 121: { ! 122: char *cp, partition; ! 123: int unit; ! 124: register struct devdescription *dp; ! 125: ! 126: cp = name; ! 127: if (cp == 0) { ! 128: fprintf(stderr, "config: internal error, nametodev\n"); ! 129: exit(1); ! 130: } ! 131: while (*cp && !isdigit(*cp)) ! 132: cp++; ! 133: unit = *cp ? atoi(cp) : defunit; ! 134: if (unit < 0 || unit > 31) { ! 135: fprintf(stderr, ! 136: "config: %s: invalid device specification, unit out of range\n", name); ! 137: unit = defunit; /* carry on more checking */ ! 138: } ! 139: if (*cp) { ! 140: *cp++ = '\0'; ! 141: while (*cp && isdigit(*cp)) ! 142: cp++; ! 143: } ! 144: partition = *cp ? *cp : defpartition; ! 145: if (partition < 'a' || partition > 'h') { ! 146: fprintf(stderr, ! 147: "config: %c: invalid device specification, bad partition\n", *cp); ! 148: partition = defpartition; /* carry on */ ! 149: } ! 150: if (devtablenotread) ! 151: initdevtable(); ! 152: for (dp = devtable; dp; dp = dp->dev_next) ! 153: if (eq(name, dp->dev_name)) ! 154: break; ! 155: if (dp == 0) { ! 156: fprintf(stderr, "config: %s: unknown device\n", name); ! 157: return (NODEV); ! 158: } ! 159: return (makedev(dp->dev_major, (unit << 3) + (partition - 'a'))); ! 160: } ! 161: ! 162: char * ! 163: devtoname(dev) ! 164: dev_t dev; ! 165: { ! 166: char buf[80]; ! 167: register struct devdescription *dp; ! 168: ! 169: if (devtablenotread) ! 170: initdevtable(); ! 171: for (dp = devtable; dp; dp = dp->dev_next) ! 172: if (major(dev) == dp->dev_major) ! 173: break; ! 174: if (dp == 0) ! 175: dp = devtable; ! 176: (void) sprintf(buf, "%s%d%c", dp->dev_name, ! 177: minor(dev) >> 3, (minor(dev) & 07) + 'a'); ! 178: return (ns(buf)); ! 179: } ! 180: ! 181: initdevtable() ! 182: { ! 183: char buf[BUFSIZ]; ! 184: int maj; ! 185: register struct devdescription **dp = &devtable; ! 186: FILE *fp; ! 187: ! 188: (void) sprintf(buf, "../conf/devices.%s", machinename); ! 189: fp = fopen(buf, "r"); ! 190: if (fp == NULL) { ! 191: fprintf(stderr, "config: can't open %s\n", buf); ! 192: exit(1); ! 193: } ! 194: while (fscanf(fp, "%s\t%d\n", buf, &maj) == 2) { ! 195: *dp = (struct devdescription *)malloc(sizeof (**dp)); ! 196: (*dp)->dev_name = ns(buf); ! 197: (*dp)->dev_major = maj; ! 198: dp = &(*dp)->dev_next; ! 199: } ! 200: *dp = 0; ! 201: fclose(fp); ! 202: devtablenotread = 0; ! 203: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.