]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: (probe) allow superblock offset from end of device
authorThomas Weißschuh <thomas@t-8ch.de>
Sat, 30 Sep 2023 21:56:46 +0000 (23:56 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 1 Oct 2023 08:33:05 +0000 (10:33 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libblkid/src/probe.c

index c5d77a17fbfc20b2d203a2d47ec79a767ff4e960..d55cf5eb178a53351dd982794bdc7103049cd089 100644 (file)
@@ -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);