From patchwork Tue Oct 11 02:44:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9370079 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 D7BFF60865 for ; Tue, 11 Oct 2016 02:45:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1ADE28D64 for ; Tue, 11 Oct 2016 02:45:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6B7029A6D; Tue, 11 Oct 2016 02:45:12 +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 6DFEA29A68 for ; Tue, 11 Oct 2016 02:45:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753237AbcJKCpG (ORCPT ); Mon, 10 Oct 2016 22:45:06 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:3846 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753085AbcJKCpF (ORCPT ); Mon, 10 Oct 2016 22:45:05 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="890199" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 11 Oct 2016 10:44:53 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 134384243524; Tue, 11 Oct 2016 10:44:53 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v2 2/4] btrfs-progs: Make btrfs-debug-tree print all readable strings for inode flags Date: Tue, 11 Oct 2016 10:44:44 +0800 Message-Id: <20161011024446.16546-3-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161011024446.16546-1-quwenruo@cn.fujitsu.com> References: <20161011024446.16546-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 134384243524.A9BC3 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 Before this patch, only 3 inode flags have readable string: NODATACOW, NODATASUM, READONLY. This patch will output all readable strings for remaining inode flags, making debug-tree tool more handy. Signed-off-by: Qu Wenruo --- print-tree.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/print-tree.c b/print-tree.c index 4444a14..990cdba 100644 --- a/print-tree.c +++ b/print-tree.c @@ -851,29 +851,36 @@ static void print_uuid_item(struct extent_buffer *l, unsigned long offset, } } -/* Caller should ensure sizeof(*ret) >= 29 "NODATASUM|NODATACOW|READONLY" */ +/* Btrfs inode flag stringification helper */ +#define CAT_ONE_INODE_FLAG(flags, name, empty, dst) ({ \ + if (flags & BTRFS_INODE_##name) { \ + if (!empty) \ + strcat(dst, "|"); \ + strcat(dst, #name); \ + empty = 0; \ + } \ +}) + +/* + * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of + * BTRFS_INODE_* flags + */ static void inode_flags_to_str(u64 flags, char *ret) { int empty = 1; - if (flags & BTRFS_INODE_NODATASUM) { - empty = 0; - strcpy(ret, "NODATASUM"); - } - if (flags & BTRFS_INODE_NODATACOW) { - if (!empty) { - empty = 0; - strcat(ret, "|"); - } - strcat(ret, "NODATACOW"); - } - if (flags & BTRFS_INODE_READONLY) { - if (!empty) { - empty = 0; - strcat(ret, "|"); - } - strcat(ret, "READONLY"); - } + CAT_ONE_INODE_FLAG(flags, NODATASUM, empty, ret); + CAT_ONE_INODE_FLAG(flags, NODATACOW, empty, ret); + CAT_ONE_INODE_FLAG(flags, READONLY, empty, ret); + CAT_ONE_INODE_FLAG(flags, NOCOMPRESS, empty, ret); + CAT_ONE_INODE_FLAG(flags, PREALLOC, empty, ret); + CAT_ONE_INODE_FLAG(flags, SYNC, empty, ret); + CAT_ONE_INODE_FLAG(flags, IMMUTABLE, empty, ret); + CAT_ONE_INODE_FLAG(flags, APPEND, empty, ret); + CAT_ONE_INODE_FLAG(flags, NODUMP, empty, ret); + CAT_ONE_INODE_FLAG(flags, NOATIME, empty, ret); + CAT_ONE_INODE_FLAG(flags, DIRSYNC, empty, ret); + CAT_ONE_INODE_FLAG(flags, COMPRESS, empty, ret); if (empty) strcat(ret, "none"); } @@ -902,7 +909,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l) u32 nr = btrfs_header_nritems(l); u64 objectid; u32 type; - char flags_str[32]; + char flags_str[128]; printf("leaf %llu items %d free space %d generation %llu owner %llu\n", (unsigned long long)btrfs_header_bytenr(l), nr,