]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: add remove_buffer helper
authorThomas Weißschuh <thomas@t-8ch.de>
Sun, 10 Sep 2023 20:11:20 +0000 (22:11 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 12 Sep 2023 11:15:02 +0000 (13:15 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libblkid/src/probe.c

index 8f13ecb5c3f5c6e867ffeb36a2d2ee52b34a9aec..fa16f06082e0806999a4f00d66374f2ece16d4ab 100644 (file)
@@ -544,6 +544,16 @@ int __blkid_probe_filter_types(blkid_probe pr, int chain, int flag, char *names[
        return 0;
 }
 
+static void remove_buffer(struct blkid_bufinfo *bf)
+{
+       list_del(&bf->bufs);
+
+       DBG(BUFFER, ul_debug(" remove buffer: [off=%"PRIu64", len=%"PRIu64"]",
+                               bf->off, bf->len));
+       munmap(bf->data, bf->len);
+       free(bf);
+}
+
 static struct blkid_bufinfo *read_buffer(blkid_probe pr, uint64_t real_off, uint64_t len)
 {
        ssize_t ret;
@@ -585,8 +595,7 @@ static struct blkid_bufinfo *read_buffer(blkid_probe pr, uint64_t real_off, uint
        ret = read(pr->fd, bf->data, len);
        if (ret != (ssize_t) len) {
                DBG(LOWPROBE, ul_debug("\tread failed: %m"));
-               munmap(bf->data, bf->len);
-               free(bf);
+               remove_buffer(bf);
 
                /* I/O errors on CDROMs are non-fatal to work with hybrid
                 * audio+data disks */
@@ -776,12 +785,10 @@ int blkid_probe_reset_buffers(blkid_probe pr)
                                                struct blkid_bufinfo, bufs);
                ct++;
                len += bf->len;
-               list_del(&bf->bufs);
 
                DBG(BUFFER, ul_debug(" remove buffer: [off=%"PRIu64", len=%"PRIu64"]",
                                     bf->off, bf->len));
-               munmap(bf->data, bf->len);
-               free(bf);
+               remove_buffer(bf);
        }
 
        DBG(LOWPROBE, ul_debug(" buffers summary: %"PRIu64" bytes by %"PRIu64" read() calls",