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