diff --git a/src/minivhd.h b/src/minivhd.h index a81cdf8..b01128c 100644 --- a/src/minivhd.h +++ b/src/minivhd.h @@ -121,15 +121,15 @@ void mvhd_close(MVHDMeta* vhdm); * * Note, maximum VHD size (in bytes) is 65535 * 16 * 255 * 512, which is 127GB * - * This function determines the appropriate CHS geometry from a provided size in MB. + * This function determines the appropriate CHS geometry from a provided size in bytes. * The calculations used are those provided in "Appendix: CHS Calculation" from the document * "Virtual Hard Disk Image Format Specification" provided by Microsoft. * - * \param [in] size_mb the desired VHD image size, in MiB + * \param [in] size the desired VHD image size, in bytes * * \return MVHDGeom the calculated geometry. This can be used in the appropriate create functions. */ -MVHDGeom mvhd_calculate_geometry(int size_mb); +MVHDGeom mvhd_calculate_geometry(uint64_t size); /** * \brief Read sectors from VHD file diff --git a/src/minivhd_manage.c b/src/minivhd_manage.c index 3d79f25..9569054 100644 --- a/src/minivhd_manage.c +++ b/src/minivhd_manage.c @@ -327,9 +327,9 @@ bool mvhd_file_is_vhd(FILE* f) { } } -MVHDGeom mvhd_calculate_geometry(int size_mb) { +MVHDGeom mvhd_calculate_geometry(uint64_t size) { MVHDGeom chs; - uint32_t ts = ((uint64_t)size_mb * 1024 * 1024) / MVHD_SECTOR_SIZE; + uint32_t ts = size / MVHD_SECTOR_SIZE; uint32_t spt, heads, cyl, cth; if (ts > 65535 * 16 * 255) { ts = 65535 * 16 * 255; diff --git a/test_program/minivhd_test.c b/test_program/minivhd_test.c index ca70ecd..92dceee 100644 --- a/test_program/minivhd_test.c +++ b/test_program/minivhd_test.c @@ -12,7 +12,7 @@ int main(int argc, char* argv[]) { MVHDMeta* vhdm = mvhd_open(path, false, &err); mvhd_close(vhdm); /* Creation Tests */ - MVHDGeom geom = mvhd_calculate_geometry(512); + MVHDGeom geom = mvhd_calculate_geometry(512 * 1024 * 1024); vhdm = mvhd_create_sparse("C:/StandaloneProg/pcem/Images/minivhd/sparse.vhd", geom, &err); if (vhdm == NULL) { printf("Failed with exit code: %d", err);