Skip to content

Commit b11004f

Browse files
maharmstonekdave
authored andcommitted
btrfs-progs: print csum values on superblock mismatch
If in btrfs_check_super() we find that the superblock has a csum mismatch, print the wanted and found values, just as we do for metadata in __csum_tree_block_size(). When hex-editing a btrfs image, it's useful to use btrfs check to calculate what the new csum should be. Unfortunately at present this only works for trees and not for the superblock, meaning you have to use the much more wordy `btrfs inspect-internal`. Pull-request: #985 Signed-off-by: Mark Harmstone <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f97bebc commit b11004f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

kernel-shared/disk-io.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,8 +1771,14 @@ int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
17711771
btrfs_csum_data(csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
17721772
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
17731773

1774-
if (memcmp(result, sb->csum, csum_size)) {
1775-
error("superblock checksum mismatch");
1774+
if (memcmp(result, sb->csum, csum_size) != 0) {
1775+
char found[BTRFS_CSUM_STRING_LEN];
1776+
char wanted[BTRFS_CSUM_STRING_LEN];
1777+
1778+
btrfs_format_csum(csum_type, result, found);
1779+
btrfs_format_csum(csum_type, (u8 *)sb->csum, wanted);
1780+
1781+
error("superblock checksum mismatch: wanted %s found %s", wanted, found);
17761782
return -EIO;
17771783
}
17781784
if (btrfs_super_root_level(sb) >= BTRFS_MAX_LEVEL) {

0 commit comments

Comments
 (0)