]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: btrfs: add support for xxhash checksums
authorThomas Weißschuh <thomas@t-8ch.de>
Fri, 18 Nov 2022 19:07:37 +0000 (20:07 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Mon, 21 Nov 2022 14:29:58 +0000 (15:29 +0100)
libblkid/src/superblocks/btrfs.c

index de39b70fb83aef5105e71f65dec1c32e677e6594..b9cf4bd3706b88a6b8e266b5e41b092d2c71339c 100644 (file)
 #include "superblocks.h"
 #include "crc32c.h"
 #include "sha256.h"
+#include "xxhash.h"
 
 enum btrfs_super_block_csum_type {
        BTRFS_SUPER_BLOCK_CSUM_TYPE_CRC32C = 0,
+       BTRFS_SUPER_BLOCK_CSUM_TYPE_XXHASH = 1,
        BTRFS_SUPER_BLOCK_CSUM_TYPE_SHA256 = 2,
 };
 
 union btrfs_super_block_csum {
        uint8_t bytes[32];
        uint32_t crc32c;
+       XXH64_hash_t xxh64;
        uint8_t sha256[UL_SHA256LENGTH];
 };
 
@@ -227,6 +230,11 @@ static int btrfs_verify_csum(blkid_probe pr, const struct btrfs_super_block *bfs
                        return blkid_probe_verify_csum(pr, crc,
                                        le32_to_cpu(bfs->csum.crc32c));
                }
+               case BTRFS_SUPER_BLOCK_CSUM_TYPE_XXHASH: {
+                       XXH64_hash_t xxh64 = XXH64(csum_data, csum_data_size, 0);
+                       return blkid_probe_verify_csum(pr, xxh64,
+                                       le64_to_cpu(bfs->csum.xxh64));
+               }
                case BTRFS_SUPER_BLOCK_CSUM_TYPE_SHA256: {
                        uint8_t sha256[UL_SHA256LENGTH];
                        ul_SHA256(sha256, csum_data, csum_data_size);