All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Thumshirn <jthumshirn@suse.de>
To: David Sterba <dsterba@suse.com>
Cc: Nikolay Borisov <nborisov@suse.com>,
	Linux BTRFS Mailinglist <linux-btrfs@vger.kernel.org>,
	Johannes Thumshirn <jthumshirn@suse.de>
Subject: [PATCH v5 2/7] btrfs-progs: add is_valid_csum_type() helper
Date: Wed, 25 Sep 2019 15:37:23 +0200	[thread overview]
Message-ID: <20190925133728.18027-3-jthumshirn@suse.de> (raw)
In-Reply-To: <20190925133728.18027-1-jthumshirn@suse.de>

Add a helper to check if we have a valid csum type from the super block.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 cmds/inspect-dump-super.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/cmds/inspect-dump-super.c b/cmds/inspect-dump-super.c
index 58bf82b0bbd3..272df1bfdc14 100644
--- a/cmds/inspect-dump-super.c
+++ b/cmds/inspect-dump-super.c
@@ -311,6 +311,16 @@ static void print_readable_super_flag(u64 flag)
 				     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)
 {
 	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_size = BTRFS_CSUM_SIZE;
 	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");
 	} else {
 		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");
 	for (i = 0, p = sb->csum; i < csum_size; i++)
 		printf("%02x", p[i]);
-	if (csum_type != BTRFS_CSUM_TYPE_CRC32 ||
-	    csum_size != btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32])
+	if (!is_valid_csum_type(csum_type))
 		printf(" [UNKNOWN CSUM TYPE OR SIZE]");
 	else if (check_csum_sblock(sb, csum_size, csum_type))
 		printf(" [match]");
-- 
2.16.4


  parent reply	other threads:[~2019-09-25 13:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25 13:37 [PATCH v5 0/7] btrfs-progs: support xxhash64 checksums Johannes Thumshirn
2019-09-25 13:37 ` [PATCH v5 1/7] btrfs-progs: add option for checksum type to mkfs Johannes Thumshirn
2019-09-25 13:50   ` Johannes Thumshirn
2019-09-25 14:01     ` Johannes Thumshirn
2019-09-25 16:48       ` David Sterba
2019-09-25 13:37 ` Johannes Thumshirn [this message]
2019-09-25 13:37 ` [PATCH v5 3/7] btrfs-progs: add table for checksum type and name Johannes Thumshirn
2019-09-25 13:37 ` [PATCH v5 4/7] btrfs-progs: also print checksum type when running mkfs Johannes Thumshirn
2019-09-25 13:37 ` [PATCH v5 5/7] btrfs-progs: add xxhash64 to mkfs Johannes Thumshirn
2019-09-26 10:06   ` Johannes Thumshirn
2019-09-26 11:24     ` David Sterba
2019-09-26 10:11   ` [PATCH v6] " Johannes Thumshirn
2019-10-07 11:11     ` Qu Wenruo
2019-10-07 15:41       ` David Sterba
2019-09-25 13:37 ` [PATCH v5 6/7] btrfs-progs: move crc32c implementation to crypto/ Johannes Thumshirn
2019-09-25 13:37 ` [RFC PATCH v5 7/7] btrfs-progs: add test override for mkfs to use different checksums Johannes Thumshirn
2019-09-25 17:20   ` David Sterba
2019-09-25 17:22 ` [PATCH v5 0/7] btrfs-progs: support xxhash64 checksums David Sterba
2019-09-26  6:49   ` Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190925133728.18027-3-jthumshirn@suse.de \
    --to=jthumshirn@suse.de \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.