xref: /csrg-svn/sys/hp300/stand/installboot.c (revision 56510)
1*56510Sbostic /*-
2*56510Sbostic  * Copyright (c) 1986, 1990 The Regents of the University of California.
341488Smckusick  * All rights reserved.
441488Smckusick  *
541488Smckusick  * %sccs.include.redist.c%
641488Smckusick  */
741488Smckusick 
841488Smckusick #ifndef lint
941488Smckusick char copyright[] =
10*56510Sbostic "@(#) Copyright (c) 1986, 1990 The Regents of the University of California.\n\
1141488Smckusick  All rights reserved.\n";
1241488Smckusick #endif /* not lint */
1341488Smckusick 
1441488Smckusick #ifndef lint
15*56510Sbostic static char sccsid[] = "@(#)installboot.c	7.4 (Berkeley) 10/11/92";
1641488Smckusick #endif /* not lint */
1741488Smckusick 
18*56510Sbostic #include <sys/param.h>
19*56510Sbostic #include <ufs/ffs/fs.h>
2041488Smckusick 
2141488Smckusick char block[1024];
2241488Smckusick int maxbootsize = 16 * 7 * 512;		/* XXX */
2341488Smckusick 
2441488Smckusick /*
2541488Smckusick  * HPs are a kludge.
2641488Smckusick  * The boot program won't fit in the boot area of a file system so we
2741488Smckusick  * have to place it outside the file systems.  By convention, this means
2841488Smckusick  * that if the 'a' partition is being used for '/', it is offset one
2941488Smckusick  * cylinder into the disk and the boot program goes into that one cylinder.
3041488Smckusick  * Also by convention, the 'c' partition is defined to be the entire disk
3141488Smckusick  * including this boot cylinder.  If these conventions are not adhered to,
3241488Smckusick  * the potential for disaster is enormous.
3341488Smckusick  */
main(argc,argv)3441488Smckusick main(argc, argv)
3541488Smckusick 	int argc;
3641488Smckusick 	char *argv[];
3741488Smckusick {
3841488Smckusick 	int ifd, ofd, len;
3941488Smckusick 	char *dev, *standalonecode;
4041488Smckusick 	int bsize = 1024;
4141488Smckusick 
4241488Smckusick 	if (argc != 3)
4341488Smckusick 		usage();
4441488Smckusick 	dev = argv[2];
4541488Smckusick 	len = strlen(dev);
4641488Smckusick 	if (dev[len-1] != 'c')
4741488Smckusick 		usage();
4841488Smckusick 	standalonecode = argv[1];
4941488Smckusick 	ifd = open(standalonecode, 0);
5041488Smckusick 	if (ifd < 0) {
5141488Smckusick 		perror(standalonecode);
5241488Smckusick 		exit(1);
5341488Smckusick 	}
5441488Smckusick 	ofd = open(dev, 1);
5541488Smckusick 	if (ofd < 0) {
5641488Smckusick 		perror(dev);
5741488Smckusick 		exit(1);
5841488Smckusick 	}
5941488Smckusick 	while ((len = read(ifd, block, bsize)) > 0) {
6041488Smckusick 		if ((maxbootsize -= bsize) < 0) {
6141488Smckusick 			printf("%s: too big\n", standalonecode);
6241488Smckusick 			exit(2);
6341488Smckusick 		}
6441488Smckusick 		if (len < bsize)
6541488Smckusick 			bzero(&block[len], bsize-len);
6641488Smckusick 		if (write(ofd, block, bsize) != bsize) {
6741488Smckusick 			perror(dev);
6841488Smckusick 			exit(2);
6941488Smckusick 		}
7041488Smckusick 	}
7141488Smckusick 	if (len < 0) {
7241488Smckusick 		perror(standalonecode);
7341488Smckusick 		exit(2);
7441488Smckusick 	}
7541488Smckusick 	exit(0);
7641488Smckusick }
7741488Smckusick 
usage()7841488Smckusick usage()
7941488Smckusick {
8041488Smckusick 	printf("Usage: installboot bootprog device\n");
8141488Smckusick 	printf("where:\n");
8241488Smckusick 	printf("\t\"bootprog\" is a LIF format file < %d bytes long\n",
8341488Smckusick 	       maxbootsize);
8441488Smckusick 	printf("\t\"device\" must be the 'c' partition of a bootable disk\n");
8541488Smckusick 	printf("WARNING!!  If the 'c' partition contains a file system, %s\n",
8641488Smckusick 	       "DON'T RUN THIS!!");
8741488Smckusick 	exit(1);
8841488Smckusick }
89