-h option for harddisk emulation
This commit is contained in:
parent
c392c177b5
commit
cc083ade4d
1 changed files with 65 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
/* writeisofs - simple ISO9660-format-image writing utility */
|
/* writeisofs - simple ISO9660-format-image writing utility */
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -9,6 +10,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <ibm/partition.h>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
@ -158,6 +160,10 @@ struct node {
|
||||||
};
|
};
|
||||||
|
|
||||||
int n_reserved_pathtableentries = 0, n_used_pathtableentries = 0;
|
int n_reserved_pathtableentries = 0, n_used_pathtableentries = 0;
|
||||||
|
int harddisk_emulation = 0;
|
||||||
|
int system_type = 0;
|
||||||
|
|
||||||
|
int get_system_type(int fd);
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
Write(int fd, void *buf, ssize_t len)
|
Write(int fd, void *buf, ssize_t len)
|
||||||
|
@ -730,6 +736,12 @@ writebootcatalog(int fd, int *currentsector, int imagesector, int imagesectors)
|
||||||
memset(&initial, 0, sizeof(initial));
|
memset(&initial, 0, sizeof(initial));
|
||||||
|
|
||||||
initial.indicator = INDICATE_BOOTABLE;
|
initial.indicator = INDICATE_BOOTABLE;
|
||||||
|
if (harddisk_emulation)
|
||||||
|
{
|
||||||
|
initial.media = BOOTMEDIA_HARDDISK;
|
||||||
|
initial.type = system_type;
|
||||||
|
}
|
||||||
|
else
|
||||||
initial.media = BOOTMEDIA_144M;
|
initial.media = BOOTMEDIA_144M;
|
||||||
/* initial.sectors = imagesectors; */
|
/* initial.sectors = imagesectors; */
|
||||||
initial.sectors = 1;
|
initial.sectors = 1;
|
||||||
|
@ -845,8 +857,11 @@ main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "Rb:l:")) != -1) {
|
while ((ch = getopt(argc, argv, "Rb:hl:")) != -1) {
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
|
case 'h':
|
||||||
|
harddisk_emulation= 1;
|
||||||
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
label = optarg;
|
label = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -956,6 +971,8 @@ main(int argc, char *argv[])
|
||||||
/* write the boot catalog */
|
/* write the boot catalog */
|
||||||
fprintf(stderr, " * writing the boot catalog\n");
|
fprintf(stderr, " * writing the boot catalog\n");
|
||||||
bootcatalogsector = currentsector;
|
bootcatalogsector = currentsector;
|
||||||
|
if (harddisk_emulation)
|
||||||
|
system_type = get_system_type(bootfd);
|
||||||
writebootcatalog(fd, ¤tsector, imagesector, imagesectors);
|
writebootcatalog(fd, ¤tsector, imagesector, imagesectors);
|
||||||
|
|
||||||
/* write boot image */
|
/* write boot image */
|
||||||
|
@ -1045,4 +1062,50 @@ main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_system_type(int fd)
|
||||||
|
{
|
||||||
|
off_t old_pos;
|
||||||
|
size_t size;
|
||||||
|
ssize_t r;
|
||||||
|
int type;
|
||||||
|
struct part_entry *partp;
|
||||||
|
unsigned char bootsector[512];
|
||||||
|
|
||||||
|
errno= 0;
|
||||||
|
old_pos= lseek(fd, SEEK_SET, 0);
|
||||||
|
if (old_pos == -1 && errno != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "bootimage file is not seekable: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
size= sizeof(bootsector);
|
||||||
|
r= read(fd, bootsector, size);
|
||||||
|
if (r != size)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error reading bootimage file: %s\n",
|
||||||
|
r < 0 ? strerror(errno) : "unexpected EOF");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (bootsector[size-2] != 0x55 && bootsector[size-1] != 0xAA)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "bad magic in bootimage file\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
partp= (struct part_entry *)&bootsector[PART_TABLE_OFF];
|
||||||
|
type= partp->sysind;
|
||||||
|
if (type == NO_PART)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "first partition table entry is unused\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (!(partp->bootind & ACTIVE_FLAG))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "first partition table entry is not active\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lseek(fd, SEEK_SET, old_pos);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue