Making an educated guess whether the boot images contain a boot info table.

New API call el_torito_seems_boot_info_table() publishes this guess.
This commit is contained in:
2010-04-29 15:10:18 +02:00
parent 3d9367d52a
commit e4cf93665a
4 changed files with 252 additions and 25 deletions

View File

@@ -153,8 +153,14 @@ int el_torito_get_selection_crit(ElToritoBootImage *bootimg, uint8_t crit[20])
return 1;
}
/* API */
int el_torito_seems_boot_info_table(ElToritoBootImage *bootimg, int flag)
{
return bootimg->seems_boot_info_table;
}
/**
* Specifies that this image needs to be patched. This involves the writting
* Specifies that this image needs to be patched. This involves the writing
* of a 56 bytes boot information table at offset 8 of the boot image file.
* The original boot image file won't be modified.
* This is needed for isolinux boot images.
@@ -173,7 +179,7 @@ void el_torito_patch_isolinux_image(ElToritoBootImage *bootimg)
* bitmask style flag. The following values are defined:
*
* bit 0 -> 1 to path the image, 0 to not
* Patching the image involves the writting of a 56 bytes
* Patching the image involves the writing of a 56 bytes
* boot information table at offset 8 of the boot image file.
* The original boot image file won't be modified. This is needed
* to allow isolinux images to be bootable.
@@ -405,6 +411,7 @@ int create_image(IsoImage *image, const char *image_path,
boot->image = (IsoFile*)imgfile;
iso_node_ref(imgfile); /* get our ref */
boot->bootable = 1;
boot->seems_boot_info_table = 0;
boot->isolinux_options = 0;
boot->type = boot_media_type;
boot->partition_type = partition_type;
@@ -677,10 +684,12 @@ void el_torito_boot_catalog_free(struct el_torito_boot_catalog *cat)
image = cat->bootimages[i];
if (image == NULL)
continue;
iso_node_unref((IsoNode*)image->image);
if ((IsoNode*)image->image != NULL)
iso_node_unref((IsoNode*)image->image);
free(image);
}
iso_node_unref((IsoNode*)cat->node);
if ((IsoNode*)cat->node != NULL)
iso_node_unref((IsoNode*)cat->node);
free(cat);
}
@@ -981,6 +990,50 @@ int el_torito_catalog_file_src_create(Ecma119Image *target, IsoFileSrc **src)
/******************* EL-TORITO WRITER *******************************/
/**
* Insert boot info table content into buf.
*
* @return
* 1 on success, 0 error (but continue), < 0 error
*/
int make_boot_info_table(uint8_t *buf, uint32_t pvd_lba,
uint32_t boot_lba, uint32_t imgsize)
{
struct boot_info_table *info;
uint32_t checksum;
uint32_t offset;
info = (struct boot_info_table *) (buf + 8);
if (imgsize < 64)
return ISO_ISOLINUX_CANT_PATCH;
/* compute checksum, as the the sum of all 32 bit words in boot image
* from offset 64 */
checksum = 0;
offset = 64;
while (offset <= imgsize - 4) {
checksum += iso_read_lsb(buf + offset, 4);
offset += 4;
}
if (offset != imgsize) {
/*
* file length not multiple of 4
* empty space in isofs is padded with zero;
* assume same for last dword
*/
checksum += iso_read_lsb(buf + offset, imgsize - offset);
}
/*memset(info, 0, sizeof(struct boot_info_table));*/
iso_lsb(info->bi_pvd, pvd_lba, 4);
iso_lsb(info->bi_file, boot_lba, 4);
iso_lsb(info->bi_length, imgsize, 4);
iso_lsb(info->bi_csum, checksum, 4);
memset(buf + 24, 0, 40);
return ISO_SUCCESS;
}
/**
* Patch an isolinux boot image.
*
@@ -990,6 +1043,24 @@ int el_torito_catalog_file_src_create(Ecma119Image *target, IsoFileSrc **src)
static
int patch_boot_image(uint8_t *buf, Ecma119Image *t, size_t imgsize, int idx)
{
/* >>> ts B00428 BOOT : make this the default case */
#define Libisofs_new_patch_boot_imagE 1
#ifdef Libisofs_new_patch_boot_imagE
int ret;
if (imgsize < 64) {
return iso_msg_submit(t->image->id, ISO_ISOLINUX_CANT_PATCH, 0,
"Isolinux image too small. We won't patch it.");
}
ret = make_boot_info_table(buf, t->ms_block + (uint32_t) 16,
t->bootsrc[idx]->sections[0].block,
(uint32_t) imgsize);
return ret;
#else /* Libisofs_new_patch_boot_imagE */
struct boot_info_table *info;
uint32_t checksum;
size_t offset;
@@ -1024,7 +1095,11 @@ int patch_boot_image(uint8_t *buf, Ecma119Image *t, size_t imgsize, int idx)
iso_lsb(info->bi_file, t->bootsrc[idx]->sections[0].block, 4);
iso_lsb(info->bi_length, imgsize, 4);
iso_lsb(info->bi_csum, checksum, 4);
memset(buf + 24, 0, 40);
return ISO_SUCCESS;
#endif /* ! Libisofs_new_patch_boot_imagE */
}
static
@@ -1054,6 +1129,10 @@ int eltorito_writer_compute_data_blocks(IsoImageWriter *writer)
continue;
original = t->bootsrc[idx]->stream;
size = (size_t) iso_stream_get_size(original);
/* >>> BOOT ts B00428 :
check whether size is not too large for buffering */;
buf = calloc(1, size);
if (buf == NULL) {
return ISO_OUT_OF_MEM;