From 65efb419a272e323e5845774e8e5f2f5930e5d9c Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 5 Nov 2019 19:34:07 +0100 Subject: [PATCH] btrfs-progs: move parse_csum_type to utils This will be used by convert. Signed-off-by: David Sterba --- common/utils.c | 20 ++++++++++++++++++++ common/utils.h | 1 + mkfs/main.c | 20 -------------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/common/utils.c b/common/utils.c index 71eac462..25d588ba 100644 --- a/common/utils.c +++ b/common/utils.c @@ -762,6 +762,26 @@ err: exit(-1); } +enum btrfs_csum_type parse_csum_type(const char *s) +{ + if (strcasecmp(s, "crc32c") == 0) { + return BTRFS_CSUM_TYPE_CRC32; + } else if (strcasecmp(s, "xxhash64") == 0 || + strcasecmp(s, "xxhash") == 0) { + return BTRFS_CSUM_TYPE_XXHASH; + } else if (strcasecmp(s, "sha256") == 0) { + return BTRFS_CSUM_TYPE_SHA256; + } else if (strcasecmp(s, "blake2b") == 0 || + strcasecmp(s, "blake2") == 0) { + return BTRFS_CSUM_TYPE_BLAKE2; + } else { + error("unknown csum type %s", s); + exit(1); + } + /* not reached */ + return 0; +} + int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags) { int ret; diff --git a/common/utils.h b/common/utils.h index 0ef1d6e8..c31da330 100644 --- a/common/utils.h +++ b/common/utils.h @@ -65,6 +65,7 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_bytes, unsigned unit_mo #define pretty_size(size) pretty_size_mode(size, UNITS_DEFAULT) const char *pretty_size_mode(u64 size, unsigned mode); +enum btrfs_csum_type parse_csum_type(const char *s); u64 parse_size(const char *s); u64 parse_qgroupid(const char *p); u64 arg_strtou64(const char *str); diff --git a/mkfs/main.c b/mkfs/main.c index 1a457841..d9ed01e1 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -388,26 +388,6 @@ static u64 parse_profile(const char *s) return 0; } -static enum btrfs_csum_type parse_csum_type(const char *s) -{ - if (strcasecmp(s, "crc32c") == 0) { - return BTRFS_CSUM_TYPE_CRC32; - } else if (strcasecmp(s, "xxhash64") == 0 || - strcasecmp(s, "xxhash") == 0) { - return BTRFS_CSUM_TYPE_XXHASH; - } else if (strcasecmp(s, "sha256") == 0) { - return BTRFS_CSUM_TYPE_SHA256; - } else if (strcasecmp(s, "blake2b") == 0 || - strcasecmp(s, "blake2") == 0) { - return BTRFS_CSUM_TYPE_BLAKE2; - } else { - error("unknown csum type %s", s); - exit(1); - } - /* not reached */ - return 0; -} - static char *parse_label(const char *input) { int len = strlen(input);