Annotation of 43BSDReno/sys/hpstand/mkboot.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1990 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution is only permitted until one year after the first shipment
        !             6:  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
        !             7:  * binary forms are permitted provided that: (1) source distributions retain
        !             8:  * this entire copyright notice and comment, and (2) distributions including
        !             9:  * binaries display the following acknowledgement:  This product includes
        !            10:  * software developed by the University of California, Berkeley and its
        !            11:  * contributors'' in the documentation or other materials provided with the
        !            12:  * distribution and in all advertising materials mentioning features or use
        !            13:  * of this software.  Neither the name of the University nor the names of
        !            14:  * its contributors may be used to endorse or promote products derived from
        !            15:  * this software without specific prior written permission.
        !            16:  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            17:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            18:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            19:  *
        !            20:  *     @(#)mkboot.c    7.1 (Berkeley) 5/8/90
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: char copyright[] =
        !            25: "@(#) Copyright (c) 1990 The Regents of the University of California.\n\
        !            26:  All rights reserved.\n";
        !            27: #endif /* not lint */
        !            28: 
        !            29: #ifndef lint
        !            30: static char sccsid[] = "@(#)mkboot.c   7.1 (Berkeley) 5/8/90";
        !            31: #endif /* not lint */
        !            32: 
        !            33: #include "machine/machparam.h"
        !            34: #include "volhdr.h"
        !            35: #include <sys/exec.h>
        !            36: #include <sys/file.h>
        !            37: #include <stdio.h>
        !            38: #include <ctype.h>
        !            39: 
        !            40: int lpflag;
        !            41: int loadpoint;
        !            42: struct load ld;
        !            43: struct lifvol lifv;
        !            44: struct lifdir lifd[8];
        !            45: struct exec ex;
        !            46: char buf[10240];
        !            47: 
        !            48: main(argc, argv)
        !            49:        char **argv;
        !            50: {
        !            51:        int ac;
        !            52:        char **av;
        !            53:        int from1, from2, to;
        !            54:        register int n;
        !            55:        char *n1, *n2, *lifname();
        !            56: 
        !            57:        ac = --argc;
        !            58:        av = ++argv;
        !            59:        if (ac == 0)
        !            60:                usage();
        !            61:        if (!strcmp(av[0], "-l")) {
        !            62:                av++;
        !            63:                ac--;
        !            64:                if (ac == 0)
        !            65:                        usage();
        !            66:                sscanf(av[0], "0x%x", &loadpoint);
        !            67:                lpflag++;
        !            68:                av++;
        !            69:                ac--;
        !            70:        }
        !            71:        if (ac == 0)
        !            72:                usage();
        !            73:        from1 = open(av[0], O_RDONLY, 0);
        !            74:        if (from1 < 0) {
        !            75:                perror("open");
        !            76:                exit(1);
        !            77:        }
        !            78:        n1 = av[0];
        !            79:        av++;
        !            80:        ac--;
        !            81:        if (ac == 0)
        !            82:                usage();
        !            83:        if (ac == 2) {
        !            84:                from2 = open(av[0], O_RDONLY, 0);
        !            85:                if (from2 < 0) {
        !            86:                        perror("open");
        !            87:                        exit(1);
        !            88:                }
        !            89:                n2 = av[0];
        !            90:                av++;
        !            91:                ac--;
        !            92:        } else
        !            93:                from2 = -1;
        !            94:        to = open(av[0], O_WRONLY | O_TRUNC | O_CREAT, 0644);
        !            95:        if (to < 0) {
        !            96:                perror("open");
        !            97:                exit(1);
        !            98:        }
        !            99:        /* clear possibly unused directory entries */
        !           100:        strncpy(lifd[1].dir_name, "          ", 10);
        !           101:        lifd[1].dir_type = -1;
        !           102:        lifd[1].dir_addr = 0;
        !           103:        lifd[1].dir_length = 0;
        !           104:        lifd[1].dir_flag = 0xFF;
        !           105:        lifd[1].dir_exec = 0;
        !           106:        lifd[7] = lifd[6] = lifd[5] = lifd[4] = lifd[3] = lifd[2] = lifd[1];
        !           107:        /* record volume info */
        !           108:        lifv.vol_id = VOL_ID;
        !           109:        strncpy(lifv.vol_label, "BOOT43", 6);
        !           110:        lifv.vol_addr = 2;
        !           111:        lifv.vol_oct = VOL_OCT;
        !           112:        lifv.vol_dirsize = 1;
        !           113:        lifv.vol_version = 1;
        !           114:        /* output bootfile one */
        !           115:        lseek(to, 3 * SECTSIZE, 0);
        !           116:        putfile(from1, to);
        !           117:        n = (ld.count + sizeof(ld) + (SECTSIZE - 1)) / SECTSIZE;
        !           118:        strcpy(lifd[0].dir_name, lifname(n1));
        !           119:        lifd[0].dir_type = DIR_TYPE;
        !           120:        lifd[0].dir_addr = 3;
        !           121:        lifd[0].dir_length = n;
        !           122:        lifd[0].dir_flag = DIR_FLAG;
        !           123:        lifd[0].dir_exec = lpflag? loadpoint + ex.a_entry : ex.a_entry;
        !           124:        lifv.vol_length = lifd[0].dir_addr + lifd[0].dir_length;
        !           125:        /* if there is an optional second boot program, output it */
        !           126:        if (from2 >= 0) {
        !           127:                lseek(to, (3 + n) * SECTSIZE, 0);
        !           128:                putfile(from2, to);
        !           129:                n = (ld.count + sizeof(ld) + (SECTSIZE - 1)) / SECTSIZE;
        !           130:                strcpy(lifd[1].dir_name, lifname(n2));
        !           131:                lifd[1].dir_type = DIR_TYPE;
        !           132:                lifd[1].dir_addr = 3 + lifd[0].dir_length;
        !           133:                lifd[1].dir_length = n;
        !           134:                lifd[1].dir_flag = DIR_FLAG;
        !           135:                lifd[1].dir_exec = lpflag? loadpoint + ex.a_entry : ex.a_entry;
        !           136:                lifv.vol_length = lifd[1].dir_addr + lifd[1].dir_length;
        !           137:        }
        !           138:        /* output volume/directory header info */
        !           139:        lseek(to, 0 * SECTSIZE, 0);
        !           140:        write(to, &lifv, sizeof(lifv));
        !           141:        lseek(to, 2 * SECTSIZE, 0);
        !           142:        write(to, lifd, sizeof(lifd));
        !           143:        exit(0);
        !           144: }
        !           145: 
        !           146: putfile(from, to)
        !           147: {
        !           148:        register int n, tcnt, dcnt;
        !           149: 
        !           150:        n = read(from, &ex, sizeof(ex));
        !           151:        if (n != sizeof(ex)) {
        !           152:                fprintf(stderr, "error reading file header\n");
        !           153:                exit(1);
        !           154:        }
        !           155:        if (ex.a_magic == OMAGIC) {
        !           156:                tcnt = ex.a_text;
        !           157:                dcnt = ex.a_data;
        !           158:        }
        !           159:        else if (ex.a_magic == NMAGIC) {
        !           160:                tcnt = (ex.a_text + PGOFSET) & ~PGOFSET;
        !           161:                dcnt = ex.a_data;
        !           162:        }
        !           163:        else {
        !           164:                fprintf(stderr, "bad magic number\n");
        !           165:                exit(1);
        !           166:        }
        !           167:        ld.address = lpflag ? loadpoint : ex.a_entry;
        !           168:        ld.count = tcnt + dcnt;
        !           169:        write(to, &ld, sizeof(ld));
        !           170:        while (tcnt) {
        !           171:                n = sizeof(buf);
        !           172:                if (n > tcnt)
        !           173:                        n = tcnt;
        !           174:                n = read(from, buf, n);
        !           175:                if (n < 0) {
        !           176:                        perror("read");
        !           177:                        exit(1);
        !           178:                }
        !           179:                if (n == 0) {
        !           180:                        fprintf(stderr, "short read\n");
        !           181:                        exit(1);
        !           182:                }
        !           183:                if (write(to, buf, n) < 0) {
        !           184:                        perror("write");
        !           185:                        exit(1);
        !           186:                }
        !           187:                tcnt -= n;
        !           188:        }
        !           189:        while (dcnt) {
        !           190:                n = sizeof(buf);
        !           191:                if (n > dcnt)
        !           192:                        n = dcnt;
        !           193:                n = read(from, buf, n);
        !           194:                if (n < 0) {
        !           195:                        perror("read");
        !           196:                        exit(1);
        !           197:                }
        !           198:                if (n == 0) {
        !           199:                        fprintf(stderr, "short read\n");
        !           200:                        exit(1);
        !           201:                }
        !           202:                if (write(to, buf, n) < 0) {
        !           203:                        perror("write");
        !           204:                        exit(1);
        !           205:                }
        !           206:                dcnt -= n;
        !           207:        }
        !           208: }
        !           209: 
        !           210: usage()
        !           211: {
        !           212:        fprintf(stderr,
        !           213:                "usage:  mkboot [-l loadpoint] prog1 [ prog2 ] outfile\n");
        !           214:        exit(1);
        !           215: }
        !           216: 
        !           217: char *
        !           218: lifname(str)
        !           219:  char *str;
        !           220: {
        !           221:        static char lname[10] = "SYS_XXXXX";
        !           222:        register int i;
        !           223: 
        !           224:        for (i = 4; i < 9; i++) {
        !           225:                if (islower(*str))
        !           226:                        lname[i] = toupper(*str);
        !           227:                else if (isalnum(*str) || *str == '_')
        !           228:                        lname[i] = *str;
        !           229:                else
        !           230:                        break;
        !           231:                str++;
        !           232:        }
        !           233:        for ( ; i < 10; i++)
        !           234:                lname[i] = '\0';
        !           235:        return(lname);
        !           236: }

unix.superglobalmegacorp.com

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