writeisofs: also boots plain binaries with -B
With -n -b file, a.out boot images can be used for CD booting; with the new -n -B file option, plain binary (like bootxx_cd9660) can be used instead. Restore working the -h and -f options while there. And add a new -F option for 2.8MB floppy image.
This commit is contained in:
parent
2ae897db7b
commit
3f2ab5b34b
1 changed files with 39 additions and 9 deletions
|
@ -115,9 +115,9 @@ struct bc_validation {
|
||||||
|
|
||||||
#define BOOTMEDIA_UNSPECIFIED -1
|
#define BOOTMEDIA_UNSPECIFIED -1
|
||||||
#define BOOTMEDIA_NONE 0
|
#define BOOTMEDIA_NONE 0
|
||||||
#define BOOTMEDIA_120M 1
|
#define BOOTMEDIA_1200K 1
|
||||||
#define BOOTMEDIA_144M 2
|
#define BOOTMEDIA_1440K 2
|
||||||
#define BOOTMEDIA_288M 3
|
#define BOOTMEDIA_2880K 3
|
||||||
#define BOOTMEDIA_HARDDISK 4
|
#define BOOTMEDIA_HARDDISK 4
|
||||||
|
|
||||||
struct bc_initial {
|
struct bc_initial {
|
||||||
|
@ -170,6 +170,7 @@ int n_reserved_pathtableentries = 0, n_used_pathtableentries = 0;
|
||||||
int bootmedia = BOOTMEDIA_UNSPECIFIED;
|
int bootmedia = BOOTMEDIA_UNSPECIFIED;
|
||||||
unsigned long bootseg = 0;
|
unsigned long bootseg = 0;
|
||||||
int system_type = 0;
|
int system_type = 0;
|
||||||
|
int bootimage_is_aout = 0;
|
||||||
|
|
||||||
int get_system_type(int fd);
|
int get_system_type(int fd);
|
||||||
|
|
||||||
|
@ -785,13 +786,21 @@ writebootimage(char *bootimage, int bootfd, int fd, int *currentsector,
|
||||||
ssize_t written = 0, rest;
|
ssize_t written = 0, rest;
|
||||||
int virtuals, rem;
|
int virtuals, rem;
|
||||||
struct exec hdr;
|
struct exec hdr;
|
||||||
|
struct stat sb;
|
||||||
struct bap {
|
struct bap {
|
||||||
off_t sector;
|
off_t sector;
|
||||||
int length;
|
int length;
|
||||||
} bap[2];
|
} bap[2];
|
||||||
|
|
||||||
|
bap[0].length = bap[0].sector = 0;
|
||||||
bap[1].length = bap[1].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);
|
Read(bootfd, &hdr, A_MINHDR);
|
||||||
|
|
||||||
if(hdr.a_magic[0] != A_MAGIC0) {
|
if(hdr.a_magic[0] != A_MAGIC0) {
|
||||||
|
@ -809,11 +818,26 @@ writebootimage(char *bootimage, int bootfd, int fd, int *currentsector,
|
||||||
|
|
||||||
/* copy text+data */
|
/* copy text+data */
|
||||||
rem = hdr.a_text + hdr.a_data;
|
rem = hdr.a_text + hdr.a_data;
|
||||||
|
} else
|
||||||
|
rem = sb.st_size;
|
||||||
|
|
||||||
while(rem > 0) {
|
while(rem > 0) {
|
||||||
int want;
|
int want;
|
||||||
want = rem < sizeof(buf) ? rem : sizeof(buf);
|
want = rem < sizeof(buf) ? rem : sizeof(buf);
|
||||||
Read(bootfd, buf, want);
|
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);
|
written += Write(fd, buf, want);
|
||||||
rem -= want;
|
rem -= want;
|
||||||
}
|
}
|
||||||
|
@ -833,7 +857,7 @@ writebootimage(char *bootimage, int bootfd, int fd, int *currentsector,
|
||||||
exit(1);
|
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);
|
bap[0].sector, bap[0].length);
|
||||||
|
|
||||||
addr = buf;
|
addr = buf;
|
||||||
|
@ -931,7 +955,7 @@ main(int argc, char *argv[])
|
||||||
return 1;
|
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) {
|
switch(ch) {
|
||||||
case 's':
|
case 's':
|
||||||
if(optarg[0] != '0' || optarg[1] != 'x') {
|
if(optarg[0] != '0' || optarg[1] != 'x') {
|
||||||
|
@ -948,7 +972,10 @@ main(int argc, char *argv[])
|
||||||
bootmedia= BOOTMEDIA_NONE;
|
bootmedia= BOOTMEDIA_NONE;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
bootmedia= BOOTMEDIA_144M;
|
bootmedia= BOOTMEDIA_1440K;
|
||||||
|
break;
|
||||||
|
case 'F':
|
||||||
|
bootmedia= BOOTMEDIA_2880K;
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
if(!(appendsectorinfo = strdup(optarg)))
|
if(!(appendsectorinfo = strdup(optarg)))
|
||||||
|
@ -957,10 +984,13 @@ main(int argc, char *argv[])
|
||||||
case 'l':
|
case 'l':
|
||||||
label = optarg;
|
label = optarg;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'R':
|
||||||
remove_after = 1;
|
remove_after = 1;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
|
bootimage_is_aout= 1;
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
case 'B':
|
||||||
bootimage = optarg;
|
bootimage = optarg;
|
||||||
if((bootfd = open(bootimage, O_RDONLY)) < 0) {
|
if((bootfd = open(bootimage, O_RDONLY)) < 0) {
|
||||||
perror(bootimage);
|
perror(bootimage);
|
||||||
|
@ -976,7 +1006,7 @@ main(int argc, char *argv[])
|
||||||
/* Args check */
|
/* Args check */
|
||||||
|
|
||||||
if(argc != 2) {
|
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);
|
prog);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1175,8 +1205,8 @@ main(int argc, char *argv[])
|
||||||
writebootimage(bootimage, bootfd,
|
writebootimage(bootimage, bootfd,
|
||||||
fd, ¤tsector, appendsectorinfo, &root);
|
fd, ¤tsector, appendsectorinfo, &root);
|
||||||
|
|
||||||
close(bootfd);
|
|
||||||
}
|
}
|
||||||
|
close(bootfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, " * all ok\n");
|
fprintf(stderr, " * all ok\n");
|
||||||
|
|
Loading…
Reference in a new issue