Annotation of coherent/d/etc/build/build.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * build.c
                      3:  * 07/09/92    COH 386 release
                      4:  *
                      5:  * Build (install) COHERENT on a system, part 1.
                      6:  * The second part of the install procedure is in install.c.
                      7:  * Uses common routines in build0.c,
                      8:  * serial number checking in numtab.c and serialno.c.
                      9:  * Requires floating point output: cc build.c build0.c numtab.c serialno.c -f
                     10:  * Usage: build [ -dv ]
                     11:  * Options:
                     12:  *     -d      Debug, echo commands without executing
                     13:  *     -v      Verbose
                     14:  *
                     15:  * In addition to the files necessary to run the single user system
                     16:  * (/coherent, /etc/init, /bin/sh, /dev/console, /dev/null, etc.),
                     17:  * the build disk from which this program runs must contain:
                     18:  *     In /bin:        chgrp, chown, cpdir, date, echo, ln, mkdir, mv, rm, touch
                     19:  *     In /conf:       boot, mboot, patch
                     20:  *     In /dev:        at[01][abcdx], rat[01][abcd]
                     21:  *     In /etc:        ATclock, badscan, fdisk, mkdev, mkfs, mount, umount
                     22:  * It must also contain directories /mnt and /tmp.
                     23:  * This program runs from a write-protected floppy-disk-based COHERENT
                     24:  * boot disk, so it writes only to directory /tmp (mounted on a RAM disk).
                     25:  */
                     26: 
                     27: #include <stdio.h>
                     28: #include <canon.h>
                     29: #include <string.h>
                     30: #include <time.h>
                     31: #include <sys/devices.h>
                     32: #include <sys/fdisk.h>
                     33: #include <sys/filsys.h>
                     34: #include <sys/types.h>
                     35: #include <access.h>
                     36: #include "build0.h"
                     37: #include "serialno.h"
                     38: 
                     39: /* Compilation switches. */
                     40: #define        DOSSHRINK       0               /* punt dosshrink for now       */
                     41: 
                     42: /* Manifest constants. */
                     43: #define        VERSION         "3.7"
                     44: #define        USAGE           "Usage: /etc/build [ -dv ]\n"
                     45: #define        ATDEVS          (NPARTN+NPARTN) /* number of AT disk devices    */
                     46: #define        BSIZE           512             /* sector size                  */
                     47: #if _I386
                     48: #define        BAR_BAR         "__"            /* 1st copy of serial # */
                     49: #define        BAR_ENTRY       "_entry"        /* 2nd copy of serial # */
                     50: #define        MAXSIZE         500             /* suggested max size (MB)      */
                     51: #define        MINSIZE         9               /* required root size (MB)      */
                     52: #define        NEEDSIZE        10              /* suggested min root size (MB) */
                     53: #define        PIPEDEV         "pipedev"       /* kernel pipe F.S. device */
                     54: #define        RONFLAG         "ronflag"       /* kernel readonly root F.S. flag */
                     55: #define        ROOTDEV         "rootdev"       /* kernel root F.S. device */
                     56: #else
                     57: #define        BAR_BAR         "___"           /* 1st copy of serial # */
                     58: #define        BAR_ENTRY       "_entry_"       /* 2nd copy of serial # */
                     59: #define        MAXSIZE         75              /* suggested max size (MB)      */
                     60: #define        MINSIZE         8               /* required root size (MB)      */
                     61: #define        NEEDSIZE        10              /* suggested min root size (MB) */
                     62: #define        PIPEDEV         "pipedev_"      /* kernel pipe F.S. device */
                     63: #define        RONFLAG         "ronflag_"      /* kernel readonly root F.S. flag */
                     64: #define        ROOTDEV         "rootdev_"      /* kernel root F.S. device */
                     65: #endif
                     66: #define        NAMESIZE        6               /* max device name buffer size  */
                     67: #define        NDEVICES        24              /* number of disk devices       */
                     68: 
                     69: /* (unsigned long) sectors to (double) megabytes. */
                     70: #define        meg(sec)        ((double)sec * BSIZE / 1000000.)
                     71: 
                     72: /* Device table structure. */
                     73: typedef        struct  device  {
                     74:        char            d_xname[NAMESIZE];      /* partition table name */
                     75:        char            d_dname[NAMESIZE];      /* device name          */
                     76:        int             d_major;                /* major number         */
                     77:        int             d_minor;                /* minor number         */
                     78:        int             d_flags;                /* flags                */
                     79:        unsigned long   d_size;                 /* size in blocks       */
                     80: }      DEVICE;
                     81: 
                     82: /* Flag bits. */
                     83: #define        F_COH   0x01                            /* COHERENT partition   */
                     84: #define        F_BOOT  0x02                            /* Active               */
                     85: #define        F_ROOT  0x04                            /* Root                 */
                     86: #define        F_FS    0x08                            /* File system exists   */
                     87: #define        F_MOUNT 0x10                            /* Mounted by /etc/rc   */
                     88: #define        F_PROTO 0x20                            /* Proto created        */
                     89: #define        F_SCAN  0x40                            /* Badscanned           */
                     90: #define        F_ATDEV 0x80                            /* AT device            */
                     91: #define        isflag(i, f)    ((devices[i].d_flags & (f)) != 0)
                     92: #define        notflag(i, f)   ((devices[i].d_flags & (f)) == 0)
                     93: #define        clrflag(i, f)   devices[i].d_flags &= ~(f)
                     94: #define        setflag(i, f)   devices[i].d_flags |= (f)
                     95: 
                     96: /*
                     97:  * Device table.
                     98:  * add_devices() adds entries for devices created by /etc/mkdev.
                     99:  * fdisk() zaps the entries for which the xdevice open fails.
                    100:  */
                    101: DEVICE devices[NDEVICES] = {
                    102:        { "at0x", "at0a", AT_MAJOR, 0, F_ATDEV, 0L },
                    103:        { "at0x", "at0b", AT_MAJOR, 1, F_ATDEV, 0L },
                    104:        { "at0x", "at0c", AT_MAJOR, 2, F_ATDEV, 0L },
                    105:        { "at0x", "at0d", AT_MAJOR, 3, F_ATDEV, 0L },
                    106:        { "at1x", "at1a", AT_MAJOR, 4, F_ATDEV, 0L },
                    107:        { "at1x", "at1b", AT_MAJOR, 5, F_ATDEV, 0L },
                    108:        { "at1x", "at1c", AT_MAJOR, 6, F_ATDEV, 0L },
                    109:        { "at1x", "at1d", AT_MAJOR, 7, F_ATDEV, 0L }
                    110: };
                    111: 
                    112: /* Externals. */
                    113: extern long    atol();
                    114: extern char    *fgets();
                    115: extern long    lseek();
                    116: extern time_t  time();
                    117: 
                    118: /* Forward. */
                    119: void   add_devices();
                    120: void   badscan();
                    121: void   copy();
                    122: char   *devname();
                    123: void   done();
                    124: void   fdisk();
                    125: void   get_timezone();
                    126: int    is_fs();
                    127: void   mkdev();
                    128: void   mkfs();
                    129: void   patches();
                    130: char   *protoname();
                    131: char   *rawname();
                    132: void   rootpatch();
                    133: void   set_date();
                    134: void   uucp();
                    135: void   user_devices();
                    136: void   welcome();
                    137: char   *xname();
                    138: 
                    139: /* Globals. */
                    140: int    active = -1;                    /* active partition     */
                    141: char   *activeos;                      /* active partition OS  */
                    142: char   buf2[NBUF];                     /* extra buffer         */
                    143: HDISK_S        hd;                             /* hard disk boot block */
                    144: int    mboot;                          /* mboot replaced       */
                    145: int    ncohdev;                        /* number of COHERENT devices */
                    146: int    ndevices = ATDEVS;              /* number of devices    */
                    147: int    protoflag;                      /* prototypes created   */
                    148: int    root;                           /* root partition       */
                    149: char   tzone[NBUF];                    /* timezone             */
                    150: char   tzone5[NBUF];                   /* timezone for Sys V   */
                    151: 
                    152: main(argc, argv) int argc; char *argv[];
                    153: {
                    154:        register char *s;
                    155: 
                    156:        argv0 = argv[0];
                    157:        abortmsg = 1;
                    158:        usagemsg = USAGE;
                    159:        if (argc > 1 && argv[1][0] == '-') {
                    160:                for (s = &argv[1][1]; *s; ++s) {
                    161:                        switch(*s) {
                    162:                        case 'd':       ++dflag;        break;
                    163:                        case 'v':       ++vflag;        break;
                    164:                        case 'V':
                    165:                                fprintf(stderr, "%s: V%s\n", argv0, VERSION);
                    166:                                break;
                    167:                        default:        usage();        break;
                    168:                        }
                    169:                }
                    170:                --argc;
                    171:                ++argv;
                    172:        }
                    173:        if (argc != 1)
                    174:                usage();
                    175: 
                    176:        welcome();
                    177:        set_date();
                    178:        mkdev();
                    179:        fdisk();
                    180:        rootpatch();
                    181:        badscan();
                    182:        mkfs();
                    183:        copy();
                    184:        user_devices();
                    185:        uucp();
                    186:        sys("/conf/ldker", S_FATAL);
                    187:        patches();
                    188:        sys("/bin/echo /etc/build: success >>/mnt/etc/install.log", S_NONFATAL);
                    189:        sprintf(cmd, "TIMEZONE=\"%s\" /bin/date >>/mnt/etc/install.log", tzone);
                    190:        sys(cmd, S_NONFATAL);
                    191:        sys("/bin/echo >>/mnt/etc/install.log", S_NONFATAL);
                    192:        done();
                    193:        sync();
                    194:        sys("/etc/reboot -p", S_IGNORE);
                    195:        /* NOTREACHED */
                    196:        exit(0);
                    197: }
                    198: 
                    199: /*
                    200:  * Append devices as specified by /etc/mkdev to devices table.
                    201:  */
                    202: void
                    203: add_devices()
                    204: {
                    205:        register FILE *fp;
                    206:        register int i, n;
                    207: 
                    208:        if ((fp = fopen("/tmp/devices", "r")) == NULL)
                    209:                return;
                    210:        for (i = ndevices; i < NDEVICES; i++) {
                    211:                n = fscanf(fp, "%s %s %d %d\n",
                    212:                        devices[i].d_xname, devices[i].d_dname,
                    213:                        &devices[i].d_major, &devices[i].d_minor);
                    214:                if (n == 0 || n == EOF)
                    215:                        break;
                    216:                else if (n != 4)
                    217:                        fatal("scanf failed on /tmp/devices, n=%d", n);
                    218:                ++ndevices;
                    219:        }
                    220:        if (i == NDEVICES)
                    221:                nonfatal("too many devices, excess ignored");
                    222:        fclose(fp);
                    223: }
                    224: 
                    225: /*
                    226:  * Scan each COHERENT device for bad blocks.
                    227:  */
                    228: void
                    229: badscan()
                    230: {
                    231:        register int i;
                    232:        register char *name;
                    233: 
                    234:        cls(0);
                    235:        printf(
                    236: "The next step in installation is to scan each COHERENT partition\n"
                    237: "for bad blocks.  Be patient, this takes a few minutes.\n"
                    238:                );
                    239:        for (i = 0; i < ndevices; i++) {
                    240:                if (notflag(i, F_COH) || notflag(i, F_ATDEV))
                    241:                        continue;       /* scan only AT device COH partitions */
                    242:                printf("\n");
                    243:                name = devname(i, 0);
                    244:                if (isflag(i, F_FS)) {
                    245:                        printf(
                    246: "Partition %d (%s) already contains a COHERENT filesystem.\n"
                    247: "If you wish to continue to use the existing filesystem, you can skip\n"
                    248: "scanning it for bad blocks.  If you want to replace it with an empty\n"
                    249: "filesystem, you must scan it for bad blocks first.\n",
                    250:                                i, name);
                    251:                        if (yes_no("Do you want to scan %s for bad blocks",
                    252:                                name) == 0)
                    253:                                continue;
                    254:                }
                    255:                printf("Scanning partition %d:\n", i);
                    256:                setflag(i, F_SCAN);
                    257:                sprintf(cmd, "/etc/badscan -v -o %s %s %s",
                    258:                        protoname(i), rawname(i, 1), xname(i, 1));
                    259:                if (sys(cmd, S_NONFATAL) == 0) {
                    260:                        setflag(i, F_PROTO);
                    261:                        ++protoflag;
                    262:                }
                    263:        }
                    264: }
                    265: 
                    266: /*
                    267:  * Mount the root filesystem, copy files to it, patch /coherent.
                    268:  * Kludge around as required.
                    269:  */
                    270: void
                    271: copy()
                    272: {
                    273:        cls(0);
                    274:        printf(
                    275: "The next step is to copy some COHERENT files from the diskette to the\n"
                    276: "root filesystem of your hard disk.  This will take a few minutes...\n"
                    277:                );
                    278: 
                    279:        /* Mount the filesystem. */
                    280:        sprintf(cmd, "/etc/mount %s /mnt", devname(root, 1));
                    281:        sys(cmd, S_FATAL);
                    282: 
                    283:        /* Copy kernel patch and link scripts in case regen needed some day */
                    284:        /* Do it now - don't wait for the whole diskette to cpdir */
                    285:        sprintf(cmd, "/bin/cpdir -ad%s /conf /mnt/conf", (vflag) ? "v" : "");
                    286:        sys(cmd, S_FATAL);
                    287:        sprintf(cmd, "/bin/cpdir -ad%s /tmp /mnt/conf/gen", (vflag) ? "v" : "");
                    288:        sys(cmd, S_FATAL);
                    289:        printf( "..............\n" );
                    290: 
                    291:        /* Copy the boot floppy to it. */
                    292:        sprintf(cmd, "/bin/cpdir -ad%s -smnt -sbegin -stmp -s/conf / /mnt",
                    293:          (vflag) ? "v" : "");
                    294:        sys(cmd, S_FATAL);
                    295:        if (!is_dir("/mnt/mnt"))
                    296:                sys("/bin/mkdir /mnt/mnt", S_FATAL);
                    297:        sys("/bin/chmog 0755 bin bin /mnt/mnt", S_NONFATAL);
                    298: 
                    299:        /* Write entry to /etc/install.log. */
                    300:        sys("/bin/echo /etc/build: >>/mnt/etc/install.log", S_NONFATAL);
                    301:        sprintf(cmd, "TIMEZONE=\"%s\" /bin/date >>/mnt/etc/install.log", tzone);
                    302:        sys(cmd, S_NONFATAL);
                    303: 
                    304: #if 0
                    305:        /* If /etc/fdisk created patched /tmp/coherent, replace /coherent. */
                    306:        if (exists("/mnt/tmp/coherent")) {
                    307:                sys("/bin/mv /mnt/tmp/coherent /mnt/coherent", S_FATAL);
                    308:                sys("/bin/chmod 0400 /mnt/coherent", S_NONFATAL);
                    309:                sys("/bin/chown sys /mnt/coherent", S_NONFATAL);
                    310:                sys("/bin/chgrp sys /mnt/coherent", S_NONFATAL);
                    311:        }
                    312: #endif
                    313: 
                    314:        /* If /etc/mkdev created devices in /tmp/dev, copy them to /dev. */
                    315:        /* Remove the copies in /tmp/dev on the hard disk. */
                    316:        if (exists("/tmp/dev"))
                    317:                sys("/bin/cpdir -d /tmp/dev /mnt/dev", S_FATAL);
                    318: #if !_I386
                    319:        /*
                    320:         * As of COH 3.2, support for COM ports is not built into the system.
                    321:         * Echo lines to /tmp/drvld.all to drvld com line support,
                    322:         * then replace /mnt/etc/drvld.all and make sure permissions are right.
                    323:         */
                    324:        sys("/bin/echo /etc/drvld -r /drv/al0 >>/tmp/drvld.all", S_NONFATAL);
                    325:        sys("/bin/echo /etc/drvld -r /drv/al1 >>/tmp/drvld.all", S_NONFATAL);
                    326: #endif
                    327:        if (exists("/tmp/drvld.all")) {
                    328:                sys("/bin/cp /tmp/drvld.all /mnt/etc/drvld.all", S_NONFATAL);
                    329:                sys("/bin/chmog 0744 root root /mnt/etc/drvld.all", S_NONFATAL);
                    330:        }
                    331: 
                    332:        sys("/bin/cat /tmp/ttys >>/mnt/etc/ttys", S_NONFATAL);
                    333: 
                    334:        /* Grow /lost+found to make room for files. */
                    335:        sys("cd /mnt/lost+found; "
                    336:            "/bin/touch a b c d e f g h i j k l m n o p q r s t u v w x y z; "
                    337:            "/bin/rm [a-z]", S_IGNORE);
                    338: 
                    339:        /* Create /autoboot. */
                    340:        sys("/bin/ln -f /mnt/coherent /mnt/autoboot", S_FATAL);
                    341: 
                    342:        /* Replace the build version of /etc/brc with the install version. */
                    343:        sys("/bin/rm /mnt/etc/brc", S_NONFATAL);
                    344:        sys("/bin/ln -f /mnt/etc/brc.install /mnt/etc/brc", S_FATAL);
                    345: 
                    346:        /* Link root device to /dev/root. */
                    347:        sprintf(cmd, "/bin/ln -f /mnt%s /mnt/dev/root", devname(root, 0));
                    348:        sys(cmd, S_FATAL);
                    349: 
                    350:        /* Write the timezone to /etc/timezone. */
                    351:        sprintf(cmd, "/bin/echo export TIMEZONE=\\\"%s\\\" >/mnt/etc/timezone", tzone);
                    352:        sys(cmd, S_NONFATAL);
                    353:        sprintf(cmd, "/bin/echo export TZ=\\\"%s\\\" >>/mnt/etc/timezone", tzone5);
                    354:        sys(cmd, S_NONFATAL);
                    355: 
                    356:        /* Write the serial number to /etc/serialno. */
                    357:        sprintf(cmd, "/bin/echo %s >/mnt/etc/serialno", serialno);
                    358:        sys(cmd, S_NONFATAL);
                    359: 
                    360:        /* Save the prototypes from /tmp to /conf. */
                    361:        if (protoflag)
                    362:                sys("/bin/mv /tmp/*.proto /mnt/conf", S_NONFATAL);
                    363: }
                    364: 
                    365: /*
                    366:  * Generate a device name from a DEVICE entry name.
                    367:  * Return a pointer to the statically allocated name.
                    368:  * If flag and not one of the built-in AT device names,
                    369:  * the device is in /tmp/dev rather than /dev.
                    370:  * Sleazy hack: this always writes "/tmp/dev/..." in the buffer and
                    371:  * massages the return value accordingly so that subsequent calls
                    372:  * with same i but different flag will not clobber previous return values.
                    373:  */
                    374: char *
                    375: devname(i, flag) int i, flag;
                    376: {
                    377:        static char name[4+4+1+NAMESIZE];       /* e.g. "/tmp/dev/at0a" */
                    378: 
                    379:        sprintf(name, "/tmp/dev/%s", devices[i].d_dname);
                    380:        return (flag && notflag(i, F_ATDEV)) ? name : name+4;
                    381: }
                    382: 
                    383: /*
                    384:  * Done.
                    385:  * Print useful information.
                    386:  */
                    387: void
                    388: done()
                    389: {
                    390:        cls(1);
                    391:        printf(
                    392: "You have installed the COHERENT operating system onto your hard disk.\n"
                    393: "To install files from the remaining diskettes in the installation kit,\n"
                    394: "you must boot the COHERENT system from the hard disk.  It will prompt\n"
                    395: "you to install the remaining diskettes in the installation kit.\n"
                    396: "\n"
                    397: "After you finish reading this information, remove the floppy disk,\n"
                    398: "hit <Enter> and your system will automatically reboot.\n"
                    399: "\n"
                    400:                );
                    401:        if (mboot) {
                    402:                printf(
                    403: "If you type a partition number (0 to 7) while\n"
                    404: "the boot procedure is trying to read the floppy disk,\n"
                    405: "your system will boot the operating system on that partition.\n"
                    406:                        );
                    407:                if (active != -1) {
                    408:                        printf("If you type nothing, your system will boot ");
                    409:                        if (active == root)
                    410:                                printf("COHERENT (partition %d).\n", active);
                    411:                        else {
                    412:                                printf("active partition %d", active);
                    413:                                if (activeos != NULL)
                    414:                                        printf(" (%s)", activeos);
                    415:                                printf(".\n", active);
                    416:                        }
                    417:                }
                    418:        } else
                    419:                printf(
                    420: "You must boot the new COHERENT root filesystem on partition %d.\n",
                    421:                        root);
                    422:        printf("\nNow remove the floppy disk so your system does not boot from the floppy.\n");
                    423:        if (mboot && root != active)
                    424:                printf(
                    425: "You MUST type %d when the system tries to read the floppy disk during the boot\n"
                    426: "procedure to boot the partition containing the new COHERENT root filesystem.\n",
                    427:                        root);
                    428: }
                    429: 
                    430: /*
                    431:  * Get partition table information.
                    432:  */
                    433: void
                    434: fdisk()
                    435: {
                    436:        register int fd, i, j, n, part, cohpart, flag;
                    437:        char *fname, *s;
                    438: 
                    439:        cls(1);
                    440:        printf(
                    441: "This installation procedure allows you to create one or more partitions\n"
                    442: "on your hard disk to contain the COHERENT system and its files.\n"
                    443: "Each disk drive may contain no more than four logical partitions.\n"
                    444: "If all four partitions on your disk are already in use, you will\n"
                    445: "have to overwrite at least one of them to install COHERENT.\n"
                    446: "If your disk uses fewer than four partitions and has enough unused space\n"
                    447: "for COHERENT (%d megabytes), you can install COHERENT into the unused space.\n"
                    448: "If you intend to install MS-DOS after installing COHERENT,\n"
                    449: "you must leave the first physical partition free for MS-DOS.\n"
                    450: "\n"
                    451: "The next part of the installation procedure will let you change the\n"
                    452: "partitions on your hard disk.  Data on unchanged hard disk partitions\n"
                    453: "will not be changed.  However, data already on your hard disk may be\n"
                    454: "destroyed if you change the base or the size of a logical partition,\n"
                    455: "or if you change the order of the partition table entries.\n"
                    456: "If you need to back up existing data from the hard disk,\n"
                    457: "type <Ctrl-C> now to interrupt COHERENT installation; then reboot your\n"
                    458: "system and back up your hard disk data onto diskettes.\n"
                    459: "\n"
                    460:                , NEEDSIZE);
                    461:        cls(1);
                    462:        printf(
                    463: "COHERENT initialization normally writes a new master bootstrap program onto\n"
                    464: "your hard disk.  The COHERENT master boot allows you to boot the operating\n"
                    465: "system on one selected disk partition (the active partition) automatically;\n"
                    466: "it also allows you to boot the operating system on any disk partition by\n"
                    467: "typing a key when you reboot.  Mark Williams strongly recommends that you\n"
                    468: "use the COHERENT master boot.  However, the COHERENT master boot may not\n"
                    469: "work with some operating systems (for example, Xenix) if you make the\n"
                    470: "COHERENT partition active; instead, leave the other partition (e.g. Xenix)\n"
                    471: "active and boot COHERENT by typing a key.  If you do not use the COHERENT\n"
                    472: "bootstrap, you must understand how to boot the COHERENT partition using your\n"
                    473: "existing bootstrap program.\n"
                    474: "\n"
                    475:                );
                    476:        if (yes_no("Do you want to use the COHERENT master boot"))
                    477:                ++mboot;
                    478: 
                    479: retry:
                    480:        /* Construct an /etc/fdisk command with appropriate xdevice names. */
                    481:        strcpy(cmd, "/etc/fdisk -cB");
                    482:        if (mboot)
                    483:                strcat(cmd, "b /conf/mboot");
                    484:        for (i = 0; i < ndevices; i++) {
                    485:                if (i == 0
                    486:                 || strcmp(devices[i-1].d_xname, devices[i].d_xname) != 0) {
                    487:                        if ((fd = open(xname(i, 1), 0)) < 0)
                    488:                                continue;
                    489:                        close(fd);
                    490:                        strcat(cmd, " ");
                    491:                        strcat(cmd, xname(i, 1));
                    492:                }
                    493:        }
                    494:        sys(cmd, S_FATAL);              /* do the fdisk command */
                    495: 
                    496:        /* Read the partition table and set device flags appropriately. */
                    497:        for (i = part = 0; i < ndevices; ++i) {
                    498:                if (i != 0
                    499:                 && strcmp(devices[i-1].d_xname, devices[i].d_xname) == 0)
                    500:                        continue;               /* partition already done */
                    501:                fname = xname(i, 1);
                    502:                if ((fd = open(fname, 0)) < 0)
                    503:                        continue;               /* cannot open xdevice */
                    504:                if (read(fd, &hd, sizeof hd) != sizeof hd)
                    505:                        fatal("%s: read failed", fname);
                    506:                close(fd);
                    507:                if (hd.hd_sig != HDSIG) {
                    508:                        nonfatal("%s: invalid partition table", fname);
                    509:                        continue;
                    510:                }
                    511:                /* The partition table is valid, check its partitions. */
                    512:                for (j = 0; j < NPARTN && i + j < ndevices; j++) {
                    513:                        n = i + j;              /* index in devices[] */
                    514:                        if (part != n) {
                    515:                                /*
                    516:                                 * Copy over unopenable partitions.
                    517:                                 * This allows subsequent code to use
                    518:                                 * the devices[] index as the partition number.
                    519:                                 */
                    520:                                devices[part] = devices[n];
                    521:                                n = part;
                    522:                        }
                    523:                        part++;                 /* another valid partition */
                    524:                        if (hd.hd_partn[j].p_boot != 0) {
                    525:                                setflag(n, F_BOOT);
                    526:                                if (active == -1)
                    527:                                        active = n;     /* first active partition */
                    528:                                switch(hd.hd_partn[j].p_sys) {
                    529:                                case SYS_COH:
                    530:                                        activeos = "COHERENT";
                    531:                                        break;
                    532:                                case SYS_DOS_12:
                    533:                                case SYS_DOS_16:
                    534:                                case SYS_DOS_XP:
                    535:                                case SYS_DOS_LARGE:
                    536:                                        activeos = "MS-DOS";
                    537:                                        break;
                    538:                                case SYS_XENIX:
                    539:                                        activeos = "Xenix";
                    540:                                        break;
                    541:                                default:
                    542:                                        activeos = NULL;
                    543:                                        break;
                    544:                                }
                    545:                        }
                    546:                        if (hd.hd_partn[j].p_sys != SYS_COH)
                    547:                                continue;
                    548: 
                    549:                        /* Make sure the device can be accessed. */
                    550:                        s = devname(n, 1);
                    551:                        if (!exists(s)) {
                    552:                                nonfatal("cannot open COHERENT partition %d (%s)",
                    553:                                        n, devname(n, 0));
                    554:                                continue;
                    555:                        } else if (hd.hd_partn[j].p_size == 0L) {
                    556:                                nonfatal("COHERENT partition %d (%s) is empty",
                    557:                                        j, devname(n, 0));
                    558:                                continue;
                    559:                        }
                    560: 
                    561:                        /* OK, set flags in the device table. */
                    562:                        ++ncohdev;
                    563:                        setflag(n, F_COH);
                    564:                        devices[n].d_size = hd.hd_partn[j].p_size;
                    565:                        if (is_fs(s, devices[n].d_size))
                    566:                                setflag(n, F_FS);
                    567: 
                    568:                        /* Make sure the device is not mounted. */
                    569:                        sprintf(cmd, "/etc/umount %s 2>/dev/null", s);
                    570:                        sys(cmd, S_IGNORE);
                    571:                }
                    572:        }
                    573:        ndevices = part;
                    574:        if (ndevices == 0)
                    575:                fatal("cannot open partition tables");
                    576:        else if (ncohdev == 0)
                    577:                fatal("no COHERENT partition found");
                    578:        cls(0);
                    579:        printf("Your system includes %d COHERENT partition%s:\n",
                    580:                ncohdev, (ncohdev == 1) ? "" : "s");
                    581:        printf("Drive Partition\t  Device\tMegabytes\n");
                    582:        for (flag = i = 0; i < ndevices; i++)
                    583:                if (isflag(i, F_COH)) {
                    584:                        cohpart = i;
                    585:                        printf("%3d\t%3d\t%s\t%.2f\n",
                    586:                                i/NPARTN,
                    587:                                i,
                    588:                                devname(i, 0),
                    589:                                meg(devices[i].d_size));
                    590:                        if (((int)meg(devices[i].d_size)) > MAXSIZE)
                    591:                                flag = 1;
                    592:                }
                    593:        if (flag) {
                    594:                printf(
                    595: "\n"
                    596: "Your system includes a large COHERENT filesystem (larger than %d megabytes).\n"
                    597: #if !_I386
                    598: "The /etc/mkfs command which builds COHERENT 286 filesystems may run out of\n"
                    599: "memory and fail on large filesystems.\n"
                    600: #endif
                    601: "You should repartition the hard disk to define smaller COHERENT partitions.\n",
                    602:                        MAXSIZE);
                    603:                if (yes_no("Do you want to repartition the hard disk"))
                    604:                        goto retry;
                    605:                printf("\n");
                    606:        }
                    607:        if (ncohdev == 1) {
                    608:                root = cohpart;
                    609:                setflag(root, F_ROOT);
                    610:                return;
                    611:        }
                    612:        printf(
                    613: "You must specify one COHERENT partition as the root filesystem.\n"
                    614: "The root filesystem contains the files normally used by COHERENT.\n"
                    615: "The root filesystem should contain at least %d megabytes.\n",
                    616:                NEEDSIZE);
                    617:        if (ndevices > ATDEVS)
                    618:                printf(
                    619: "The COHERENT root filesystem must be on partition 0 through 7.\n"
                    620:                        );
                    621:        if (active != -1 && isflag(active, F_COH)) {
                    622:                printf("COHERENT partition %d is marked as active in the partition table.\n",
                    623:                        active);
                    624:                printf("If you choose it as the root, you can boot COHERENT automatically.\n");
                    625:        }
                    626:        printf("\n");
                    627: again:
                    628:        s = get_line("Which partition do you want to be the root filesystem?");
                    629:        root = *s - '0';
                    630:        if (*++s != '\0' || root < 0 || root >= ATDEVS || notflag(root, F_COH)) {
                    631:                printf("Enter a number between 0 and 7 which specifies a COHERENT partition.\n");
                    632:                goto again;
                    633:        }
                    634:        if (meg(devices[root].d_size) < (double)NEEDSIZE) {
                    635:                printf("Partition %d contains only %.2f megabytes.\n",
                    636:                        root, meg(devices[root].d_size));
                    637:                if (meg(devices[root].d_size) < (double)MINSIZE) {
                    638:                        printf("It is too small to contain the COHERENT root filesystem.\n");
                    639:                        goto again;
                    640:                }
                    641:                if (!yes_no("Are you sure you want it to be the root partition"))
                    642:                        goto again;
                    643:        }
                    644:        setflag(root, F_ROOT);
                    645: }
                    646: 
                    647: /*
                    648:  * Set up a nonstandard timezone.
                    649:  */
                    650: void
                    651: get_timezone(dstflag)
                    652: int dstflag;
                    653: {
                    654:        register char *s;
                    655:        int diff;
                    656:        char std_abbr[20], dst_abbr[20];
                    657:        int east_of_gr;
                    658: 
                    659:        /* tzone5 is like tzone except no colons and number is in hours */
                    660: 
                    661:        printf(
                    662: "You need to specify an abbreviation for your timezone,\n"
                    663: "whether you are east or west of Greenwich, England,\n"
                    664: "and the difference in minutes between your timezone\n"
                    665: "and Greenwich Time (called UT or GMT).  For example,\n"
                    666: "Germany is 60 minutes of time east of Greenwich.\n"
                    667:                );
                    668:        s = get_line("Abbreviation for your timezone:");
                    669:        strcpy(std_abbr, s);
                    670:        east_of_gr = yes_no("Is your timezone east of Greenwich");
                    671:        s = get_line("Difference in minutes from GMT:");
                    672:        diff = atoi(s);
                    673:        if (east_of_gr)
                    674:                diff = -diff;
                    675:        if (dstflag) {
                    676:                s = get_line("Abbreviation for your daylight savings timezone:");
                    677:                strcpy(dst_abbr, s);
                    678:                sprintf(tzone, "%s:%d:%s:1.1.4", std_abbr, diff, dst_abbr);
                    679:                sprintf(tzone5, "%s%d%s", std_abbr, diff/60, dst_abbr);
                    680:        } else {
                    681:                sprintf(tzone, "%s:%d:", std_abbr, diff);
                    682:                sprintf(tzone5, "%s%d", std_abbr, diff/60);
                    683:        }
                    684: }
                    685: 
                    686: /*
                    687:  * Check if a special file is a well-formed filesystem.
                    688:  * This routine is derived from code in "mount.c".
                    689:  * Here the check that "special" is a block special file is eliminated
                    690:  * and the size is checked against the partition size.
                    691:  */
                    692: int
                    693: is_fs(special, size) char *special; unsigned long size;
                    694: {
                    695:        static struct filsys f;
                    696:        register int fd;
                    697:        register struct filsys *fp;
                    698:        register daddr_t *dp;
                    699:        register ino_t *ip, maxinode;
                    700: 
                    701:        if ((fd = open(special, 0)) < 0                 /* cannot open */
                    702:         || lseek(fd, (long)SUPERI*BSIZE, 0) == -1L     /* seek failed */
                    703:         || read(fd, &f, sizeof(f)) != sizeof(f))       /* read failed */
                    704:                return 0;
                    705:        close(fd);
                    706: 
                    707:        /* Canonical stuff. */
                    708:        fp = &f;
                    709:        canshort(fp->s_isize);
                    710:        candaddr(fp->s_fsize);
                    711:        canshort(fp->s_nfree);
                    712:        for (dp = &fp->s_free[0]; dp < &fp->s_free[NICFREE]; dp += 1)
                    713:                candaddr(*dp);
                    714:        canshort(fp->s_ninode);
                    715:        for (ip = &fp->s_inode[0]; ip < &fp->s_inode[NICINOD]; ip += 1)
                    716:                canino(*ip);
                    717:        candaddr(fp->s_tfree);
                    718:        canino(fp->s_tinode);
                    719: 
                    720:        /* Test for rationality. */
                    721:        maxinode = (fp->s_isize - INODEI) * INOPB + 1;
                    722:        if (fp->s_isize >= fp->s_fsize)
                    723:                return 0;
                    724:        if ((fp->s_tfree < fp->s_nfree)
                    725:        ||  (fp->s_tfree >= fp->s_fsize - fp->s_isize + 1))
                    726:                return 0;
                    727:        if ((fp->s_tinode < fp->s_ninode) || (fp->s_tinode >= maxinode-1 ))
                    728:                return 0;
                    729:        for (dp = &fp->s_free[0]; dp < &fp->s_free[fp->s_nfree]; dp += 1)
                    730:                if ((*dp < fp->s_isize) || (*dp >= fp->s_fsize))
                    731:                        return 0;
                    732:        for (ip = &fp->s_inode[0]; ip < &fp->s_inode[fp->s_ninode]; ip += 1)
                    733:                if ((*ip < 1) || (*ip > maxinode))
                    734:                        return 0;
                    735:        if (fp->s_fsize > (daddr_t)size)
                    736:                return 0;
                    737:        if (fp->s_fsize > (daddr_t)size)
                    738:                nonfatal("warning: filesystem size=%ld but partition size=%ld",
                    739:                        (long)fp->s_fsize, size);
                    740:        return 1;
                    741: }
                    742: 
                    743: /*
                    744:  * Make new devices with /etc/mkdev if appropriate.
                    745:  */
                    746: void
                    747: mkdev()
                    748: {
                    749:        int hdc;
                    750: 
                    751:        cls(0);
                    752: printf("Most PC compatible computer systems use MFM, RLL, IDE, or ESDI disk\n");
                    753: printf("controllers and disk drives.  A few percent use SCSI disk drives.\n");
                    754: printf("Please indicate the type(s) of disk drive(s) used in your computer system.\n");
                    755: printf("If you are uncertain of the type, please select choice 1.\n\n");
                    756: printf("Are you using:\n\n");
                    757: printf("1.  AT-compatible hard drive controller (IDE/RLL/MFM/ESDI).\n");
                    758: printf("2.  SCSI hard drive controller.\n");
                    759: printf("3.  Both.\n\n");
                    760:        hdc = get_int(1, 3, "Enter your choice:");
                    761: 
                    762:        sprintf(cmd, "/etc/mkdev -b%s%s %s %s",
                    763:                (dflag) ? "d" : "",
                    764:                (vflag) ? "v" : "",
                    765:                (hdc == 1 || hdc == 3) ? "at" : "",
                    766:                (hdc == 2 || hdc == 3) ? "scsi" : "");
                    767:                sys(cmd, S_NONFATAL);
                    768:        if (hdc == 2 || hdc == 3)
                    769:                add_devices();
                    770: }
                    771: 
                    772: /*
                    773:  * Make filesystems on COHERENT partitions.
                    774:  */
                    775: void
                    776: mkfs()
                    777: {
                    778:        register int i;
                    779:        char *name;
                    780: 
                    781:        cls(0);
                    782:        printf(
                    783: "You must create an empty COHERENT filesystem on each COHERENT partition\n"
                    784: "before you can use it.  Creating an empty filesystem will destroy all\n"
                    785: "previously existing data on the partition.\n"
                    786:                );
                    787:        for (i = 0; i < ndevices; i++) {
                    788:                if (notflag(i, F_COH) || (isflag(i, F_ATDEV) && notflag(i, F_SCAN)))
                    789:                        continue;
                    790:                printf("\n");
                    791:                if (isflag(i, F_FS))
                    792:                        printf("Partition %d (%s) already contains a COHERENT filesystem.\n",
                    793:                                i, devname(i, 0));
                    794:                name = devname(i, 1);
                    795: again:
                    796:                if (yes_no("Do you want to create a new COHERENT filesystem on partition %d", i)) {
                    797:                        if (notflag(i, F_ATDEV))
                    798:                                sprintf(cmd, "/etc/mkfs %s %lu", name, devices[i].d_size);
                    799:                        else if (notflag(i, F_PROTO)) {
                    800:                                printf("The attempt to scan %s for bad blocks previously failed.",
                    801:                                        name);
                    802:                                if (yes_no("Do you want to create a new filesystem on it without a bad block list"))
                    803:                                        sprintf(cmd, "/etc/mkfs %s %lu", name, devices[i].d_size);
                    804:                                else
                    805:                                        continue;
                    806:                        } else
                    807:                                sprintf(cmd, "/etc/mkfs %s %s",
                    808:                                        name, protoname(i));
                    809:                        clrflag(i, F_FS);
                    810:                        if (sys(cmd, S_NONFATAL) == 0) {
                    811:                                setflag(i, F_FS);
                    812:                                if (notflag(i, F_PROTO)) {
                    813:                                        /* Stick a boot block on device. */
                    814:                                        /* The proto does it in the other case. */
                    815:                                        sprintf(cmd, "/bin/cp /conf/boot %s", name);
                    816:                                        sys(cmd, S_NONFATAL);
                    817:                                }
                    818: 
                    819:                                /*
                    820:                                 * Mount the file system,
                    821:                                 * create /lost+found,
                    822:                                 * unmount it.
                    823:                                 */
                    824:                                sprintf(cmd, "/etc/mount %s /mnt", name);
                    825:                                if (sys(cmd, S_NONFATAL))
                    826:                                        continue;
                    827:                                sprintf(cmd, "/bin/mkdir /mnt/lost+found");
                    828:                                if (sys(cmd, S_NONFATAL) == 0)
                    829:                                        sys(
                    830: "cd /mnt/lost+found; "
                    831: "/bin/touch a b c d e f g h i j k l m n o p q r s t u v w x y z; "
                    832: "/bin/rm [a-z]",
                    833:                                                S_IGNORE);
                    834:                                sprintf(cmd, "/etc/umount %s", name);
                    835:                                sys(cmd, S_NONFATAL);
                    836:                        } else if (i == root)
                    837:                                fatal("%s: root partition mkfs failed", name);
                    838:                } else if (i == root) {
                    839:                        if (notflag(i, F_FS)) {
                    840:                                printf("You must create a filesystem on the root partition.\n");
                    841:                                goto again;
                    842:                        } else {
                    843:                                /* Stick a boot block on the root device. */
                    844:                                sprintf(cmd, "/bin/cp /conf/boot %s", name);
                    845:                                sys(cmd, S_NONFATAL);
                    846:                        }
                    847:                }
                    848:        }
                    849: }
                    850: 
                    851: /*
                    852:  * Validate "name" to see if its an OK UUCP sitename or domain name.  If
                    853:  * anything suspicious is found, query the user and allow them to change
                    854:  * their answer.  The domain defaults to UUCP.  In order to avoid having
                    855:  * 10,000 machines called bbsuser, no default exists for the sitename.
                    856:  *
                    857:  * Return true if OK, false otherwise.
                    858:  */
                    859: int
                    860: ok_name(name, type)
                    861: unsigned char *name;           /* User's response to site/domain question */
                    862: int    type;                   /* 'd' == domain, 'u' == uucpname/site */
                    863: {
                    864:        int warn = 0;
                    865:        char    save[NBUF];     /* save off name for caller */
                    866: 
                    867:        if (type == 'd' && name[0] == '.')
                    868:                strcpy(name, name+1);
                    869:        strcpy(save, name);
                    870:        if (name[0] == '\0') {                  /* no input ? */
                    871:                if (type == 'd') {
                    872:                        strcpy(name, "UUCP");   /* default to UUCP domain */
                    873:                        return 1;
                    874:                } else {
                    875:                        return 0;               /* no defaults for sitename */
                    876:                }
                    877:        }
                    878:        if (type == 'u' && strlen(name) > 7) {
                    879:                ++warn;
                    880:                printf(
                    881: "The system name you chose is greater than seven characters in length.\n"
                    882:                );
                    883:        }
                    884:        if ((type == 'd' && strspn(name, "abcdefghijklmnopqrstuvwxyz"
                    885:                         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                    886:                         "0123456789"
                    887:                         ".-_") != strlen(name))
                    888:          || (type == 'u' && strspn(name, "abcdefghijklmnopqrstuvwxyz"
                    889:                         "0123456789") != strlen(name))) {
                    890:                ++warn;
                    891:                printf("The name you chose contains invalid characters.\n");
                    892:        }
                    893:        if (!warn)
                    894:                return 1;
                    895:        if (yes_no("Would you like to choose a different name"))
                    896:                return 0;
                    897:        strcpy(name, save);
                    898:        return 1;
                    899: }
                    900: 
                    901: /*
                    902:  * If PATCHFILE exists, execute it.
                    903:  */
                    904: void patches()
                    905: {
                    906:        if (access(PATCHFILE, AREAD) == 0) {
                    907:                sprintf(cmd, "/bin/sh %s", PATCHFILE);
                    908:                sys(cmd, S_NONFATAL);
                    909:        }
                    910: }
                    911: 
                    912: /*
                    913:  * Generate a prototype name from a DEVICE entry name.
                    914:  * Return a pointer to the statically allocated name.
                    915:  */
                    916: char *
                    917: protoname(i) int i;
                    918: {
                    919:        static char pname[5+NAMESIZE+6];        /* e.g. "/tmp/at0a.proto" */
                    920: 
                    921:        sprintf(pname, "/tmp/%s.proto", devices[i].d_dname);
                    922:        return pname;
                    923: }
                    924: 
                    925: /*
                    926:  * Generate a raw device name from a DEVICE entry name.
                    927:  * Return a pointer to the statically allocated name.
                    928:  * If flag and not one of the built-in AT device names,
                    929:  * the device is in /tmp/dev rather than /dev.
                    930:  */
                    931: char *
                    932: rawname(i, flag) int i, flag;
                    933: {
                    934:        static char rname[4+4+1+1+NAMESIZE];    /* e.g. "/tmp/dev/rat0a" */
                    935: 
                    936:        sprintf(rname, "/tmp/dev/r%s", devices[i].d_dname);
                    937:        return (flag && notflag(i,  F_ATDEV)) ? rname : rname+4;
                    938: }
                    939: /*
                    940:  * Patches to be done to the kernel - but can't do them yet because
                    941:  * kernel hasn't been linked.
                    942:  */
                    943: void
                    944: rootpatch()
                    945: {
                    946:        /*
                    947:         * After fdisk() we know "root".  Write to PATCHFILE the patches
                    948:         * that will be needed when a new kernel is linked at /mnt/coherent.
                    949:         */
                    950:        sprintf(cmd,
                    951:          "echo /conf/patch /mnt/coherent %s=0 %s=0x%lx:l %s=0x%lx:l >> %s\n",
                    952:          RONFLAG, BAR_BAR, atol(serialno),
                    953:          BAR_ENTRY, atol(serialno), PATCHFILE);
                    954:        sys(cmd, S_FATAL);
                    955:        sprintf(cmd,
                    956:          "echo /conf/patch /mnt/coherent "
                    957:          "\\\"%s\\=makedev\\(%d,%d\\)\\\" "
                    958:          "\\\"%s\\=makedev\\(%d,%d\\)\\\" >> %s\n",
                    959:          ROOTDEV, devices[root].d_major, devices[root].d_minor,
                    960:          PIPEDEV, devices[root].d_major, devices[root].d_minor, PATCHFILE);
                    961:        sys(cmd, S_FATAL);
                    962: }
                    963: 
                    964: /*
                    965:  * Date and time.
                    966:  */
                    967: void
                    968: set_date()
                    969: {
                    970:        register char *s;
                    971:        int dst_conv;           /* 1 if DST conversion will be used */
                    972:        int dst_now;            /* 1 if DST in effect today */
                    973:        int n;
                    974:        char *tz;
                    975:        time_t now;
                    976:        struct tm *tmp;
                    977:        char *timestr;
                    978: 
                    979: again:
                    980: #if 1  /* new set_date */
                    981: 
                    982:        /*
                    983:         * yyy:
                    984:         *
                    985:         * dst_conv = FALSE
                    986:         * dst_now = FALSE
                    987:         *
                    988:         * if using DST conversion
                    989:         *      dst_conv = TRUE
                    990:         *      if DST in effect today
                    991:         *              dst_now = TRUE
                    992:         * get date from system clock
                    993:         * if dst_conv and dst_now
                    994:         *      add 1 hour to date fetched
                    995:         * display date
                    996:         * while date not correct
                    997:         *      if proceed without setting clock
                    998:         *              goto xxx
                    999:         *      read date from kb
                   1000:         *      write date to CMOS clock and RAM clock
                   1001:         *      if dst_conv and dst_now
                   1002:         *              subtract 1 hour from date entered
                   1003:         *              write adjusted date to CMOS clock
                   1004:         * xxx:
                   1005:         * set TIMEZONE and TZ variables
                   1006:         * if date, TIMEZONE, and TZ not all correct
                   1007:         *      goto yyy
                   1008:         */
                   1009:        cls(0);
                   1010:        dst_conv = 0;
                   1011:        dst_now = 0;
                   1012:        printf(
                   1013: "You can run COHERENT with or without conversion for daylight savings time\n"
                   1014: "(summer time).  You should normally run with daylight savings time\n"
                   1015: "conversion.  However, if you are going to use both COHERENT and MS-DOS\n"
                   1016: "and you choose to run with daylight savings time conversion,\n"
                   1017: "your time will be wrong (by one hour) during daylight savings time\n"
                   1018: "while you are running under MS-DOS.\n"
                   1019: "\n"
                   1020:                );
                   1021:        if (yes_no(
                   1022:          "Do you want COHERENT to use daylight savings time conversion")) {
                   1023:                dst_conv = 1;
                   1024:                printf(
                   1025: "\n"
                   1026: "By default, COHERENT assumes daylight savings time begins on the\n"
                   1027: "first Sunday in April and ends on the last Sunday in October.\n"
                   1028: "If you want to change the defaults, edit the file \"/etc/timezone\"\n"
                   1029: "after you finish installing COHERENT.\n"
                   1030: "\n"
                   1031:                );
                   1032:                if (yes_no("Is daylight savings time currently in effect"))
                   1033:                        dst_now = 1;
                   1034:        }
                   1035:        sys("/bin/date `/etc/ATclock` > /dev/null", S_NONFATAL);
                   1036:        now = time(0);
                   1037:        if (dst_conv && dst_now)
                   1038:                now += 3600;
                   1039:        timestr = ctime(&now);
                   1040:        printf(
                   1041: "\nAccording to your system clock, your local date and time are:\n"
                   1042:        );
                   1043:        printf("%s\n", timestr);
                   1044:        if (!yes_no("Is this correct")) {
                   1045:                n = 0;
                   1046:                do {
                   1047:                        if (++n > 3) {
                   1048:                                printf(
                   1049: "The command which sets the internal real-time clock of your system is\n"
                   1050: "failing repeatedly.  Either you are entering the date and time incorrectly\n"
                   1051: "or your clock hardware is not completely AT-compatible.  If your clock\n"
                   1052: "hardware is incompatible, you can continue with the installation without\n"
                   1053: "setting the clock correctly.  However, if you do so, subsequent clock\n"
                   1054: "references (including file access and modification time information) will be\n"
                   1055: "incorrect and some commands (such as \"date\") will not function correctly.\n"
                   1056:                                        );
                   1057:                                if (yes_no("Do you want to proceed without setting the clock correctly"))
                   1058:                                        break;
                   1059:                                n = 0;
                   1060:                        }
                   1061:                        s = get_line(
                   1062: "\nEnter the correct date and time in the form YYMMDDHHMM.SS:"
                   1063:                                );
                   1064:                        sprintf(cmd, "/etc/ATclock %s >/dev/null", s);
                   1065:                } while (sys(cmd, S_NONFATAL) != 0);
                   1066:                sys("/bin/date `/etc/ATclock` >/dev/null", S_NONFATAL);
                   1067: 
                   1068:                if (dst_conv && dst_now) {
                   1069:                        /* Adjust for DST: set hardware clock back one hour. */
                   1070:                        now = time(0) - 3600;
                   1071:                        tmp = localtime(&now);
                   1072:                        sprintf(cmd,
                   1073:                          "/etc/ATclock %02d%02d%02d%02d%02d.%02d >/dev/null",
                   1074:                          tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday,
                   1075:                          tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
                   1076:                        sys(cmd, S_NONFATAL);
                   1077:                }
                   1078: 
                   1079:        }
                   1080: 
                   1081:        /* Timezone. */
                   1082:        cls(0);
                   1083:        printf(
                   1084: "Please choose one of the following timezones:\n"
                   1085: "\t0\tCentral European\n"
                   1086: "\t1\tGreenwich\n"
                   1087: "\t2\tNewfoundland\n"
                   1088: "\t3\tAtlantic\n"
                   1089: "\t4\tEastern\n"
                   1090: "\t5\tCentral\n"
                   1091: "\t6\tMountain\n"
                   1092: "\t7\tPacific\n"
                   1093: "\t8\tYukon\n"
                   1094: "\t9\tAlaska\n"
                   1095: "\t10\tBering\n"
                   1096: "\t11\tHawaii\n"
                   1097: "\t12\tOther\n"
                   1098:                );
                   1099:        do {
                   1100:                s = get_line("Timezone code:");
                   1101:        } while ((n = atoi(s)) < 0 || n > 12);
                   1102:        switch (n) {
                   1103:        /* N.B. entries truncated at tz[8] below if !dst_conv. */
                   1104:        case 0:         tz = "EST:-60:EDT:1.1.4";       break;
                   1105:        case 1:         tz = "GMT:000:GDT:1.1.4";       break;
                   1106:        case 2:         tz = "NST:210:NDT:1.1.4";       break;
                   1107:        case 3:         tz = "AST:240:ADT:1.1.4";       break;
                   1108:        case 4:         tz = "EST:300:EDT:1.1.4";       break;
                   1109:        case 5:         tz = "CST:360:CDT:1.1.4";       break;
                   1110:        case 6:         tz = "MST:420:MDT:1.1.4";       break;
                   1111:        case 7:         tz = "PST:480:PDT:1.1.4";       break;
                   1112:        case 8:         tz = "YST:540:YDT:1.1.4";       break;
                   1113:        case 9:         tz = "AST:600:ADT:1.1.4";       break;
                   1114:        case 10:        tz = "BST:660:BDT:1.1.4";       break;
                   1115:        case 11:        tz = "HST:600:HDT:1.1.4";       break;
                   1116:        case 12:        tz = NULL;                      break;
                   1117:        }
                   1118: 
                   1119:        if (tz == NULL)
                   1120:                get_timezone(dst_conv);
                   1121:        else {
                   1122:                strcpy(tzone, tz);
                   1123:                if (dst_conv) {
                   1124:                        /* for TZ, AST:240:ADT becomes AST4ADT */
                   1125:                        sprintf(tzone5, "%.3s%d%cDT",
                   1126:                          tz, atoi(tzone + 4)/60, tz[0]);
                   1127:                } else {
                   1128:                        /* for TZ, AST:240 becomes AST4 */
                   1129:                        sprintf(tzone5, "%.3s%d", tz, atoi(tzone + 4)/60);
                   1130:                        tzone[8] = '\0';
                   1131:                }
                   1132:        }
                   1133:        /* Done, print current time and retry if user botched it. */
                   1134:        printf("\nYour current local date and time are now:\n");
                   1135:        sprintf(cmd, "TIMEZONE='%s' /bin/date -s `/etc/ATclock`", tzone);
                   1136:        sys(cmd, S_NONFATAL);
                   1137: 
                   1138:        /* Write the timezone to /tmp/timezone for debug */
                   1139:        sprintf(cmd, "/bin/echo export TIMEZONE=\\\"%s\\\" >/tmp/timezone", tzone);
                   1140:        sys(cmd, S_NONFATAL);
                   1141:        sprintf(cmd, "/bin/echo export TZ=\\\"%s\\\" >>/tmp/timezone", tzone5);
                   1142:        sys(cmd, S_NONFATAL);
                   1143: #else
                   1144:        cls(0);
                   1145:        /* Get correct local time, set system time accordingly. */
                   1146:        printf(
                   1147: "It is important for the COHERENT system to know the correct date and time.\n"
                   1148: "You must provide information about your timezone and daylight savings time.\n"
                   1149: "\n"
                   1150: "According to your computer system clock, your current local date and time are:\n"
                   1151:                );
                   1152:        sys("/bin/date `/etc/ATclock`", S_NONFATAL);
                   1153:        if (!yes_no("Is this correct")) {
                   1154:                n = 0;
                   1155:                do {
                   1156:                        if (++n > 3) {
                   1157:                                printf(
                   1158: "The command which sets the internal real-time clock of your system is\n"
                   1159: "failing repeatedly.  Either you are entering the date and time incorrectly\n"
                   1160: "or your clock hardware is not completely AT-compatible.  If your clock\n"
                   1161: "hardware is incompatible, you can continue with the installation without\n"
                   1162: "setting the clock correctly.  However, if you do so, subsequent clock\n"
                   1163: "references (including file access and modification time information) will be\n"
                   1164: "incorrect and some commands (such as \"date\") will not function correctly.\n"
                   1165:                                        );
                   1166:                                if (yes_no("Do you want to proceed without setting the clock correctly"))
                   1167:                                        break;
                   1168:                                n = 0;
                   1169:                        }
                   1170:                        s = get_line(
                   1171: "Enter the correct date and time in the form YYMMDDHHMM.SS:"
                   1172:                                );
                   1173:                        sprintf(cmd, "/etc/ATclock %s >/dev/null", s);
                   1174:                } while (sys(cmd, S_NONFATAL) != 0);
                   1175:                sys("/bin/date `/etc/ATclock` >/dev/null", S_NONFATAL);
                   1176:        }
                   1177: 
                   1178:        /* DST. */
                   1179:        cls(0);
                   1180:        printf(
                   1181: "You can run COHERENT with or without conversion for daylight savings time\n"
                   1182: "(summer time).  You should normally run with daylight savings time\n"
                   1183: "conversion.  However, if you are going to use both COHERENT and MS-DOS\n"
                   1184: "and you choose to run with daylight savings time conversion,\n"
                   1185: "your time will be wrong (by one hour) during daylight savings time\n"
                   1186: "while you are running under MS-DOS.\n"
                   1187: "\n"
                   1188:                );
                   1189:        dst_conv = yes_no("Do you want COHERENT to use daylight savings time conversion");
                   1190:        if (dst_conv) {
                   1191:                printf(
                   1192: "\n"
                   1193: "By default, COHERENT assumes daylight savings time begins on the\n"
                   1194: "first Sunday in April and ends on the last Sunday in October.\n"
                   1195: "If you want to change the defaults, edit the file \"/etc/timezone\"\n"
                   1196: "after you finish installing COHERENT.\n"
                   1197: "\n"
                   1198:                        );
                   1199:                if (yes_no("Is daylight savings time currently in effect")) {
                   1200:                        /* Adjust for DST: set hardware clock back one hour. */
                   1201:                        now = time(NULL) - 60 * 60;
                   1202:                        tmp = localtime(&now);
                   1203:                        sprintf(cmd, "/etc/ATclock %02d%02d%02d%02d%02d.%02d >/dev/null",
                   1204:                                tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday,
                   1205:                                tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
                   1206:                        sys(cmd, S_NONFATAL);
                   1207:                }
                   1208:        }
                   1209: 
                   1210:        /* Timezone. */
                   1211:        cls(0);
                   1212:        printf(
                   1213: "Please choose one of the following timezones:\n"
                   1214: "\t0\tCentral European\n"
                   1215: "\t1\tGreenwich\n"
                   1216: "\t2\tNewfoundland\n"
                   1217: "\t3\tAtlantic\n"
                   1218: "\t4\tEastern\n"
                   1219: "\t5\tCentral\n"
                   1220: "\t6\tMountain\n"
                   1221: "\t7\tPacific\n"
                   1222: "\t8\tYukon\n"
                   1223: "\t9\tAlaska\n"
                   1224: "\t10\tBering\n"
                   1225: "\t11\tHawaii\n"
                   1226: "\t12\tOther\n"
                   1227:                );
                   1228:        do {
                   1229:                s = get_line("Timezone code:");
                   1230:        } while ((n = atoi(s)) < 0 || n > 12);
                   1231:        switch (n) {
                   1232:        /* N.B. entries truncated at tz[8] below if !dst_conv. */
                   1233:        case 0:         tz = "EST:-60:EDT:1.1.4";       break;
                   1234:        case 1:         tz = "GMT:000:GDT:1.1.4";       break;
                   1235:        case 2:         tz = "NST:210:NDT:1.1.4";       break;
                   1236:        case 3:         tz = "AST:240:ADT:1.1.4";       break;
                   1237:        case 4:         tz = "EST:300:EDT:1.1.4";       break;
                   1238:        case 5:         tz = "CST:360:CDT:1.1.4";       break;
                   1239:        case 6:         tz = "MST:420:MDT:1.1.4";       break;
                   1240:        case 7:         tz = "PST:480:PDT:1.1.4";       break;
                   1241:        case 8:         tz = "YST:540:YDT:1.1.4";       break;
                   1242:        case 9:         tz = "AST:600:ADT:1.1.4";       break;
                   1243:        case 10:        tz = "BST:660:BDT:1.1.4";       break;
                   1244:        case 11:        tz = "HST:600:HDT:1.1.4";       break;
                   1245:        case 12:        tz = NULL;                      break;
                   1246:        }
                   1247: 
                   1248:        if (tz == NULL)
                   1249:                get_timezone(dst_conv);
                   1250:        else {
                   1251:                strcpy(tzone, tz);
                   1252:                if (!dst_conv)
                   1253:                        tzone[8] = '\0';
                   1254:        }
                   1255: 
                   1256:        /* Done, print current time and retry if user botched it. */
                   1257:        printf("\nYour current local date and time are now:\n");
                   1258:        sprintf(cmd, "TIMEZONE='%s' /bin/date -s `/etc/ATclock`", tzone);
                   1259:        sys(cmd, S_NONFATAL);
                   1260: #endif /* new set_date */
                   1261:        if (!yes_no("Is this correct"))
                   1262:                goto again;
                   1263: }
                   1264: 
                   1265: /*
                   1266:  * Configure user devices.
                   1267:  * Assumes hard disk filesystem mounted on /mnt.
                   1268:  * Write lines to /etc/mount.all, /etc/umount.all to [u]mount the user devices.
                   1269:  */
                   1270: void
                   1271: user_devices()
                   1272: {
                   1273:        register int i, status;
                   1274:        register char *s, *s2, *name, *rname;
                   1275: 
                   1276:        if (ncohdev == 1) {
                   1277:                sys("/bin/echo /dev/root >>/mnt/etc/checklist", S_NONFATAL);
                   1278:                return;
                   1279:        }
                   1280: 
                   1281:        /* Create user device names. */
                   1282:        cls(0);
                   1283:        printf(
                   1284: "Your system includes %d partition%s in addition to the root partition.\n"
                   1285: "These partitions are usually mounted on directories in the COHERENT\n"
                   1286: "root filesystem when the system goes into multiuser mode.\n"
                   1287: "For example, one non-root partition might be mounted on\n"
                   1288: "directory \"/u\", another on \"/v\", and so on.\n"
                   1289: "You now may specify where you want each partition mounted.\n",
                   1290:                ncohdev - 1, ncohdev == 2 ? "" : "s");
                   1291:        for (i = 0; i < ndevices; i++) {
                   1292:                if (notflag(i, F_COH) || notflag(i, F_FS) || isflag(i, F_ROOT))
                   1293:                        continue;
                   1294:                name = devname(i, 0);
                   1295:                rname = rawname(i, 0);
                   1296:                printf("\nPartition %d (%s):\n", i, name);
                   1297:                if (yes_no("Do you want %s mounted", name)) {
                   1298:                        setflag(i, F_MOUNT);
                   1299: again:
                   1300:                        s = get_line("Where do you want to mount it?");
                   1301:                        if (*s != '/') {
                   1302:                                printf("Type a directory name beginning with '/', such as \"/u\".\n");
                   1303:                                goto again;
                   1304:                        } else if ((s2 = strchr(s, ' ')) != NULL)
                   1305:                                *s2 = '\0';
                   1306:                        sprintf(cmd, "/mnt/%s", s);
                   1307:                        if ((status = is_dir(cmd)) == -1) {
                   1308:                                printf("%s exists but is not a directory.\n", s);
                   1309:                                goto again;
                   1310:                        } else if (status == 1) {
                   1311:                                strcpy(buf2, s);
                   1312:                                printf("Directory %s already exists.\n", s);
                   1313:                                if (!yes_no("Are you sure you want %s mounted on %s", name, s))
                   1314:                                        goto again;
                   1315:                                s = buf;
                   1316:                                strcpy(s, buf2);
                   1317:                        } else {
                   1318:                                /* Make the target directory, uid=bin, gid=bin. */
                   1319:                                sprintf(cmd, "/bin/mkdir -r /mnt%s", s);
                   1320:                                if (sys(cmd, S_NONFATAL))
                   1321:                                        goto again;
                   1322:                                sprintf(cmd, "/bin/chown bin /mnt%s", s);
                   1323:                                sys(cmd, S_NONFATAL);
                   1324:                                sprintf(cmd, "/bin/chgrp bin /mnt%s", s);
                   1325:                                sys(cmd, S_NONFATAL);
                   1326:                        }
                   1327:                        printf("%s will be mounted on %s when COHERENT goes multiuser.\n",
                   1328:                                name, s);
                   1329: 
                   1330:                        /* Change e.g. /usr/src to usr_src. */
                   1331:                        strcpy(buf2, &s[1]);
                   1332:                        while ((s2 = strchr(buf2, '/')) != NULL)
                   1333:                                *s2 = '_';
                   1334: 
                   1335:                        /* Make link to pseudo-device, e.g. "/dev/usr_src". */
                   1336:                        sprintf(cmd, "/mnt/dev/%s", buf2);
                   1337:                        if (exists(cmd))
                   1338:                                status = 1;             /* use normal name */
                   1339:                        else {
                   1340:                                sprintf(cmd, "/bin/ln -f /mnt%s /mnt/dev/%s",
                   1341:                                        name, buf2);
                   1342:                                if ((status = sys(cmd, S_NONFATAL)) == 0)
                   1343:                                        printf(
                   1344: "/dev/%s is linked to %s to provide a mnemonic device name.\n",
                   1345:                                                buf2, name);
                   1346:                        }
                   1347: 
                   1348:                        /* Add lines to /etc/mount.all, /etc/umount.all. */
                   1349:                        if (status == 0)
                   1350:                                sprintf(cmd, "/bin/echo /etc/mount /dev/%s %s >>/mnt/etc/mount.all",
                   1351:                                        buf2, s);
                   1352:                        else
                   1353:                                sprintf(cmd, "/bin/echo /etc/mount %s %s >>/mnt/etc/mount.all",
                   1354:                                        name, s);
                   1355:                        sys(cmd, S_NONFATAL);
                   1356:                        if (status == 0)
                   1357:                                sprintf(cmd, "/bin/echo /etc/umount /dev/%s >>/mnt/etc/umount.all",
                   1358:                                        buf2);
                   1359:                        else
                   1360:                                sprintf(cmd, "/bin/echo /etc/umount %s >>/mnt/etc/umount.all",
                   1361:                                        name);
                   1362:                        sys(cmd, S_NONFATAL);
                   1363: 
                   1364:                        /* And again, for the raw device. */
                   1365:                        sprintf(cmd, "/mnt/dev/r%s", buf2);
                   1366:                        if (exists(cmd))
                   1367:                                status = 1;
                   1368:                        else {
                   1369:                                sprintf(cmd, "/bin/ln -f /mnt%s /mnt/dev/r%s",
                   1370:                                        rname, buf2);
                   1371:                                if ((status = sys(cmd, S_NONFATAL)) == 0)
                   1372:                                        printf(
                   1373: "/dev/r%s is linked to %s to provide a mnemonic device name.\n",
                   1374:                                                buf2, rname);
                   1375:                        }
                   1376: 
                   1377:                        /* Add raw device line to /etc/checklist. */
                   1378:                        if (status == 0)
                   1379:                                sprintf(cmd, "/bin/echo /dev/r%s >>/mnt/etc/checklist",
                   1380:                                        buf2);
                   1381:                        else
                   1382:                                sprintf(cmd, "/bin/echo %s >>/mnt/etc/checklist",
                   1383:                                        rname);
                   1384:                        sys(cmd, S_NONFATAL);
                   1385:                } else {
                   1386:                        /* Not mounted, check using standard name. */
                   1387:                        sprintf(cmd, "/bin/echo %s >>/mnt/etc/checklist", rname);
                   1388:                        sys(cmd, S_NONFATAL);
                   1389:                }
                   1390:        }
                   1391:        sys("/bin/echo /dev/root >>/mnt/etc/checklist", S_NONFATAL);
                   1392: 
                   1393:        /* Link /dev/dos if desired. */
                   1394:        if (yes_no("Do you use both COHERENT and MS-DOS on your hard disk")) {
                   1395:                i = get_int(0, ndevices-1, "Enter the partition number of your MS-DOS partition:");
                   1396:                sprintf(cmd, "/bin/ln -f /mnt%s /mnt/dev/dos", devname(i, 0));
                   1397:                if (sys(cmd, S_NONFATAL) == 0)
                   1398:                        printf(
                   1399: "Device name /dev/dos is now linked to %s for use as a mnemonic\n"
                   1400: "device name.  You may use the \"dos*\" family of commands to transfer files\n"
                   1401: "to and from the MS-DOS partition on your hard disk as well as MS-DOS floppies.\n",
                   1402:                                devname(i, 0));
                   1403:                printf("\n");
                   1404:        }
                   1405: }
                   1406: 
                   1407: 
                   1408: /*
                   1409:  * Set up site/machine specific info in files /etc/uucpname and /etc/domain
                   1410:  */
                   1411: void
                   1412: uucp()
                   1413: {
                   1414:        unsigned char *cp;
                   1415: 
                   1416:        cls(1);
                   1417:        printf(
                   1418: "In order to use COHERENT's electronic mail facility and UUCP subsystem,\n"
                   1419: "you must choose a \"site name\" for your computer system.  In general, a site\n"
                   1420: "name consists of lower case letters or digits and should be at most seven\n"
                   1421: "characters in length.  The name you choose should be unique if you intend\n"
                   1422: "to access any other computer systems.  Some of the more well known site\n"
                   1423: "names include \"mwc\", \"uunet\", \"clout\", \"decwrl\", \"hp\", \"kgbvax\", "
                   1424: "\"prep\",\n\"seismo\", and \"ucbvax\".\n\n"
                   1425:        );
                   1426:        for (;;) {
                   1427:                cp = get_line("Please enter the site name for this system: ");
                   1428:                if (ok_name(cp, 'u'))
                   1429:                        break;
                   1430:        }
                   1431:        sprintf(cmd, "/bin/echo \"%s\" >/mnt/etc/uucpname", cp);
                   1432:        sys(cmd, S_NONFATAL);
                   1433: 
                   1434:        printf(
                   1435: "\nThe COHERENT mail subsystem supports \"domain addressing\" in addition to\n"
                   1436: "traditional \"bang paths\".  Until your system becomes part of a registered\n"
                   1437: "domain, you may use the UUCP pseudo-domain.  Domain names consist of groups\n"
                   1438: "of letters and digits separated by periods (dots).  Some of the more well\n"
                   1439: "known domains include \"com\", \"edu\", \"gov\", \"org\", \"net\", as well as domains\n"
                   1440: "covering a geographical area, such as the Chicago area \"chi.il.us\" domain.\n"
                   1441: "If you are not registered in a domain, or if you are uncertain about this\n"
                   1442: "question, simply press the <Enter> key to default to the UUCP pseudo-domain.\n\n"
                   1443:        );
                   1444:        for (;;) {
                   1445:                cp = get_line("Please enter the domain name for this system: ");
                   1446:                if (ok_name(cp, 'd'))
                   1447:                        break;
                   1448:        }
                   1449:        sprintf(cmd, "/bin/echo \"%s\" >/mnt/etc/domain", cp);
                   1450:        sys(cmd, S_NONFATAL);
                   1451: }
                   1452: 
                   1453: /*
                   1454:  * Hi there.
                   1455:  */
                   1456: void
                   1457: welcome()
                   1458: {
                   1459:        register char *s;
                   1460:        int i;
                   1461: 
                   1462:        cls(0);
                   1463:        printf(
                   1464: "\n\n\n\n\n\n\n\n"
                   1465: "                              The COHERENT System\n\n"
                   1466: "                    (c) 1982, 1992 by Mark Williams Company\n\n"
                   1467: "                     60 Revere Drive, Northbrook, IL  60062\n\n"
                   1468: "                        708-291-6700, 708-291-6750 (FAX)\n"
                   1469: "\n\n\n\n\n\n"
                   1470:                );
                   1471: 
                   1472:        cls(1);
                   1473:        printf(
                   1474: "Welcome to the COHERENT operating system!\n\n"
                   1475: "Your computer is now running COHERENT from the floppy disk.\n"
                   1476: "This program will install COHERENT onto your hard disk.\n"
                   1477: "\n"
                   1478: "You can interrupt installation at any time by typing <Ctrl-C>;\n"
                   1479: "then reboot and start the installation procedure again.\n"
                   1480: "Please be patient and read the instructions on the screen carefully.\n"
                   1481: "\n"
                   1482:                );
                   1483: #if 0
                   1484:        cls(1);
                   1485:        printf(
                   1486: "If you do not know the BIOS parameters for your hard disk drive,\n"
                   1487: "please reset your computer NOW and enter \"dpb\" at the boot prompt.\n"
                   1488: "Copy the displayed parameter values for later reference, then reset\n"
                   1489: "again and restart installation by entering \"begin\" at the boot prompt.\n"
                   1490:                );
                   1491: #endif
                   1492:        cls(1);
                   1493:        sys("/etc/kbdinstall -b", S_NONFATAL);
                   1494: 
                   1495:        cls(1);
                   1496:        printf(
                   1497: "A card included with your distribution gives the serial number\n"
                   1498: "of your copy of COHERENT.\n"
                   1499:                );
                   1500:        for (i = 1; i <= 3; i++) {
                   1501:                s = get_line("Type in the serial number from the card:");
                   1502:                if (isserial(s))
                   1503:                        return;
                   1504:                printf("Invalid serial number, please try again.\n");
                   1505:        }
                   1506:        fatal("invalid serial number");
                   1507: }
                   1508: 
                   1509: /*
                   1510:  * Generate a partition table device name from a DEVICE entry name.
                   1511:  * Return a pointer to the statically allocated name.
                   1512:  * If flag and not one of the built-in AT device names,
                   1513:  * the device is in /tmp/dev rather than /dev.
                   1514:  */
                   1515: char *
                   1516: xname(i, flag) int i, flag;
                   1517: {
                   1518:        static char xname[4+4+1+NAMESIZE];      /* e.g. "/tmp/dev/at0x" */
                   1519: 
                   1520:        sprintf(xname, "/tmp/dev/%s", devices[i].d_xname);
                   1521:        return (flag && notflag(i,  F_ATDEV)) ? xname : xname+4;
                   1522: }
                   1523: 
                   1524: /* end of build.c */

unix.superglobalmegacorp.com

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