* Copyright (c) 1990 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* @(#)mkboot.c 7.2 (Berkeley) 12/16/90
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)mkboot.c 7.2 (Berkeley) 12/16/90";
#include "../include/param.h"
char *n1
, *n2
, *lifname();
if (!strcmp(av
[0], "-l")) {
sscanf(av
[0], "0x%x", &loadpoint
);
from1
= open(av
[0], O_RDONLY
, 0);
from2
= open(av
[0], O_RDONLY
, 0);
to
= open(av
[0], O_WRONLY
| O_TRUNC
| O_CREAT
, 0644);
/* clear possibly unused directory entries */
strncpy(lifd
[1].dir_name
, " ", 10);
lifd
[7] = lifd
[6] = lifd
[5] = lifd
[4] = lifd
[3] = lifd
[2] = lifd
[1];
strncpy(lifv
.vol_label
, "BOOT43", 6);
/* output bootfile one */
lseek(to
, 3 * SECTSIZE
, 0);
n
= (ld
.count
+ sizeof(ld
) + (SECTSIZE
- 1)) / SECTSIZE
;
strcpy(lifd
[0].dir_name
, lifname(n1
));
lifd
[0].dir_type
= DIR_TYPE
;
lifd
[0].dir_flag
= DIR_FLAG
;
lifd
[0].dir_exec
= lpflag
? loadpoint
+ ex
.a_entry
: ex
.a_entry
;
lifv
.vol_length
= lifd
[0].dir_addr
+ lifd
[0].dir_length
;
/* if there is an optional second boot program, output it */
lseek(to
, (3 + n
) * SECTSIZE
, 0);
n
= (ld
.count
+ sizeof(ld
) + (SECTSIZE
- 1)) / SECTSIZE
;
strcpy(lifd
[1].dir_name
, lifname(n2
));
lifd
[1].dir_type
= DIR_TYPE
;
lifd
[1].dir_addr
= 3 + lifd
[0].dir_length
;
lifd
[1].dir_flag
= DIR_FLAG
;
lifd
[1].dir_exec
= lpflag
? loadpoint
+ ex
.a_entry
: ex
.a_entry
;
lifv
.vol_length
= lifd
[1].dir_addr
+ lifd
[1].dir_length
;
/* output volume/directory header info */
lseek(to
, 0 * SECTSIZE
, 0);
write(to
, &lifv
, sizeof(lifv
));
lseek(to
, 2 * SECTSIZE
, 0);
write(to
, lifd
, sizeof(lifd
));
register int n
, tcnt
, dcnt
;
n
= read(from
, &ex
, sizeof(ex
));
fprintf(stderr
, "error reading file header\n");
if (ex
.a_magic
== OMAGIC
) {
else if (ex
.a_magic
== NMAGIC
) {
tcnt
= (ex
.a_text
+ PGOFSET
) & ~PGOFSET
;
fprintf(stderr
, "bad magic number\n");
ld
.address
= lpflag
? loadpoint
: ex
.a_entry
;
write(to
, &ld
, sizeof(ld
));
fprintf(stderr
, "short read\n");
if (write(to
, buf
, n
) < 0) {
fprintf(stderr
, "short read\n");
if (write(to
, buf
, n
) < 0) {
"usage: mkboot [-l loadpoint] prog1 [ prog2 ] outfile\n");
static char lname
[10] = "SYS_XXXXX";
for (i
= 4; i
< 9; i
++) {
lname
[i
] = toupper(*str
);
else if (isalnum(*str
) || *str
== '_')