Recognizing grub2_mbr= on image load

This commit is contained in:
Thomas Schmitt 2013-04-16 12:44:16 +00:00
parent e11f9665dc
commit b83ff630d1
2 changed files with 68 additions and 9 deletions

View File

@ -211,6 +211,40 @@ int Xorriso_is_isohybrid(struct XorrisO *xorriso, IsoFile *bootimg_node,
} }
/* @return <0 yes , 0 no , <0 error */
int Xorriso_is_grub2_elto(struct XorrisO *xorriso, IsoFile *bootimg_node,
int flag)
{
#define Xorriso_grub2_boot_info_poS 2548
int ret, i;
unsigned char buf[Xorriso_grub2_boot_info_poS + 8];
void *data_stream= NULL;
off_t blk;
ret= Xorriso_iso_file_open(xorriso, "", (void *) bootimg_node,
&data_stream, 1);
if(ret <= 0)
return(-1);
ret= Xorriso_iso_file_read(xorriso, data_stream, (char *) buf,
Xorriso_grub2_boot_info_poS + 8, 0);
Xorriso_iso_file_close(xorriso, &data_stream, 0);
if(ret < Xorriso_grub2_boot_info_poS + 8)
return(0);
/* >>> ??? Check for some id */;
/* Check whether it has grub2_boot_info patching */
blk= 0;
for(i= 0; i < 8; i++)
blk|= buf[Xorriso_grub2_boot_info_poS + i] << (8 * i);
blk-= 5;
blk/= 4;
if(blk != (off_t) xorriso->loaded_boot_bin_lba)
return(0);
return(1);
}
int Xorriso_image_has_md5(struct XorrisO *xorriso, int flag) int Xorriso_image_has_md5(struct XorrisO *xorriso, int flag)
{ {
int ret; int ret;
@ -730,9 +764,10 @@ int Xorriso__append_boot_params(char *line, ElToritoBootImage *bootimg,
*/ */
int Xorriso_show_boot_info(struct XorrisO *xorriso, int flag) int Xorriso_show_boot_info(struct XorrisO *xorriso, int flag)
{ {
int ret, bin_path_valid= 0,has_isolinux_mbr= 0, i, num_boots; int ret, bin_path_valid= 0,has_isolinux_mbr= 0, i, num_boots, has_mbr= 0;
int has_grub2_mbr= 0;
unsigned int mbr_lba= 0; unsigned int mbr_lba= 0;
off_t lb0_count; off_t lb0_count, blk;
char *respt, *path; char *respt, *path;
unsigned char *lb0= NULL; unsigned char *lb0= NULL;
struct burn_drive_info *dinfo; struct burn_drive_info *dinfo;
@ -785,18 +820,19 @@ no_boot:;
bin_path_valid= 1; bin_path_valid= 1;
} }
sprintf(respt, "Boot record : El Torito"); sprintf(respt, "Boot record : El Torito");
/* Load and examine potential MBR */
ret= burn_read_data(drive, (off_t) 0, (char *) lb0, (off_t) 2048,
&lb0_count, 2);
if(ret > 0)
if(lb0[510] == 0x55 && lb0[511] == 0xaa)
has_mbr= 1;
if(bin_path_valid) if(bin_path_valid)
ret= Xorriso_is_isohybrid(xorriso, bootimg_node, 0); ret= Xorriso_is_isohybrid(xorriso, bootimg_node, 0);
else else
ret= 0; ret= 0;
if(ret > 0) { if(ret > 0) {
/* Load and examine potential MBR */ if(has_mbr) {
ret= burn_read_data(drive, (off_t) 0, (char *) lb0, (off_t) 2048,
&lb0_count, 2);
if(ret > 0) {
has_isolinux_mbr= 1; has_isolinux_mbr= 1;
if(lb0[510] != 0x55 || lb0[511] != 0xaa)
has_isolinux_mbr= 0;
mbr_lba= lb0[432] | (lb0[433] << 8) | (lb0[434] << 16) | (lb0[435] << 24); mbr_lba= lb0[432] | (lb0[433] << 8) | (lb0[434] << 16) | (lb0[435] << 24);
mbr_lba/= 4; mbr_lba/= 4;
if(mbr_lba != (unsigned int) xorriso->loaded_boot_bin_lba) if(mbr_lba != (unsigned int) xorriso->loaded_boot_bin_lba)
@ -814,6 +850,29 @@ no_boot:;
else else
strcat(respt, " , ISOLINUX boot image capable of isohybrid"); strcat(respt, " , ISOLINUX boot image capable of isohybrid");
} }
if(bin_path_valid)
ret= Xorriso_is_grub2_elto(xorriso, bootimg_node, 0);
else
ret= 0;
if(ret > 0) {
if(has_mbr) {
has_grub2_mbr= 1;
blk= 0;
for(i= 0; i < 8; i++)
blk|= lb0[i + 0x1b0] << (8 * i);
blk-= 4;
blk/= 4;
if(blk != (off_t) xorriso->loaded_boot_bin_lba)
has_grub2_mbr= 0;
for(i= 32; i < 427; i++)
if(strncmp((char *) (lb0 + i), "GRUB", 4) == 0)
break;
if(i >= 427)
has_grub2_mbr= 0;
}
if(has_grub2_mbr)
strcat(respt, " , GRUB2 MBR pointing to first boot image");
}
strcat(respt, "\n"); strcat(respt, "\n");
Xorriso_toc_line(xorriso, flag & 8); Xorriso_toc_line(xorriso, flag & 8);
if(flag & 2) if(flag & 2)

View File

@ -1 +1 @@
#define Xorriso_timestamP "2013.04.14.174902" #define Xorriso_timestamP "2013.04.16.124331"