|
|
1.1 root 1: /*
2: * Copyright (c) 1990 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. All advertising materials mentioning features or use of this software
14: * must display the following acknowledgement:
15: * This product includes software developed by the University of
16: * California, Berkeley and its contributors.
17: * 4. Neither the name of the University nor the names of its contributors
18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: * SUCH DAMAGE.
32: *
1.1.1.2 ! root 33: * from: @(#)mkboot.c 7.2 (Berkeley) 12/16/90
! 34: * mkboot.c,v 1.2 1993/05/22 07:59:12 cgd Exp
1.1 root 35: */
36:
37: #ifndef lint
38: char copyright[] =
1.1.1.2 ! root 39: "Copyright (c) 1990 The Regents of the University of California.\n\
1.1 root 40: All rights reserved.\n";
41: #endif /* not lint */
42:
43: #ifndef lint
1.1.1.2 ! root 44: /* from: static char sccsid[] = "@(#)mkboot.c 7.2 (Berkeley) 12/16/90"; */
! 45: static char rcsid[] = "mkboot.c,v 1.2 1993/05/22 07:59:12 cgd Exp";
1.1 root 46: #endif /* not lint */
47:
48: #include "../include/param.h"
49: #include "volhdr.h"
50: #include <sys/exec.h>
51: #include <sys/file.h>
52: #include <stdio.h>
53: #include <ctype.h>
54:
55: int lpflag;
56: int loadpoint;
57: struct load ld;
58: struct lifvol lifv;
59: struct lifdir lifd[8];
60: struct exec ex;
61: char buf[10240];
62:
63: main(argc, argv)
64: char **argv;
65: {
66: int ac;
67: char **av;
68: int from1, from2, to;
69: register int n;
70: char *n1, *n2, *lifname();
71:
72: ac = --argc;
73: av = ++argv;
74: if (ac == 0)
75: usage();
76: if (!strcmp(av[0], "-l")) {
77: av++;
78: ac--;
79: if (ac == 0)
80: usage();
81: sscanf(av[0], "0x%x", &loadpoint);
82: lpflag++;
83: av++;
84: ac--;
85: }
86: if (ac == 0)
87: usage();
88: from1 = open(av[0], O_RDONLY, 0);
89: if (from1 < 0) {
90: perror("open");
91: exit(1);
92: }
93: n1 = av[0];
94: av++;
95: ac--;
96: if (ac == 0)
97: usage();
98: if (ac == 2) {
99: from2 = open(av[0], O_RDONLY, 0);
100: if (from2 < 0) {
101: perror("open");
102: exit(1);
103: }
104: n2 = av[0];
105: av++;
106: ac--;
107: } else
108: from2 = -1;
109: to = open(av[0], O_WRONLY | O_TRUNC | O_CREAT, 0644);
110: if (to < 0) {
111: perror("open");
112: exit(1);
113: }
114: /* clear possibly unused directory entries */
115: strncpy(lifd[1].dir_name, " ", 10);
116: lifd[1].dir_type = -1;
117: lifd[1].dir_addr = 0;
118: lifd[1].dir_length = 0;
119: lifd[1].dir_flag = 0xFF;
120: lifd[1].dir_exec = 0;
121: lifd[7] = lifd[6] = lifd[5] = lifd[4] = lifd[3] = lifd[2] = lifd[1];
122: /* record volume info */
123: lifv.vol_id = VOL_ID;
124: strncpy(lifv.vol_label, "BOOT43", 6);
125: lifv.vol_addr = 2;
126: lifv.vol_oct = VOL_OCT;
127: lifv.vol_dirsize = 1;
128: lifv.vol_version = 1;
129: /* output bootfile one */
130: lseek(to, 3 * SECTSIZE, 0);
131: putfile(from1, to);
132: n = (ld.count + sizeof(ld) + (SECTSIZE - 1)) / SECTSIZE;
133: strcpy(lifd[0].dir_name, lifname(n1));
134: lifd[0].dir_type = DIR_TYPE;
135: lifd[0].dir_addr = 3;
136: lifd[0].dir_length = n;
137: lifd[0].dir_flag = DIR_FLAG;
138: lifd[0].dir_exec = lpflag? loadpoint + ex.a_entry : ex.a_entry;
139: lifv.vol_length = lifd[0].dir_addr + lifd[0].dir_length;
140: /* if there is an optional second boot program, output it */
141: if (from2 >= 0) {
142: lseek(to, (3 + n) * SECTSIZE, 0);
143: putfile(from2, to);
144: n = (ld.count + sizeof(ld) + (SECTSIZE - 1)) / SECTSIZE;
145: strcpy(lifd[1].dir_name, lifname(n2));
146: lifd[1].dir_type = DIR_TYPE;
147: lifd[1].dir_addr = 3 + lifd[0].dir_length;
148: lifd[1].dir_length = n;
149: lifd[1].dir_flag = DIR_FLAG;
150: lifd[1].dir_exec = lpflag? loadpoint + ex.a_entry : ex.a_entry;
151: lifv.vol_length = lifd[1].dir_addr + lifd[1].dir_length;
152: }
153: /* output volume/directory header info */
154: lseek(to, 0 * SECTSIZE, 0);
155: write(to, &lifv, sizeof(lifv));
156: lseek(to, 2 * SECTSIZE, 0);
157: write(to, lifd, sizeof(lifd));
158: exit(0);
159: }
160:
161: putfile(from, to)
162: {
163: register int n, tcnt, dcnt;
164:
165: n = read(from, &ex, sizeof(ex));
166: if (n != sizeof(ex)) {
167: fprintf(stderr, "error reading file header\n");
168: exit(1);
169: }
170: if (ex.a_magic == OMAGIC) {
171: tcnt = ex.a_text;
172: dcnt = ex.a_data;
173: }
174: else if (ex.a_magic == NMAGIC) {
175: tcnt = (ex.a_text + PGOFSET) & ~PGOFSET;
176: dcnt = ex.a_data;
177: }
178: else {
179: fprintf(stderr, "bad magic number\n");
180: exit(1);
181: }
182: ld.address = lpflag ? loadpoint : ex.a_entry;
183: ld.count = tcnt + dcnt;
184: write(to, &ld, sizeof(ld));
185: while (tcnt) {
186: n = sizeof(buf);
187: if (n > tcnt)
188: n = tcnt;
189: n = read(from, buf, n);
190: if (n < 0) {
191: perror("read");
192: exit(1);
193: }
194: if (n == 0) {
195: fprintf(stderr, "short read\n");
196: exit(1);
197: }
198: if (write(to, buf, n) < 0) {
199: perror("write");
200: exit(1);
201: }
202: tcnt -= n;
203: }
204: while (dcnt) {
205: n = sizeof(buf);
206: if (n > dcnt)
207: n = dcnt;
208: n = read(from, buf, n);
209: if (n < 0) {
210: perror("read");
211: exit(1);
212: }
213: if (n == 0) {
214: fprintf(stderr, "short read\n");
215: exit(1);
216: }
217: if (write(to, buf, n) < 0) {
218: perror("write");
219: exit(1);
220: }
221: dcnt -= n;
222: }
223: }
224:
225: usage()
226: {
227: fprintf(stderr,
228: "usage: mkboot [-l loadpoint] prog1 [ prog2 ] outfile\n");
229: exit(1);
230: }
231:
232: char *
233: lifname(str)
234: char *str;
235: {
236: static char lname[10] = "SYS_XXXXX";
237: register int i;
238:
239: for (i = 4; i < 9; i++) {
240: if (islower(*str))
241: lname[i] = toupper(*str);
242: else if (isalnum(*str) || *str == '_')
243: lname[i] = *str;
244: else
245: break;
246: str++;
247: }
248: for ( ; i < 10; i++)
249: lname[i] = '\0';
250: return(lname);
251: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.