From patchwork Wed Sep 24 05:31:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 4961781 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7A4B8BEEA5 for ; Wed, 24 Sep 2014 05:31:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A914720268 for ; Wed, 24 Sep 2014 05:31:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B41A420265 for ; Wed, 24 Sep 2014 05:31:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750817AbaIXFbo (ORCPT ); Wed, 24 Sep 2014 01:31:44 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:27675 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750783AbaIXFbn (ORCPT ); Wed, 24 Sep 2014 01:31:43 -0400 X-IronPort-AV: E=Sophos;i="5.04,586,1406563200"; d="scan'208";a="36376106" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Sep 2014 13:28:41 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s8O5VkZK003128 for ; Wed, 24 Sep 2014 13:31:46 +0800 Received: from adam-work.lan (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 24 Sep 2014 13:31:45 +0800 From: Qu Wenruo To: Subject: [PATCH v2] btrfs-progs: Add human readable incompat flags output for btrfs-show-super Date: Wed, 24 Sep 2014 13:31:39 +0800 Message-ID: <1411536699-32520-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add human readable incompat flags output for btrfs-show-super, now no longer needs to calculate the hex flags by hand. Signed-off-by: Qu Wenruo --- changelog: v2: Add the mising "0x" before hex unknown incompat flags --- btrfs-show-super.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/btrfs-show-super.c b/btrfs-show-super.c index 38c5d26..456dbd8 100644 --- a/btrfs-show-super.c +++ b/btrfs-show-super.c @@ -285,6 +285,58 @@ static void print_backup_roots(struct btrfs_super_block *sb) } } +struct readable_flag_entry { + u64 bit; + char *output; +}; + +#define DEF_INCOMPAT_FLAG_ENTRY(bit_name) \ + {BTRFS_FEATURE_INCOMPAT_##bit_name, #bit_name} + +struct readable_flag_entry incompat_flags_array[] = { + DEF_INCOMPAT_FLAG_ENTRY(MIXED_BACKREF), + DEF_INCOMPAT_FLAG_ENTRY(DEFAULT_SUBVOL), + DEF_INCOMPAT_FLAG_ENTRY(MIXED_GROUPS), + DEF_INCOMPAT_FLAG_ENTRY(COMPRESS_LZO), + DEF_INCOMPAT_FLAG_ENTRY(COMPRESS_LZOv2), + DEF_INCOMPAT_FLAG_ENTRY(BIG_METADATA), + DEF_INCOMPAT_FLAG_ENTRY(EXTENDED_IREF), + DEF_INCOMPAT_FLAG_ENTRY(RAID56), + DEF_INCOMPAT_FLAG_ENTRY(SKINNY_METADATA), + DEF_INCOMPAT_FLAG_ENTRY(NO_HOLES) +}; +static const int incompat_flags_num = sizeof(incompat_flags_array) / + sizeof(struct readable_flag_entry); + +static void print_readable_incompat_flag(u64 flag) +{ + int i; + int first = 1; + struct readable_flag_entry *entry; + + if (!flag) + return; + printf("\t\t\t( "); + for (i = 0; i < incompat_flags_num; i++) { + entry = incompat_flags_array + i; + if (flag & entry->bit) { + if (first) + printf("%s ", entry->output); + else + printf("|\n\t\t\t %s ", entry->output); + } + first = 0; + } + flag &= ~BTRFS_FEATURE_INCOMPAT_SUPP; + if (flag) { + if (first) + printf("unknown flag: 0x%llx ", flag); + else + printf("|\n\t\t\t unknown flag: 0x%llx ", flag); + } + printf(")\n"); +} + static void dump_superblock(struct btrfs_super_block *sb, int full) { int i; @@ -364,6 +416,7 @@ static void dump_superblock(struct btrfs_super_block *sb, int full) (unsigned long long)btrfs_super_compat_ro_flags(sb)); printf("incompat_flags\t\t0x%llx\n", (unsigned long long)btrfs_super_incompat_flags(sb)); + print_readable_incompat_flag(btrfs_super_incompat_flags(sb)); printf("csum_type\t\t%llu\n", (unsigned long long)btrfs_super_csum_type(sb)); printf("csum_size\t\t%llu\n",