From patchwork Mon May 8 07:38:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9715867 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DAFC060364 for ; Mon, 8 May 2017 07:38:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C07E826490 for ; Mon, 8 May 2017 07:38:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1C0E27C0B; Mon, 8 May 2017 07:38:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0200926490 for ; Mon, 8 May 2017 07:38:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752808AbdEHHiP (ORCPT ); Mon, 8 May 2017 03:38:15 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:34403 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751982AbdEHHiP (ORCPT ); Mon, 8 May 2017 03:38:15 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18585723" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 08 May 2017 15:38:13 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id B606147E6349; Mon, 8 May 2017 15:38:12 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 8 May 2017 15:38:13 +0800 From: Qu Wenruo To: , Subject: [PATCH] btrfs-progs: print-tree: Add leaf flags and backref revision output Date: Mon, 8 May 2017 15:38:10 +0800 Message-ID: <20170508073810.2811-1-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.12.2 MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: B606147E6349.ACCD3 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Btrfs header has a u64 member flags, whose lowest 56 bits are for header flags like WRITTEN and RELOC. And its highest 8 bits are for backref revision. Manually checking btrfs_header_flags() will be a pain, so add such leaf flags and backref revision output for print-tree. Signed-off-by: Qu Wenruo --- print-tree.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/print-tree.c b/print-tree.c index 5af80e87..823b87c1 100644 --- a/print-tree.c +++ b/print-tree.c @@ -938,13 +938,35 @@ static void print_dev_stats(struct extent_buffer *eb, } } +/* Caller must ensure sizeof(*ret) >= 14 "WRITTEN|RELOC" */ +static void header_flags_to_str(u64 flags, char *ret) +{ + int empty = 1; + + if (flags & BTRFS_HEADER_FLAG_WRITTEN) { + empty = 0; + strcpy(ret, "WRITTEN"); + } + if (flags & BTRFS_HEADER_FLAG_RELOC) { + if (!empty) + strcat(ret, "|"); + strcat(ret, "RELOC"); + } +} + void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb) { struct btrfs_item *item; struct btrfs_disk_key disk_key; + char flags_str[128]; u32 i; u32 nr; + u64 flags; + u8 backref_rev; + flags = btrfs_header_flags(eb) & ~BTRFS_BACKREF_REV_MASK; + backref_rev = btrfs_header_flags(eb) >> BTRFS_BACKREF_REV_SHIFT; + header_flags_to_str(flags, flags_str); nr = btrfs_header_nritems(eb); printf("leaf %llu items %d free space %d generation %llu owner %llu\n", @@ -952,6 +974,8 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb) btrfs_leaf_free_space(root, eb), (unsigned long long)btrfs_header_generation(eb), (unsigned long long)btrfs_header_owner(eb)); + printf("leaf %llu flags 0x%llx(%s) backref revision %d\n", + btrfs_header_bytenr(eb), flags, flags_str, backref_rev); print_uuids(eb); fflush(stdout);