From 1f486fd78b17fa2ad0bf37ed772dc5b8fe2d3b21 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 19 Oct 2010 10:14:26 +0200 Subject: [PATCH] Coordinated appending of partition images with situations other than isohybrid MBR production or partition offset. --- libisofs/ecma119.c | 5 +++++ libisofs/libisofs.h | 6 +++++- libisofs/messages.c | 2 ++ libisofs/system_area.c | 27 +++++++++++++++++++++------ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index 4a5a05d..26d88ce 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -1615,6 +1615,11 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) } else { system_area_options = opts->system_area_options & 0xfc; } + if ((system_area_options & 0xfc) != 0) + for (i = 0; i < 4; i++) + if (opts->appended_partitions[i] != NULL) + return ISO_NON_MBR_SYS_AREA; + target->system_area_data = NULL; if (system_area != NULL) { target->system_area_data = calloc(32768, 1); diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 81a2c5a..d38be5b 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -6357,7 +6357,11 @@ int iso_md5_match(char first_md5[16], char second_md5[16]); #define ISO_BAD_PARTITION_NO 0xE830FE8F /** Cannot open data file for appended partition (FAILURE, HIGH, -370) */ -#define ISO_BAD_PARTITION_FILE 0xE830FE8E +#define ISO_BAD_PARTITION_FILE 0xE830FE8E + +/** May not combine appended partition with non-MBR system area + (FAILURE, HIGH, -371) */ +#define ISO_NON_MBR_SYS_AREA 0xE830FE8D /* Internal developer note: diff --git a/libisofs/messages.c b/libisofs/messages.c index 92feb5e..79a77fd 100644 --- a/libisofs/messages.c +++ b/libisofs/messages.c @@ -357,6 +357,8 @@ const char *iso_error_to_msg(int errcode) return "Partition number out of range"; case ISO_BAD_PARTITION_FILE: return "Cannot open data file for appended partition"; + case ISO_NON_MBR_SYS_AREA: + return "May not combine appended partition with non-MBR system area"; default: return "Unknown error"; } diff --git a/libisofs/system_area.c b/libisofs/system_area.c index 691e2d4..de7f902 100644 --- a/libisofs/system_area.c +++ b/libisofs/system_area.c @@ -436,8 +436,9 @@ static int make_mips_volume_header(Ecma119Image *t, uint8_t *buf, int flag) doc/boot_sectors.txt section "MIPS Little Endian" which was derived by Thomas Schmitt from cdrkit-1.1.10/genisoimage/boot-mipsel.c by Steve McIntyre which is based - on work of Florian Lohoff and Thiemo Seufer, and from by Free - Software Foundation, Inc. + on work of Florian Lohoff and Thiemo Seufer, + and from by Free Software Foundation, Inc. + Both functions are entirely under copyright (C) 2010 Thomas Schmitt. */ @@ -566,7 +567,7 @@ static int make_mipsel_boot_block(Ecma119Image *t, uint8_t *buf, int flag) int iso_write_system_area(Ecma119Image *t, uint8_t *buf) { - int ret, int_img_blocks, sa_type, i; + int ret, int_img_blocks, sa_type, i, will_append = 0; uint32_t img_blocks; if ((t == NULL) || (buf == NULL)) { @@ -577,6 +578,12 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf) memset(buf, 0, 16 * BLOCK_SIZE); sa_type = (t->system_area_options >> 2) & 0x3f; + for (i = 0; i < 4; i++) + if (t->appended_partitions[i] != NULL) { + will_append = 1; + break; + } + img_blocks = t->curblock; if (t->system_area_data != NULL) { /* Write more or less opaque boot image */ @@ -619,20 +626,28 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf) t->partition_secs_per_head, 0, 1, 0x17, buf, 1); if (ret != 1) return ret; - } else if(sa_type == 1) { + } else if (sa_type == 1) { ret = make_mips_volume_header(t, buf, 0); if (ret != ISO_SUCCESS) return ret; - } else if(sa_type == 2) { + } else if (sa_type == 2) { ret = make_mipsel_boot_block(t, buf, 0); if (ret != ISO_SUCCESS) return ret; - } else if(t->partition_offset > 0 && sa_type == 0) { + } else if ((t->partition_offset > 0 || will_append) && sa_type == 0) { /* Write a simple partition table. */ ret = make_grub_msdos_label(img_blocks, t->partition_secs_per_head, t->partition_heads_per_cyl, buf, 2); if (ret != ISO_SUCCESS) /* error should never happen */ return ISO_ASSERT_FAILURE; + if (t->partition_offset == 0) { + /* Re-write partion entry 1 : start at 0, type Linux */ + ret = write_mbr_partition_entry(1, 0x83, 0, img_blocks, + t->partition_secs_per_head, t->partition_heads_per_cyl, + buf, 0); + if (ret < 0) + return ret; + } } if (t->partition_offset > 0 && sa_type == 0) {