static long cylinders = 0;
static long heads_per_cylinder = 0;
static long sectors_per_track = 0;
+static long sectors_per_cylinder = 0;
struct parted_state *state = 0;
const char *program_name = 0;
cylinders++;
- state->image_size = ((cylinders * heads_per_cylinder) * sectors_per_track);
- state->image_size += ((heads_per_cylinder - 1) * sectors_per_track);
+#if 0
+ /* This works for PCem and 86box but not for qemu. */
+ state->image_size = cylinders * heads_per_cylinder;
+ state->image_size = (state->image_size * sectors_per_track) * 512;
+
+#else
+
+ /**
+ * Ideally we'd have a new size of 41,954,304 for the image as Pcem and
+ * 86box reports 81940 sectors and times by 512 equals 41,953,280 add 512
+ * bytes for the mbr and 512 for the VHD footer however qemu seems to report
+ * different disk geometry compared to PCem and 86box resuling to 81900
+ * sectors being reported instead so we need to make the image way bigger
+ * than it needs to be to accommodate qemu.
+ */
+ state->image_size = (cylinders * heads_per_cylinder) * sectors_per_track;
+
+ state->image_size = state->image_size + ((heads_per_cylinder - 1) * sectors_per_track);
state->image_size = (state->image_size + (sectors_per_track - 1)) * 512;
+
+#endif
}
+
+ sectors_per_cylinder = heads_per_cylinder * sectors_per_track;
}
struct mbr mbr;
long p, sector = 1;
- long sectors_per_cylinder, start, end;
+ long start, end;
if (argc && *argv) {
write741_to_byte_array (mbr.signature, generate_signature (), 1);
calculate_geometry ();
- sectors_per_cylinder = heads_per_cylinder * sectors_per_track;
for (p = 0; p < state->nb_parts; ++p) {