]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: zonefs: add checksum support
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 13 Sep 2022 11:08:49 +0000 (13:08 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 13 Sep 2022 12:30:48 +0000 (14:30 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libblkid/src/superblocks/zonefs.c

index 2cb7097d4c57118f2fbd57d2167553d12c3a1ec1..b18dc2c6deb7bcda8a24a4535f9dbd94d4b3a9cc 100644 (file)
@@ -8,6 +8,7 @@
 #include <string.h>
 
 #include "superblocks.h"
+#include "crc32.h"
 
 #define ZONEFS_MAGIC           "SFOZ" /* 0x5a4f4653 'Z' 'O' 'F' 'S' */
 #define ZONEFS_MAGIC_SIZE      4
@@ -44,10 +45,18 @@ struct zonefs_super {
        int32_t         s_perm;
 
        /* Padding to 4096 bytes */
-       /* uint8_t              s_reserved[4020]; */
+       uint8_t         s_reserved[4020];
 
 } __attribute__ ((packed));
 
+static int zonefs_verify_csum(blkid_probe pr, struct zonefs_super *sb)
+{
+       uint32_t expected = le32_to_cpu(sb->s_crc);
+       sb->s_crc = 0;
+       uint32_t crc = ul_crc32(~0LL, (unsigned char *) sb, sizeof(*sb));
+       return blkid_probe_verify_csum(pr, crc, expected);
+}
+
 static int probe_zonefs(blkid_probe pr,
                const struct blkid_idmag *mag  __attribute__((__unused__)))
 {
@@ -59,6 +68,9 @@ static int probe_zonefs(blkid_probe pr,
        if (!sb)
                return errno ? -errno : 1;
 
+       if (!zonefs_verify_csum(pr, sb))
+               return 1;
+
        if (sb->s_label[0])
                blkid_probe_set_label(pr, (unsigned char *) sb->s_label,
                                      sizeof(sb->s_label));