From patchwork Fri Jan 26 08:35:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 10185287 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 8214D60383 for ; Fri, 26 Jan 2018 08:31:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70AE7290EB for ; Fri, 26 Jan 2018 08:31:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65BBE290F6; Fri, 26 Jan 2018 08:31:04 +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 0E9F5290EB for ; Fri, 26 Jan 2018 08:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752466AbeAZIbC (ORCPT ); Fri, 26 Jan 2018 03:31:02 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:2977 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752203AbeAZIbA (ORCPT ); Fri, 26 Jan 2018 03:31:00 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="36018072" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Jan 2018 16:30:53 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 30B4E49F19B8 for ; Fri, 26 Jan 2018 16:30:52 +0800 (CST) Received: from archlinux.g08.fujitsu.local (10.167.226.31) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 26 Jan 2018 16:30:51 +0800 From: Su Yue To: CC: Subject: [PATCH 13/15] btrfs-progs: check: find inode filetype in create_inode_item() Date: Fri, 26 Jan 2018 16:35:17 +0800 Message-ID: <20180126083519.28373-14-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180126083519.28373-1-suy.fnst@cn.fujitsu.com> References: <20180126083519.28373-1-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.31] X-yoursite-MailScanner-ID: 30B4E49F19B8.AB7B9 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: suy.fnst@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 Now, find_file_type() doesn't return 0 if mismatched filetype is in a backref. Let create_inode_item() first call find_file_type() to get filetype. If it failed, then guess filetype. Signed-off-by: Su Yue Reviewed-by: Qu Wenruo --- cmds-check.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index a83f0a92f48b..6091c7ef3442 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -3140,6 +3140,8 @@ static int create_inode_item_lowmem(struct btrfs_trans_handle *trans, return __create_inode_item(trans, root, ino, 0, 0, 0, mode); } +static u32 btrfs_type_to_imode(u8 type); +static int find_file_type(struct inode_record *rec, u8 *type); static int create_inode_item(struct btrfs_root *root, struct inode_record *rec, int root_dir) { @@ -3148,14 +3150,19 @@ static int create_inode_item(struct btrfs_root *root, u32 mode = 0; u64 size = 0; int ret; + u8 type = 0; - trans = btrfs_start_transaction(root, 1); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - return ret; + nlink = root_dir ? 1 : rec->found_link; + ret = find_file_type(rec, &type); + if (!ret) { + mode = btrfs_type_to_imode(type) | 0755; + if (type == BTRFS_FT_REG_FILE) + size = rec->found_size; + else + size = rec->extent_end; + goto create_inode; } - nlink = root_dir ? 1 : rec->found_link; if (rec->found_dir_item) { if (rec->found_file_extent) fprintf(stderr, "root %llu inode %llu has both a dir " @@ -3167,7 +3174,14 @@ static int create_inode_item(struct btrfs_root *root, size = rec->found_size; } else if (!rec->found_dir_item) { size = rec->extent_end; - mode = S_IFREG | 0755; + mode = S_IFREG | 0755; + } + +create_inode: + trans = btrfs_start_transaction(root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + return ret; } ret = __create_inode_item(trans, root, rec->ino, size, rec->nbytes, @@ -3307,7 +3321,8 @@ static int find_file_type(struct inode_record *rec, u8 *type) } list_for_each_entry(backref, &rec->backrefs, list) { - if (backref->found_dir_index || backref->found_dir_item) { + if ((backref->found_dir_index || backref->found_dir_item) && + (!(backref->errors & REF_ERR_FILETYPE_UNMATCH))) { *type = backref->filetype; return 0; }