]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: fix blkid_probe_get_sb() to use hint offset calculation
authorPali Rohár <pali.rohar@gmail.com>
Sun, 8 Nov 2020 00:51:28 +0000 (01:51 +0100)
committerPali Rohár <pali.rohar@gmail.com>
Tue, 10 Nov 2020 22:40:53 +0000 (23:40 +0100)
libblkid/src/blkidP.h
libblkid/src/probe.c

index df335f1b1b858fe18ffc8c22571b6fbe6255a53a..a3fe6748a969eb6e6ff2f87433b741eaa2cb9043 100644 (file)
@@ -428,9 +428,9 @@ extern int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
                        __attribute__((nonnull(1)));
 
 /* returns superblock according to 'struct blkid_idmag' */
+extern unsigned char *_blkid_probe_get_sb(blkid_probe pr, const struct blkid_idmag *mag, size_t size);
 #define blkid_probe_get_sb(_pr, _mag, type) \
-                       ((type *) blkid_probe_get_buffer((_pr),\
-                                       (_mag)->kboff << 10, sizeof(type)))
+                       ((type *) _blkid_probe_get_sb((_pr), _mag, sizeof(type)))
 
 extern blkid_partlist blkid_probe_get_partlist(blkid_probe pr)
                        __attribute__((nonnull))
index 7c29b7fdcf9d408bd10253c003a9c50d6542603d..35977edef426c5d12aea4ec8806ab70324a346f7 100644 (file)
@@ -1035,6 +1035,16 @@ int blkid_probe_set_dimension(blkid_probe pr, uint64_t off, uint64_t size)
        return 0;
 }
 
+unsigned char *_blkid_probe_get_sb(blkid_probe pr, const struct blkid_idmag *mag, size_t size)
+{
+       uint64_t hint_offset;
+
+       if (!mag->hoff || blkid_probe_get_hint(pr, mag->hoff, &hint_offset) < 0)
+               hint_offset = 0;
+
+       return blkid_probe_get_buffer(pr, hint_offset + (mag->kboff << 10), size);
+}
+
 /*
  * Check for matching magic value.
  * Returns BLKID_PROBE_OK if found, BLKID_PROBE_NONE if not found