From 2816a817149c792fa836d9ab06b64934aee8ac33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sat, 30 Sep 2023 23:56:46 +0200 Subject: [PATCH] libblkid: (probe) allow superblock offset from end of device MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Weißschuh --- libblkid/src/probe.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index c5d77a17fb..d55cf5eb17 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -1200,12 +1200,18 @@ int blkid_probe_set_dimension(blkid_probe pr, uint64_t off, uint64_t size) const unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, const struct blkid_idmag *mag, size_t size) { - uint64_t hint_offset; + uint64_t hint_offset, off; - if (!mag->hoff || blkid_probe_get_hint(pr, mag->hoff, &hint_offset) < 0) - hint_offset = 0; + if (mag->kboff >= 0) { + if (!mag->hoff || blkid_probe_get_hint(pr, mag->hoff, &hint_offset) < 0) + hint_offset = 0; + + off = hint_offset + (mag->kboff << 10); + } else { + off = pr->size - (-mag->kboff << 10); + } - return blkid_probe_get_buffer(pr, hint_offset + (mag->kboff << 10), size); + return blkid_probe_get_buffer(pr, off, size); } /* @@ -1227,7 +1233,7 @@ int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id, /* try to detect by magic string */ while(mag && mag->magic) { const unsigned char *buf; - uint64_t kboff; + long kboff; uint64_t hint_offset; if (!mag->hoff || blkid_probe_get_hint(pr, mag->hoff, &hint_offset) < 0) @@ -1244,7 +1250,10 @@ int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id, else kboff = ((mag->zonenum * pr->zone_size) >> 10) + mag->kboff_inzone; - off = hint_offset + ((kboff + (mag->sboff >> 10)) << 10); + if (kboff >= 0) + off = hint_offset + ((kboff + (mag->sboff >> 10)) << 10); + else + off = pr->size - (-kboff << 10); buf = blkid_probe_get_buffer(pr, off, 1024); if (!buf && errno) @@ -1253,7 +1262,7 @@ int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id, if (buf && !memcmp(mag->magic, buf + (mag->sboff & 0x3ff), mag->len)) { - DBG(LOWPROBE, ul_debug("\tmagic sboff=%u, kboff=%" PRIu64, + DBG(LOWPROBE, ul_debug("\tmagic sboff=%u, kboff=%ld", mag->sboff, kboff)); if (offset) *offset = off + (mag->sboff & 0x3ff); -- 2.47.2