#define BOOTMEDIA_UNSPECIFIED -1
#define BOOTMEDIA_NONE 0
-#define BOOTMEDIA_120M 1
-#define BOOTMEDIA_144M 2
-#define BOOTMEDIA_288M 3
+#define BOOTMEDIA_1200K 1
+#define BOOTMEDIA_1440K 2
+#define BOOTMEDIA_2880K 3
#define BOOTMEDIA_HARDDISK 4
struct bc_initial {
int bootmedia = BOOTMEDIA_UNSPECIFIED;
unsigned long bootseg = 0;
int system_type = 0;
+int bootimage_is_aout = 0;
int get_system_type(int fd);
ssize_t written = 0, rest;
int virtuals, rem;
struct exec hdr;
+ struct stat sb;
struct bap {
off_t sector;
int length;
} bap[2];
+ bap[0].length = bap[0].sector = 0;
bap[1].length = bap[1].sector = 0;
+ if (fstat(bootfd, &sb) < 0) {
+ perror("stat boot image");
+ exit(1);
+ }
+
+ if (bootimage_is_aout) {
Read(bootfd, &hdr, A_MINHDR);
if(hdr.a_magic[0] != A_MAGIC0) {
/* copy text+data */
rem = hdr.a_text + hdr.a_data;
+ } else
+ rem = sb.st_size;
while(rem > 0) {
int want;
want = rem < sizeof(buf) ? rem : sizeof(buf);
Read(bootfd, buf, want);
+ if (written == 0) {
+ /* check some properties at beginning. */
+ if (!bootimage_is_aout && buf[0] == 1 && buf[1] == 3) {
+ fprintf(stderr, "boot image %s is an a.out executable\n",
+ bootimage);
+ exit(1);
+ }
+ if (rem >= VIRTUAL_SECTOR
+ && (buf[510] != 0x55 || buf[511] != 0xaa) ) {
+ fprintf(stderr, "invalid boot sector (bad magic.)\n");
+ exit(1);
+ }
+ }
written += Write(fd, buf, want);
rem -= want;
}
exit(1);
}
- fprintf(stderr, " * appended sector info: 0x%lx len 0x%lx\n",
+ fprintf(stderr, " * appended sector info: 0x%lx len 0x%x\n",
bap[0].sector, bap[0].length);
addr = buf;
return 1;
}
- while ((ch = getopt(argc, argv, "a:b:s:Rb:hl:nf")) != -1) {
+ while ((ch = getopt(argc, argv, "a:b:B:s:Rb:hl:nfF")) != -1) {
switch(ch) {
case 's':
if(optarg[0] != '0' || optarg[1] != 'x') {
bootmedia= BOOTMEDIA_NONE;
break;
case 'f':
- bootmedia= BOOTMEDIA_144M;
+ bootmedia= BOOTMEDIA_1440K;
+ break;
+ case 'F':
+ bootmedia= BOOTMEDIA_2880K;
break;
case 'a':
if(!(appendsectorinfo = strdup(optarg)))
case 'l':
label = optarg;
break;
- case 'r':
+ case 'R':
remove_after = 1;
break;
case 'b':
+ bootimage_is_aout= 1;
+ /*FALLTHROUGH*/
+ case 'B':
bootimage = optarg;
if((bootfd = open(bootimage, O_RDONLY)) < 0) {
perror(bootimage);
/* Args check */
if(argc != 2) {
- fprintf(stderr, "usage: %s [-l <label>] [-b <bootimage> [-n] [-f] [-h] [-s <bootsegment>] [ -a <appendfile> ] <dir> <isofile>\n",
+ fprintf(stderr, "usage: %s [-l <label>] [-(b|B) <bootimage> [-n|-f|-F|-h] [-s <bootsegment>] [ -a <appendfile> ] <dir> <isofile>\n",
prog);
return 1;
}
writebootimage(bootimage, bootfd,
fd, ¤tsector, appendsectorinfo, &root);
- close(bootfd);
}
+ close(bootfd);
}
fprintf(stderr, " * all ok\n");