]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: allow to specify offset defined by hint for blkid_probe_get_idmag()
authorPali Rohár <pali.rohar@gmail.com>
Thu, 5 Nov 2020 18:22:22 +0000 (19:22 +0100)
committerPali Rohár <pali.rohar@gmail.com>
Tue, 10 Nov 2020 22:40:53 +0000 (23:40 +0100)
Extends struct blkid_idmag with a new member hoff which specify name of the
hint used for blkid_probe_get_hint() function to retrieve offset to kboff.

blkid_probe_get_idmag() will use supplied hint offset in bytes as a start
position from which the final offsets for magic strings are calculated.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
libblkid/src/blkidP.h
libblkid/src/probe.c

index c3b10562164967c00e73bbeed27df773b8951ca4..df335f1b1b858fe18ffc8c22571b6fbe6255a53a 100644 (file)
@@ -147,6 +147,7 @@ struct blkid_idmag
        const char      *magic;         /* magic string */
        unsigned int    len;            /* length of magic */
 
+       const char      *hoff;          /* hint which contains byte offset to kboff */
        long            kboff;          /* kilobyte offset of superblock */
        unsigned int    sboff;          /* byte offset within superblock */
 };
index eb71e48d4ae635f515a328d3106ba6055253ab85..7c29b7fdcf9d408bd10253c003a9c50d6542603d 100644 (file)
@@ -1054,8 +1054,12 @@ int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
        /* try to detect by magic string */
        while(mag && mag->magic) {
                unsigned char *buf;
+               uint64_t hint_offset;
 
-               off = (mag->kboff + (mag->sboff >> 10)) << 10;
+               if (!mag->hoff || blkid_probe_get_hint(pr, mag->hoff, &hint_offset) < 0)
+                       hint_offset = 0;
+
+               off = hint_offset + ((mag->kboff + (mag->sboff >> 10)) << 10);
                buf = blkid_probe_get_buffer(pr, off, 1024);
 
                if (!buf && errno)