From: Pali Rohár Date: Thu, 5 Nov 2020 18:22:22 +0000 (+0100) Subject: libblkid: allow to specify offset defined by hint for blkid_probe_get_idmag() X-Git-Tag: v2.37-rc1~266^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e31657db5353f7b94ecb066ee9787e26b3a4a1d;p=thirdparty%2Futil-linux.git libblkid: allow to specify offset defined by hint for blkid_probe_get_idmag() 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 --- diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h index c3b1056216..df335f1b1b 100644 --- a/libblkid/src/blkidP.h +++ b/libblkid/src/blkidP.h @@ -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 */ }; diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index eb71e48d4a..7c29b7fdcf 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -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)