diff --git a/src/minivhd/minivhd.h b/src/minivhd/minivhd.h index 357c91e..aafd559 100644 --- a/src/minivhd/minivhd.h +++ b/src/minivhd/minivhd.h @@ -191,6 +191,46 @@ void mvhd_close(MVHDMeta* vhdm); */ MVHDGeom mvhd_calculate_geometry(uint64_t size); +/** + * \brief Get the CHS geometry from the image + * + * \param [in] vhdm MiniVHD data structure + * + * \return The CHS geometry as stored in the image + */ +MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm); + +/** + * \brief Get the 'current_size' value from the image + * + * Note that the size returned may not match the size calculated from the + * CHS geometry. It is up to the caller to decide how best to handle this. + * + * \param [in] vhdm MiniVHD data structure + * + * \return The 'current_size' value in bytes, as stored in the image. + * Note, this may not match the CHS geometry. + */ +uint64_t mvhd_get_current_size(MVHDMeta* vhdm); + +/** + * \brief Calculate CHS geometry size in bytes + * + * \param [in] geom the CHS geometry to calculate + * + * \return the size in bytes + */ +uint64_t mvhd_calc_size_bytes(MVHDGeom *geom); + +/** + * \brief Calculate CHS geometry size in sectors + * + * \param [in] geom the CHS geometry to calculate + * + * \return the size in sectors + */ +uint32_t mvhd_calc_size_sectors(MVHDGeom *geom); + /** * \brief Convert a raw disk image to a fixed VHD image * diff --git a/src/minivhd/minivhd_util.c b/src/minivhd/minivhd_util.c index 5bfc599..cd7d446 100644 --- a/src/minivhd/minivhd_util.c +++ b/src/minivhd/minivhd_util.c @@ -16,6 +16,7 @@ #include "libxml2_encoding.h" #include "minivhd_internal.h" #include "minivhd_util.h" +#include "minivhd.h" const char MVHD_CONECTIX_COOKIE[] = "conectix"; const char MVHD_CREATOR[] = "pcem"; @@ -186,6 +187,10 @@ MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm) { return geometry; } +uint64_t mvhd_get_current_size(MVHDMeta* vhdm) { + return vhdm->footer.curr_sz; +} + uint32_t mvhd_gen_footer_checksum(MVHDFooter* footer) { uint32_t new_chk = 0; uint32_t orig_chk = footer->checksum; diff --git a/src/minivhd/minivhd_util.h b/src/minivhd/minivhd_util.h index df68410..8a18b55 100644 --- a/src/minivhd/minivhd_util.h +++ b/src/minivhd/minivhd_util.h @@ -77,9 +77,6 @@ time_t vhd_get_created_time(MVHDMeta *vhdm); FILE* mvhd_fopen(const char* path, const char* mode, int* err); void mvhd_set_encoding_err(int encoding_retval, int* err); -uint64_t mvhd_calc_size_bytes(MVHDGeom *geom); -uint32_t mvhd_calc_size_sectors(MVHDGeom *geom); -MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm); /** * \brief Generate VHD footer checksum