diff --git a/libisofs/eltorito.c b/libisofs/eltorito.c index 2c622b9..db28b7c 100644 --- a/libisofs/eltorito.c +++ b/libisofs/eltorito.c @@ -113,9 +113,24 @@ void el_torito_set_load_size(ElToritoBootImage *bootimg, short sectors) /* API */ int el_torito_get_load_size(ElToritoBootImage *bootimg) { - return (int) bootimg->load_size; + return (int) bootimg->load_size; } +/* API */ +void el_torito_set_full_load(ElToritoBootImage *bootimg, int mode) +{ + if (bootimg->type != 0) + return; + bootimg->load_size_full= !!mode; +} + +/* API */ +int el_torito_get_full_load(ElToritoBootImage *bootimg) +{ + return bootimg->load_size_full; +} + + /** * Marks the specified boot image as not bootable */ @@ -513,6 +528,7 @@ int create_image(IsoImage *image, const char *image_path, boot->partition_type = partition_type; boot->load_seg = 0; boot->load_size = load_sectors; + boot->load_size_full = 0; boot->platform_id = 0; /* 80x86 */ memset(boot->id_string, 0, sizeof(boot->id_string)); memset(boot->selection_crit, 0, sizeof(boot->selection_crit)); @@ -887,6 +903,32 @@ write_section_header(uint8_t *buf, Ecma119Image *t, int idx, int num_entries) sizeof(e->id_string)); } +static int +write_section_load_size(struct el_torito_boot_image *img, + struct el_torito_section_entry *se, + uint16_t load_size, off_t full_byte_size, int flag) +{ + uint16_t size; + off_t blocks; + + size= load_size; + if(img->type == 0 && img->load_size_full) { + blocks= ((full_byte_size + 2047) / 2048) * 4; + if (blocks > 65535) { + if (img->platform_id == 0xef) + size= 0; + else + size= 65535; + } else if(blocks <= 0) { + size= 1; + } else { + size= blocks; + } + } + iso_lsb(se->sec_count, size, 2); + return(1); +} + /** * Write one section entry. * Usable for the Default Entry @@ -930,6 +972,8 @@ int write_section_entry(uint8_t *buf, Ecma119Image *t, int idx) return ISO_BOOT_IMAGE_NOT_VALID; } + /* >>> check for non-automatic load size */; + if (t->boot_intvl_size[idx] > 65535) { if (img->platform_id == 0xef) iso_lsb(se->sec_count, 0, 2); @@ -946,6 +990,9 @@ int write_section_entry(uint8_t *buf, Ecma119Image *t, int idx) iso_lsb(se->block, t->boot_intvl_start[idx], 4); } else if (mode == 2) { app_idx = t->boot_appended_idx[idx]; + + /* >>> check for non-automatic load size */; + if (t->appended_part_size[app_idx] * 4 > 65535) { if (img->platform_id == 0xef) iso_lsb(se->sec_count, 0, 2); @@ -956,7 +1003,8 @@ int write_section_entry(uint8_t *buf, Ecma119Image *t, int idx) } iso_lsb(se->block, t->appended_part_start[app_idx], 4); } else { - iso_lsb(se->sec_count, img->load_size, 2); + write_section_load_size(img, se, (uint16_t) img->load_size, + (off_t) t->bootsrc[idx]->sections[0].size, 0); iso_lsb(se->block, t->bootsrc[idx]->sections[0].block, 4); } diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 093dca7..759dce2 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -3836,6 +3836,26 @@ void el_torito_set_load_size(ElToritoBootImage *bootimg, short sectors); */ int el_torito_get_load_size(ElToritoBootImage *bootimg); +/** + * State that the load size shall be the size of the boot image automatically. + * This overrides el_torito_set_load_size(). + * @param bootimg + * The image to to manipulate + * @param mode + * 0= use value of el_torito_set_load_size() + * 1= determine value from boot image + */ +void el_torito_set_full_load(ElToritoBootImage *bootimg, int mode); + +/** + * Inquire the setting of el_torito_set_full_load(). + * @param bootimg + * The image to inquire + * @return + * The mode set with el_torito_set_full_load(). + */ +int el_torito_get_full_load(ElToritoBootImage *bootimg); + /** * Marks the specified boot image as not bootable * diff --git a/libisofs/libisofs.ver b/libisofs/libisofs.ver index ac93120..d0052b7 100644 --- a/libisofs/libisofs.ver +++ b/libisofs/libisofs.ver @@ -5,6 +5,7 @@ aaip_xinfo_func; el_torito_get_bootable; el_torito_get_boot_media_type; el_torito_get_boot_platform_id; +el_torito_get_full_load; el_torito_get_id_string; el_torito_get_isolinux_options; el_torito_get_load_seg; @@ -13,6 +14,7 @@ el_torito_get_selection_crit; el_torito_patch_isolinux_image; el_torito_seems_boot_info_table; el_torito_set_boot_platform_id; +el_torito_set_full_load; el_torito_set_id_string; el_torito_set_isolinux_options; el_torito_set_load_seg;