1 /*- 2 * Copyright (c) 1986, 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1986, 1990 The Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)installboot.c 7.4 (Berkeley) 10/11/92"; 16 #endif /* not lint */ 17 18 #include <sys/param.h> 19 #include <ufs/ffs/fs.h> 20 21 char block[1024]; 22 int maxbootsize = 16 * 7 * 512; /* XXX */ 23 24 /* 25 * HPs are a kludge. 26 * The boot program won't fit in the boot area of a file system so we 27 * have to place it outside the file systems. By convention, this means 28 * that if the 'a' partition is being used for '/', it is offset one 29 * cylinder into the disk and the boot program goes into that one cylinder. 30 * Also by convention, the 'c' partition is defined to be the entire disk 31 * including this boot cylinder. If these conventions are not adhered to, 32 * the potential for disaster is enormous. 33 */ 34 main(argc, argv) 35 int argc; 36 char *argv[]; 37 { 38 int ifd, ofd, len; 39 char *dev, *standalonecode; 40 int bsize = 1024; 41 42 if (argc != 3) 43 usage(); 44 dev = argv[2]; 45 len = strlen(dev); 46 if (dev[len-1] != 'c') 47 usage(); 48 standalonecode = argv[1]; 49 ifd = open(standalonecode, 0); 50 if (ifd < 0) { 51 perror(standalonecode); 52 exit(1); 53 } 54 ofd = open(dev, 1); 55 if (ofd < 0) { 56 perror(dev); 57 exit(1); 58 } 59 while ((len = read(ifd, block, bsize)) > 0) { 60 if ((maxbootsize -= bsize) < 0) { 61 printf("%s: too big\n", standalonecode); 62 exit(2); 63 } 64 if (len < bsize) 65 bzero(&block[len], bsize-len); 66 if (write(ofd, block, bsize) != bsize) { 67 perror(dev); 68 exit(2); 69 } 70 } 71 if (len < 0) { 72 perror(standalonecode); 73 exit(2); 74 } 75 exit(0); 76 } 77 78 usage() 79 { 80 printf("Usage: installboot bootprog device\n"); 81 printf("where:\n"); 82 printf("\t\"bootprog\" is a LIF format file < %d bytes long\n", 83 maxbootsize); 84 printf("\t\"device\" must be the 'c' partition of a bootable disk\n"); 85 printf("WARNING!! If the 'c' partition contains a file system, %s\n", 86 "DON'T RUN THIS!!"); 87 exit(1); 88 } 89