Currently only single checksum byte is outputted.
This fixes it so that full checksum is outputted.

Signed-off-by: Dāvis Mosāns <davis...@gmail.com>
---
 kernel-shared/disk-io.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index 6f584986..10b2421e 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -160,10 +160,30 @@ int btrfs_csum_data(u16 csum_type, const u8 *data, u8 
*out, size_t len)
        return -1;
 }
 
+int btrfs_format_csum(u16 csum_type, u16 csum_size, const char *data, char 
*output)
+{
+       int i;
+       int position = 0;
+       int direction = 1;
+       if (csum_type == BTRFS_CSUM_TYPE_CRC32 ||
+               csum_type == BTRFS_CSUM_TYPE_XXHASH) {
+               position = csum_size - 1;
+               direction = -1;
+       }
+
+       for (i = 0; i < csum_size; i++) {
+               sprintf(output + i*2, "%02X", data[position + i*direction] & 
0xFF);
+       }
+
+       return csum_size;
+}
+
 static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
                                  int verify, int silent, u16 csum_type)
 {
        u8 result[BTRFS_CSUM_SIZE];
+       char found[BTRFS_CSUM_SIZE * 2 + 1]; // 2 hex chars for each byte + null
+       char wanted[BTRFS_CSUM_SIZE * 2 + 1];
        u32 len;
 
        len = buf->len - BTRFS_CSUM_SIZE;
@@ -172,12 +192,14 @@ static int __csum_tree_block_size(struct extent_buffer 
*buf, u16 csum_size,
 
        if (verify) {
                if (memcmp_extent_buffer(buf, result, 0, csum_size)) {
-                       /* FIXME: format */
-                       if (!silent)
-                               printk("checksum verify failed on %llu found 
%08X wanted %08X\n",
+                       if (!silent) {
+                               btrfs_format_csum(csum_type, csum_size, (char 
*)result, found);
+                               btrfs_format_csum(csum_type, csum_size, 
buf->data, wanted);
+                               printk("checksum verify failed on %llu wanted 
%s found %s\n",
                                       (unsigned long long)buf->start,
-                                      result[0],
-                                      buf->data[0]);
+                                      wanted,
+                                      found);
+                       }
                        return 1;
                }
        } else {
-- 
2.30.1

Reply via email to