forked from Mirrors/btrfs-progs
btrfs-progs: add is_valid_csum_type() helper
Add a helper to check if we have a valid csum type from the super block. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: David Sterba <dsterba@suse.com>master
parent
56198f3a9d
commit
f3d7675c08
|
@ -311,6 +311,16 @@ static void print_readable_super_flag(u64 flag)
|
||||||
super_flags_num, BTRFS_SUPER_FLAG_SUPP);
|
super_flags_num, BTRFS_SUPER_FLAG_SUPP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_valid_csum_type(u16 csum_type)
|
||||||
|
{
|
||||||
|
switch (csum_type) {
|
||||||
|
case BTRFS_CSUM_TYPE_CRC32:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void dump_superblock(struct btrfs_super_block *sb, int full)
|
static void dump_superblock(struct btrfs_super_block *sb, int full)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -326,7 +336,7 @@ static void dump_superblock(struct btrfs_super_block *sb, int full)
|
||||||
csum_type = btrfs_super_csum_type(sb);
|
csum_type = btrfs_super_csum_type(sb);
|
||||||
csum_size = BTRFS_CSUM_SIZE;
|
csum_size = BTRFS_CSUM_SIZE;
|
||||||
printf("csum_type\t\t%hu (", csum_type);
|
printf("csum_type\t\t%hu (", csum_type);
|
||||||
if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) {
|
if (!is_valid_csum_type(csum_type)) {
|
||||||
printf("INVALID");
|
printf("INVALID");
|
||||||
} else {
|
} else {
|
||||||
if (csum_type == BTRFS_CSUM_TYPE_CRC32) {
|
if (csum_type == BTRFS_CSUM_TYPE_CRC32) {
|
||||||
|
@ -342,8 +352,7 @@ static void dump_superblock(struct btrfs_super_block *sb, int full)
|
||||||
printf("csum\t\t\t0x");
|
printf("csum\t\t\t0x");
|
||||||
for (i = 0, p = sb->csum; i < csum_size; i++)
|
for (i = 0, p = sb->csum; i < csum_size; i++)
|
||||||
printf("%02x", p[i]);
|
printf("%02x", p[i]);
|
||||||
if (csum_type != BTRFS_CSUM_TYPE_CRC32 ||
|
if (!is_valid_csum_type(csum_type))
|
||||||
csum_size != btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32])
|
|
||||||
printf(" [UNKNOWN CSUM TYPE OR SIZE]");
|
printf(" [UNKNOWN CSUM TYPE OR SIZE]");
|
||||||
else if (check_csum_sblock(sb, csum_size, csum_type))
|
else if (check_csum_sblock(sb, csum_size, csum_type))
|
||||||
printf(" [match]");
|
printf(" [match]");
|
||||||
|
|
Loading…
Reference in New Issue