From: Thomas Weißschuh Date: Sat, 30 Dec 2023 23:26:22 +0000 (+0100) Subject: libblkid: introduce helper to get offset for idmag X-Git-Tag: v2.40-rc1~89 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0928e6ed566bc05218851f084915bde9cfaa42e0;p=thirdparty%2Futil-linux.git libblkid: introduce helper to get offset for idmag As idmag->kboff can be negative to refer to an offset from the end of the device, introduce a helper so probers don't have to worry about this detail. Signed-off-by: Thomas Weißschuh --- diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h index 63d1946f9b..cb263ef65f 100644 --- a/libblkid/src/blkidP.h +++ b/libblkid/src/blkidP.h @@ -443,6 +443,9 @@ extern const unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const stru #define blkid_probe_get_sb(_pr, _mag, type) \ ((type *) blkid_probe_get_sb_buffer((_pr), _mag, sizeof(type))) +extern uint64_t blkid_probe_get_idmag_off(blkid_probe pr, const struct blkid_idmag *mag) + __attribute__((nonnull)); + extern blkid_partlist blkid_probe_get_partlist(blkid_probe pr) __attribute__((nonnull)) __attribute__((warn_unused_result)); diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index 27085b473d..64e794467a 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -1247,6 +1247,14 @@ const unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blki return blkid_probe_get_buffer(pr, off, size); } +uint64_t blkid_probe_get_idmag_off(blkid_probe pr, const struct blkid_idmag *mag) +{ + if (mag->kboff >= 0) + return mag->kboff << 10; + else + return pr->size - (-mag->kboff << 10); +} + /* * Check for matching magic value. * Returns BLKID_PROBE_OK if found, BLKID_PROBE_NONE if not found