From ffe4486a727c07c5cbd72fb997814ca86c12c319 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Thu, 20 Mar 2025 16:50:46 +0000 Subject: [PATCH] If (cylinder_times_heads / heads_per_cylinder) has a remainder increase the cylinder by 1 and recalculate the image size based on the new geometry --- parted.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/parted.c b/parted.c index acb2701..2c3bf27 100644 --- a/parted.c +++ b/parted.c @@ -141,6 +141,17 @@ static void calculate_geometry (void) { } cylinders = cylinder_times_heads / heads_per_cylinder; + + if (cylinder_times_heads % heads_per_cylinder) { + + cylinders++; + + state->image_size = ((cylinders * heads_per_cylinder) * sectors_per_track); + state->image_size += ((heads_per_cylinder - 1) * sectors_per_track); + + state->image_size = (state->image_size + (sectors_per_track - 1)) * 512; + + } } -- 2.34.1