Annotation of cci/usr/src/etc/config/mkswapconf.c, revision 1.1.1.2

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)mkswapconf.c       4.1 (Berkeley) 8/13/83";
                      3: #endif
                      4: 
                      5: /*
                      6:  * Build a swap configuration file.
                      7:  */
                      8: #include "config.h"
                      9: 
                     10: #include <stdio.h>
                     11: #include <ctype.h>
1.1.1.2 ! root       12: #include <machine/param.h>
1.1       root       13: 
                     14: swapconf()
                     15: {
                     16:        register struct file_list *fl;
                     17:        struct file_list *do_swap();
                     18: 
                     19:        fl = conf_list;
                     20:        while (fl) {
                     21:                if (fl->f_type != SYSTEMSPEC) {
                     22:                        fl = fl->f_next;
                     23:                        continue;
                     24:                }
                     25:                fl = do_swap(fl);
                     26:        }
                     27: }
                     28: 
                     29: struct file_list *
                     30: do_swap(fl)
                     31:        register struct file_list *fl;
                     32: {
                     33:        FILE *fp;
                     34:        char  swapname[80], *cp;
                     35:        register struct file_list *swap;
                     36:        dev_t dev;
1.1.1.2 ! root       37:        int i;
1.1       root       38: 
                     39:        if (eq(fl->f_fn, "generic")) {
                     40:                fl = fl->f_next;
                     41:                return (fl->f_next);
                     42:        }
                     43:        (void) sprintf(swapname, "swap%s.c", fl->f_fn);
                     44:        fp = fopen(path(swapname), "w");
                     45:        if (fp == 0) {
                     46:                perror(path(swapname));
                     47:                exit(1);
                     48:        }
                     49:        fprintf(fp, "#include \"../h/param.h\"\n");
                     50:        fprintf(fp, "#include \"../h/conf.h\"\n");
                     51:        fprintf(fp, "\n");
                     52:        /*
                     53:         * If there aren't any swap devices
                     54:         * specified, just return, the error
                     55:         * has already been noted.
                     56:         */
                     57:        swap = fl->f_next;
                     58:        if (swap == 0 || swap->f_type != SWAPSPEC) {
                     59:                (void) unlink(path(swapname));
                     60:                fclose(fp);
                     61:                return (swap);
                     62:        }
                     63:        fprintf(fp, "dev_t\trootdev = makedev(%d, %d);\n",
                     64:                major(fl->f_rootdev), minor(fl->f_rootdev));
                     65:        fprintf(fp, "dev_t\targdev  = makedev(%d, %d);\n",
                     66:                major(fl->f_argdev), minor(fl->f_argdev));
                     67:        fprintf(fp, "dev_t\tdumpdev = makedev(%d, %d);\n",
                     68:                major(fl->f_dumpdev), minor(fl->f_dumpdev));
                     69:        fprintf(fp, "\n");
                     70:        fprintf(fp, "struct\tswdevt swdevt[] = {\n");
1.1.1.2 ! root       71: 
        !            72:        /*
        !            73:         * The commented code is for the previously more general case.
        !            74:         * Now, we configure for swap on 0b and leave room for more
        !            75:         * swap partitions.  If a configuration file is ever given
        !            76:         * directly to the user, we should revert back to the previous
        !            77:         * code.
        !            78:         *
1.1       root       79:        do {
                     80:                dev = swap->f_swapdev;
1.1.1.2 ! root       81:                fprintf(fp, "\t{ makedev(%d, %d),\t0,\t%d },\t/* %s *//*\n",
1.1       root       82:                    major(dev), minor(dev), swap->f_swapsize, swap->f_fn);
                     83:                swap = swap->f_next;
                     84:        } while (swap && swap->f_type == SWAPSPEC);
1.1.1.2 ! root       85:         */
        !            86:        dev = swap->f_swapdev;
        !            87:        fprintf(fp, "\t{ makedev(%d, %d),\t0,\t%d,\t0 },\t/* %s */\n",
        !            88:            major(dev), minor(dev), swap->f_swapsize, swap->f_fn);
        !            89:        for (i = 1; i < NSWAPDRIVES; i++) {
        !            90:                fprintf(fp, "\t{ -1,\t\t\t0,\t0,\t0 },\t");
        !            91:                fprintf(fp, "/* available for swap */\n");
        !            92:        }
        !            93:        fprintf(fp, "\t{ 0,\t\t\t0,\t0,\t0 }\t/* end of table */\n");
1.1       root       94:        fprintf(fp, "};\n");
                     95:        fclose(fp);
                     96:        return (swap);
                     97: }
                     98: 
                     99: static int devtablenotread = 1;
                    100: static struct devdescription {
                    101:        char    *dev_name;
                    102:        int     dev_major;
                    103:        struct  devdescription *dev_next;
                    104: } *devtable;
                    105: 
                    106: /*
                    107:  * Given a device name specification figure out:
                    108:  *     major device number
                    109:  *     partition
                    110:  *     device name
                    111:  *     unit number
                    112:  * This is a hack, but the system still thinks in
                    113:  * terms of major/minor instead of string names.
                    114:  */
                    115: dev_t
                    116: nametodev(name, defunit, defpartition)
                    117:        char *name;
                    118:        int defunit;
                    119:        char defpartition;
                    120: {
                    121:        char *cp, partition;
                    122:        int unit;
                    123:        register struct devdescription *dp;
                    124: 
                    125:        cp = name;
                    126:        if (cp == 0) {
                    127:                fprintf(stderr, "config: internal error, nametodev\n");
                    128:                exit(1);
                    129:        }
                    130:        while (*cp && !isdigit(*cp))
                    131:                cp++;
                    132:        unit = *cp ? atoi(cp) : defunit;
                    133:        if (unit < 0 || unit > 7) {
                    134:                fprintf(stderr,
                    135: "config: %s: invalid device specification, unit out of range\n", name);
                    136:                unit = defunit;                 /* carry on more checking */
                    137:        }
                    138:        if (*cp) {
                    139:                *cp++ = '\0';
                    140:                while (*cp && isdigit(*cp))
                    141:                        cp++;
                    142:        }
                    143:        partition = *cp ? *cp : defpartition;
                    144:        if (partition < 'a' || partition > 'h') {
                    145:                fprintf(stderr,
                    146: "config: %c: invalid device specification, bad partition\n", *cp);
                    147:                partition = defpartition;       /* carry on */
                    148:        }
                    149:        if (devtablenotread)
                    150:                initdevtable();
                    151:        for (dp = devtable; dp->dev_next; dp = dp->dev_next)
                    152:                if (eq(name, dp->dev_name))
                    153:                        break;
                    154:        if (dp == 0) {
                    155:                fprintf(stderr, "config: %s: unknown device\n", name);
                    156:                return (NODEV);
                    157:        }
                    158:        return (makedev(dp->dev_major, (unit << 3) + (partition - 'a')));
                    159: }
                    160: 
                    161: char *
                    162: devtoname(dev)
                    163:        dev_t dev;
                    164: {
                    165:        char buf[80]; 
                    166:        register struct devdescription *dp;
                    167: 
                    168:        if (devtablenotread)
                    169:                initdevtable();
                    170:        for (dp = devtable; dp->dev_next; dp = dp->dev_next)
                    171:                if (major(dev) == dp->dev_major)
                    172:                        break;
                    173:        if (dp == 0)
                    174:                dp = devtable;
                    175:        sprintf(buf, "%s%d%c", dp->dev_name,
                    176:                minor(dev) >> 3, (minor(dev) & 07) + 'a');
                    177:        return (ns(buf));
                    178: }
                    179: 
                    180: initdevtable()
                    181: {
                    182:        char buf[BUFSIZ];
                    183:        int maj;
                    184:        register struct devdescription **dp = &devtable;
                    185:        FILE *fp;
                    186: 
                    187:        sprintf(buf, "../conf/devices.%s", machinename);
                    188:        fp = fopen(buf, "r");
                    189:        if (fp == NULL) {
                    190:                fprintf(stderr, "config: can't open %s\n", buf);
                    191:                exit(1);
                    192:        }
                    193:        while (fscanf(fp, "%s\t%d\n", buf, &maj) == 2) {
                    194:                *dp = (struct devdescription *)malloc(sizeof (**dp));
                    195:                (*dp)->dev_name = ns(buf);
                    196:                (*dp)->dev_major = maj;
                    197:                dp = &(*dp)->dev_next;
                    198:        }
                    199:        *dp = 0;
                    200:        fclose(fp);
                    201:        devtablenotread = 0;
                    202: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.