From 0928e6ed566bc05218851f084915bde9cfaa42e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sun, 31 Dec 2023 00:26:22 +0100 Subject: [PATCH] libblkid: introduce helper to get offset for idmag MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- libblkid/src/blkidP.h | 3 +++ libblkid/src/probe.c | 8 ++++++++ 2 files changed, 11 insertions(+) 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 -- 2.47.3