|
|
1.1 ! root 1: /* ! 2: * read the configuration file ! 3: * name id addr ... ! 4: * addr pieces are just numbers here; ! 5: * it's up to the address drivers to interpret ! 6: */ ! 7: ! 8: #include <fio.h> ! 9: #include <libc.h> ! 10: #include <ctype.h> ! 11: #include "mkconf.h" ! 12: ! 13: /* ! 14: * table of address-type drivers ! 15: * entries should match with the numbers above ! 16: */ ! 17: ! 18: int nosyntax(), nofixup(), noputaddr(), noputvec(); ! 19: int sbisyntax(), sbifixup(), sbiputaddr(), nexputvec(); ! 20: int vbisyntax(), vbifixup(), vbiputaddr(); ! 21: int cntsyntax(), cntputaddr(); ! 22: int ubasyntax(), ubafixup(), ubaputaddr(), ubaputvec(); ! 23: int subsyntax(), subputaddr(); ! 24: int mbasyntax(), mbafixup(), mbaputaddr(); ! 25: int prmputaddr(); ! 26: int mscpsyntax(), mscpfixup(), mscpputaddr(); ! 27: int nobussyntax(), nobusfixup(), nobusputaddr(), nobusputvec(); ! 28: ! 29: struct acode acode[] = { ! 30: nosyntax, nofixup, noputaddr, noputvec, /* ANONE */ ! 31: cntsyntax, nofixup, cntputaddr, noputvec, /* ACNT */ ! 32: sbisyntax, sbifixup, sbiputaddr, nexputvec, /* ASBI */ ! 33: mbasyntax, mbafixup, mbaputaddr, noputvec, /* AMBA */ ! 34: ubasyntax, ubafixup, ubaputaddr, ubaputvec, /* AUBA */ ! 35: subsyntax, nofixup, subputaddr, noputvec, /* ASUB */ ! 36: vbisyntax, vbifixup, vbiputaddr, nexputvec, /* AVBI */ ! 37: cntsyntax, nofixup, prmputaddr, noputvec, /* APARAM */ ! 38: mscpsyntax, mscpfixup, mscpputaddr, noputvec, /* AMSCP */ ! 39: nobussyntax, nobusfixup, nobusputaddr, nobusputvec, /* ANOBUS */ ! 40: }; ! 41: ! 42: #define NATYPE (sizeof(acode)/sizeof(acode[0])) ! 43: ! 44: #define MAXARGS (NADDR*2+2) ! 45: ! 46: readconf(f) ! 47: char *f; ! 48: { ! 49: int fd; ! 50: register char *p; ! 51: char *args[MAXARGS]; ! 52: register Dev *dp; ! 53: register int n; ! 54: Mdev *mp; ! 55: Mdev *mdlook(); ! 56: ! 57: if ((fd = open(f, 0)) < 0) { ! 58: perror(f); ! 59: exit(1); ! 60: } ! 61: while ((p = Frdline(fd)) != NULL) { ! 62: while (isspace(*p)) ! 63: p++; ! 64: if (*p == '#' || *p == 0) ! 65: continue; ! 66: if ((n = crack(p, args, MAXARGS)) <= 1) { ! 67: fprint(STDERR, "silly conf line: %s\n", p); ! 68: errs++; ! 69: continue; ! 70: } ! 71: if (spconf(args, n)) ! 72: continue; ! 73: if ((mp = mdlook(args[0])) == NULL) { ! 74: fprint(STDERR, "unknown device %s\n", p); ! 75: errs++; ! 76: continue; ! 77: } ! 78: if (0 > mp->atype || mp->atype >= NATYPE) { ! 79: fprint(STDERR, "%s gok atype %d\n", mp->name, mp->atype); ! 80: errs++; ! 81: continue; ! 82: } ! 83: if ((dp = (Dev *)ealloc(sizeof(Dev))) == NULL) { ! 84: fprint(STDERR, "out of memory\n"); ! 85: exit(1); ! 86: } ! 87: dp->mdev = mp; ! 88: dp->id = nconv(args[1]); ! 89: dp->parent = NULL; ! 90: if ((*acode[mp->atype].syntax)(dp, &args[2], n-2)) { ! 91: free((char *)dp); ! 92: continue; ! 93: } ! 94: dinsert(dp); ! 95: } ! 96: close(fd); ! 97: } ! 98: ! 99: /* ! 100: * insert a device into the list of those configured ! 101: * check for duplicates, cluster and order ! 102: * different instances of the same device ! 103: */ ! 104: dinsert(dp) ! 105: register Dev *dp; ! 106: { ! 107: register Dev *ep, *bp; ! 108: ! 109: if (dlist == NULL) { ! 110: dlist = dp; ! 111: dp->next = NULL; ! 112: return; ! 113: } ! 114: bp = NULL; ! 115: for (ep = dlist; ep; bp = ep, ep = ep->next) ! 116: if (dp->mdev == ep->mdev) ! 117: break; ! 118: for (; ep && dp->mdev == ep->mdev; bp = ep, ep = ep->next) { ! 119: if (dp->id == ep->id) { ! 120: fprint(STDERR, "%s %d: dup device\n", dp->mdev->name, dp->id); ! 121: errs++; ! 122: return; ! 123: } ! 124: if (dp->id < ep->id) ! 125: break; ! 126: } ! 127: if (bp == NULL) { ! 128: dp->next = dlist; ! 129: dlist = dp; ! 130: } ! 131: else { ! 132: dp->next = bp->next; ! 133: bp->next = dp; ! 134: } ! 135: } ! 136: ! 137: /* ! 138: * things in the conf file ! 139: * that aren't strictly devices ! 140: * the hard-coded names here take precedence over ! 141: * names of devices and drivers ! 142: * keep these as few as possible, please ! 143: * root fs driver minor ! 144: * swap driver minor size ! 145: * dump drname minor low size ! 146: */ ! 147: ! 148: int ! 149: spconf(a, n) ! 150: register char **a; ! 151: int n; ! 152: { ! 153: ! 154: if (strcmp(a[0], "root") == 0) { ! 155: cfroot(a, n); ! 156: return (1); ! 157: } ! 158: if (strcmp(a[0], "swap") == 0) { ! 159: cfswap(a, n); ! 160: return (1); ! 161: } ! 162: if (strcmp(a[0], "dump") == 0) { ! 163: cfdump(a, n); ! 164: return (1); ! 165: } ! 166: return (0); /* not a special; perhaps a device */ ! 167: } ! 168: ! 169: Mdev *rootfmp, *rootdmp; ! 170: int rootfs; ! 171: int rootmaj, rootmin; ! 172: ! 173: cfroot(a, n) ! 174: register char **a; ! 175: int n; ! 176: { ! 177: register Mdev *fmp, *dmp; ! 178: ! 179: if (n != 4) { ! 180: fprint(STDERR, "bad root spec\n"); ! 181: errs++; ! 182: return; ! 183: } ! 184: if ((fmp = mdlook(a[1])) == NULL) { ! 185: fprint(STDERR, "%s: unknown root fs\n", a[1]); ! 186: errs++; ! 187: return; ! 188: } ! 189: if ((dmp = mdlook(a[2])) == NULL) { ! 190: fprint(STDERR, "%s: unknown root device\n", a[2]); ! 191: errs++; ! 192: return; ! 193: } ! 194: rootfmp = fmp; ! 195: rootdmp = dmp; ! 196: rootmin = nconv(a[3]); ! 197: } ! 198: ! 199: #define NSWAP 10 ! 200: ! 201: Swapdev swaptab[NSWAP]; ! 202: int nswapdev; ! 203: int swapmaj, swapmin; /* set elsewhere to `drum' */ ! 204: ! 205: cfswap(a, n) ! 206: register char **a; ! 207: int n; ! 208: { ! 209: register Mdev *mp; ! 210: ! 211: if (n < 4) { ! 212: fprint(STDERR, "bad swap spec\n"); ! 213: errs++; ! 214: return; ! 215: } ! 216: if ((mp = mdlook(a[1])) == NULL) { ! 217: fprint(STDERR, "%s: unknown swap device\n"); ! 218: errs++; ! 219: return; ! 220: } ! 221: if (nswapdev >= NSWAP) { ! 222: fprint(STDERR, "too many swap devices\n"); ! 223: errs++; ! 224: return; ! 225: } ! 226: swaptab[nswapdev].mp = mp; ! 227: swaptab[nswapdev].minor = nconv(a[2]); ! 228: swaptab[nswapdev].size = nconv(a[3]); ! 229: nswapdev++; ! 230: } ! 231: ! 232: char *dumprout; ! 233: int dumpunit; ! 234: long dumplow, dumpsize; ! 235: ! 236: cfdump(a, n) ! 237: register char **a; ! 238: int n; ! 239: { ! 240: if (n != 5) { ! 241: fprint(STDERR, "bad dump spec\n"); ! 242: errs++; ! 243: return; ! 244: } ! 245: dumprout = estrdup(a[1]); ! 246: dumpunit = nconv(a[2]); ! 247: dumplow = nconv(a[3]); ! 248: dumpsize = nconv(a[4]); ! 249: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.