From f1178950d33b70cf308eeb68787629776a573c98 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 10 May 2022 14:19:57 +0200 Subject: [PATCH] btrfs-progs: btrfstune: fix build-time detection of experimental features Qu noticed that the full checksums are still printed even if the experimental build is not enabled. This is caused by wrong use of #ifdef (as the macro is always defined), this must be "#if". Fixes: 1bb6fb896dfc ("btrfs-progs: btrfstune: experimental, new option to switch csums") Reported-by: Qu Wenruo Signed-off-by: David Sterba --- btrfstune.c | 6 +++--- kernel-shared/print-tree.c | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/btrfstune.c b/btrfstune.c index 3824a3d9..31be9074 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -794,7 +794,7 @@ static void print_usage(void) printf(" general:\n"); printf("\t-f allow dangerous operations, make sure that you are aware of the dangers\n"); printf("\t--help print this help\n"); -#ifdef EXPERIMENTAL +#if EXPERIMENTAL printf("\nEXPERIMENTAL FEATURES:\n"); printf(" checksum changes:\n"); printf("\t--csum CSUM switch checksum for data and metadata to CSUM\n"); @@ -821,7 +821,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) enum { GETOPT_VAL_CSUM = 256 }; static const struct option long_options[] = { { "help", no_argument, NULL, GETOPT_VAL_HELP}, -#ifdef EXPERIMENTAL +#if EXPERIMENTAL { "csum", required_argument, NULL, GETOPT_VAL_CSUM }, #endif { NULL, 0, NULL, 0 } @@ -864,7 +864,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) ctree_flags |= OPEN_CTREE_IGNORE_FSID_MISMATCH; change_metadata_uuid = 1; break; -#ifdef EXPERIMENTAL +#if EXPERIMENTAL case GETOPT_VAL_CSUM: ctree_flags |= OPEN_CTREE_SKIP_CSUM_CHECK; csum_type = parse_csum_type(optarg); diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index 4f34645c..a5886ff6 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -1218,7 +1218,9 @@ static void print_header_info(struct extent_buffer *eb, unsigned int mode) { struct btrfs_fs_info *fs_info = eb->fs_info; char flags_str[128]; +#if EXPERIMENTAL u8 csum[BTRFS_CSUM_SIZE]; +#endif u64 flags; u32 nr; u8 backref_rev; @@ -1265,7 +1267,7 @@ static void print_header_info(struct extent_buffer *eb, unsigned int mode) btrfs_header_bytenr(eb), flags, flags_str, backref_rev, csum_str); -#ifdef EXPERIMENTAL +#if EXPERIMENTAL printf("checksum stored "); for (i = 0; i < csum_size; i++) printf("%02hhx", (int)(eb->data[i]));