From: Daan De Meyer Date: Fri, 3 Apr 2026 19:53:42 +0000 (+0000) Subject: repart: Split out El Torito boot catalog writing into context_eltorito() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0245bf7d7e32db6539faa3fcb7d7c6106860cd08;p=thirdparty%2Fsystemd.git repart: Split out El Torito boot catalog writing into context_eltorito() Writing the El Torito boot catalog should be independent of writing the partition table. Previously, the El Torito logic was embedded in context_write_partition_table(), which meant it was skipped when the partition table hadn't changed. Extract it into a separate context_eltorito() function and invoke it after context_write_partition_table() so the boot catalog is always written when enabled. Also move the overlap verification to be done as soon as we have all the necessary information to do the check and before doing any expensive work; --- diff --git a/src/repart/repart.c b/src/repart/repart.c index 9ed4815aee9..0417d4133a9 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -8020,7 +8020,7 @@ static int write_eltorito( } static int context_verify_eltorito_overlap(Context *context) { - /* before writing the partition table, we check if we have collision with ISO9660 */ + /* Check if the partition table collides with the ISO9660 El Torito area. */ assert(context); if (!arg_eltorito) @@ -8138,10 +8138,6 @@ static int context_write_partition_table(Context *context) { (void) context_notify(context, PROGRESS_WRITING_TABLE, /* object= */ NULL, UINT_MAX); - r = context_verify_eltorito_overlap(context); - if (r < 0) - return r; - r = fdisk_write_disklabel(context->fdisk_context); if (r < 0) return log_error_errno(r, "Failed to write partition table: %m"); @@ -8161,25 +8157,39 @@ static int context_write_partition_table(Context *context) { } else log_notice("Not telling kernel to reread partition table, because selected image does not support kernel partition block devices."); - if (arg_eltorito) { - bool utc = true; - usec_t usec = parse_source_date_epoch(); - if (usec == USEC_INFINITY) { - usec = now(CLOCK_REALTIME); - utc = false; - } + log_info("Partition table written."); - uint64_t esp_offset; - r = context_find_esp_offset(context, &esp_offset); - if (r < 0) - return r; + return 0; +} - r = write_eltorito(fdisk_get_devfd(context->fdisk_context), usec, utc, esp_offset / ISO9660_BLOCK_SIZE, arg_eltorito_system, arg_eltorito_volume, arg_eltorito_publisher); - if (r < 0) - return log_error_errno(r, "Failed to write El Torito boot catalog: %m"); +static int context_write_eltorito(Context *context) { + int r; + + assert(context); + + if (!arg_eltorito) + return 0; + + if (context->dry_run) + return 0; + + bool utc = true; + usec_t usec = parse_source_date_epoch(); + if (usec == USEC_INFINITY) { + usec = now(CLOCK_REALTIME); + utc = false; } - log_info("All done."); + uint64_t esp_offset; + r = context_find_esp_offset(context, &esp_offset); + if (r < 0) + return r; + + log_info("Writing El Torito boot catalog."); + + r = write_eltorito(fdisk_get_devfd(context->fdisk_context), usec, utc, esp_offset / ISO9660_BLOCK_SIZE, arg_eltorito_system, arg_eltorito_volume, arg_eltorito_publisher); + if (r < 0) + return log_error_errno(r, "Failed to write El Torito boot catalog: %m"); return 0; } @@ -11065,6 +11075,10 @@ static int vl_method_run( SD_JSON_BUILD_PAIR_UNSIGNED("minimalSizeBytes", minimal_size)); } + r = context_verify_eltorito_overlap(context); + if (r < 0) + return r; + r = context_ponder(context); if (r == -ENOSPC) { uint64_t current_size, foreign_size, minimal_size; @@ -11113,6 +11127,10 @@ static int vl_method_run( if (r < 0) return r; + r = context_write_eltorito(context); + if (r < 0) + return r; + context_disarm_auto_removal(context); return sd_varlink_reply(link, NULL); @@ -11379,6 +11397,10 @@ static int run(int argc, char *argv[]) { return r; } + r = context_verify_eltorito_overlap(context); + if (r < 0) + return r; + r = context_ponder(context); if (r == -ENOSPC) { /* When we hit space issues, tell the user the minimal size. */ @@ -11394,6 +11416,10 @@ static int run(int argc, char *argv[]) { if (r < 0) return r; + r = context_write_eltorito(context); + if (r < 0) + return r; + r = context_split(context); if (r < 0) return r;