]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: introduce helper to get offset for idmag
authorThomas Weißschuh <thomas@t-8ch.de>
Sat, 30 Dec 2023 23:26:22 +0000 (00:26 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 31 Dec 2023 12:07:39 +0000 (13:07 +0100)
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 <thomas@t-8ch.de>
libblkid/src/blkidP.h
libblkid/src/probe.c

index 63d1946f9b66d6d02f7ac6fd85b742fc3a4e9eeb..cb263ef65f1c8881312d5b16e0cdc1f5815bad61 100644 (file)
@@ -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));
index 27085b473d03caeb0c33f56359e17d159d9238a7..64e794467a4623b0e23f9563954764d9b67e641a 100644 (file)
@@ -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