From patchwork Mon Apr 1 05:55:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10879165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06C011708 for ; Mon, 1 Apr 2019 05:56:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5C96286D9 for ; Mon, 1 Apr 2019 05:56:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9162286DE; Mon, 1 Apr 2019 05:56:02 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 83781286D9 for ; Mon, 1 Apr 2019 05:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726865AbfDAF4B (ORCPT ); Mon, 1 Apr 2019 01:56:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:54340 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725860AbfDAF4B (ORCPT ); Mon, 1 Apr 2019 01:56:01 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 232F6ACBF; Mon, 1 Apr 2019 05:56:00 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: Thorsten Hirsch Subject: [PATCH v2 2/7] btrfs-progs: check/original: Add inode mode check Date: Mon, 1 Apr 2019 13:55:46 +0800 Message-Id: <20190401055551.6837-3-wqu@suse.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401055551.6837-1-wqu@suse.com> References: <20190401055551.6837-1-wqu@suse.com> MIME-Version: 1.0 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 Just like lowmem mode, check inode mode, specially for S_IFMT bits and beyond. Please note that, this check only applies to inodes in fs/subvol trees. It doesn't apply to free space cache inodes. Reported-by: Thorsten Hirsch Signed-off-by: Qu Wenruo --- check/main.c | 5 +++++ check/mode-original.h | 1 + 2 files changed, 6 insertions(+) diff --git a/check/main.c b/check/main.c index 7547209c5604..553c93caa2c9 100644 --- a/check/main.c +++ b/check/main.c @@ -616,6 +616,9 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec) fprintf(stderr, ", odd inode flags"); if (errors & I_ERR_INLINE_RAM_BYTES_WRONG) fprintf(stderr, ", invalid inline ram bytes"); + if (errors & I_ERR_INVALID_IMODE) + fprintf(stderr, ", invalid inode mode bit 0%o", + rec->imode & ~07777); fprintf(stderr, "\n"); /* Print the orphan extents if needed */ if (errors & I_ERR_FILE_EXTENT_ORPHAN) @@ -811,6 +814,8 @@ static void maybe_free_inode_rec(struct cache_tree *inode_cache, if (!rec->checked || rec->merging) return; + if (!is_valid_imode(rec->imode)) + rec->errors |= I_ERR_INVALID_IMODE; if (S_ISDIR(rec->imode)) { if (rec->found_size != rec->isize) rec->errors |= I_ERR_DIR_ISIZE_WRONG; diff --git a/check/mode-original.h b/check/mode-original.h index 25ca274118a7..e40a12930a6f 100644 --- a/check/mode-original.h +++ b/check/mode-original.h @@ -189,6 +189,7 @@ struct file_extent_hole { #define I_ERR_ODD_INODE_FLAGS (1 << 16) #define I_ERR_INLINE_RAM_BYTES_WRONG (1 << 17) #define I_ERR_MISMATCH_DIR_HASH (1 << 18) +#define I_ERR_INVALID_IMODE (1 << 19) struct inode_record { struct list_head backrefs;