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