Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1040902rdb; Wed, 6 Dec 2023 07:10:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRxYJn1ef4pUPDjJmzZujYnkjAMkN8MqNsX1NWy7T2qEvwVp2e6ArwBV0epYLduVaslFai X-Received: by 2002:a17:90b:3146:b0:286:8b03:62ca with SMTP id ip6-20020a17090b314600b002868b0362camr868152pjb.43.1701875406242; Wed, 06 Dec 2023 07:10:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701875406; cv=none; d=google.com; s=arc-20160816; b=K52LzG30gxX5fX2T8vqAd2YNTWlRui/zd5vCsDbhi6vyZc+E5Ad2HBcbWc5KlRdYWr B4vkgMWduiEnZP0TNdrdWCaRp2rMFI4GuRAqIHPGTQKONtMiPAA7PzrSZOS8MLKfxM63 cGMfPsW3Aa/4D0iYkiksE6Sb+crP8ruIxmDUwAI1Yq3i7KHP2fZcF/WgZPTHoDjkEbkX XfJZPeIwtSvc5OpdMgxhMr4o63I9Y2oVb7Vd50jxPWncZFf+r2BpxMMsiKWCEj44gqTZ baBausmoWl+5C0xg096gSExc1wlxoZo4Zo4Agf6dj5miYxYZXbg8o0JJ82+/n7lmbM7n 63+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=Ifmg2OmIcc1e099M3eAc7+M0D09LHndtu4YB0fZ10AE=; fh=P7I85FIabZcM8ojWdeG8ABpTZepe/Xtte9jKWDfUHBM=; b=kG7Gy/Tr3JAxZ4xy25G3JiXpvNKbZLDSOJbdOxSSt77IwE13apLWwO2EzhrVRGnxqr eSYuzeekRJg/daa+h13kX8VYUscnp6d8v/lEOTGsyi7n9swCiqsDJNo5d33JpA0qmOn5 3/DzGjW+FmPnvLJuc7CSN9pur/YOrJI0I0RyJ+p1zS/BYiPPrvaa6CBls9FDIirTKKPq 9TOtjBLcrTYSrS4DC7jvx+n2V86ulPsBcBCHydYxEU14IkKDpvbyoKD3jxS00Vv0cB7i tYj0vI8bFp2uqUeKDcUJTr1fYeRWV591kJ5UqxZpSr2NIJOOB2sqOniTtv759t5vQASh hFVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=CM28fQWf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id o15-20020a17090a678f00b0028675b3e8a1si472366pjj.75.2023.12.06.07.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 07:10:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=CM28fQWf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id A08048030E7D; Wed, 6 Dec 2023 07:09:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442414AbjLFPJm (ORCPT + 99 others); Wed, 6 Dec 2023 10:09:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442406AbjLFPJl (ORCPT ); Wed, 6 Dec 2023 10:09:41 -0500 X-Greylist: delayed 99 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 06 Dec 2023 07:09:48 PST Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02ADDC6; Wed, 6 Dec 2023 07:09:47 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 75DD71E1A; Wed, 6 Dec 2023 15:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875001; bh=Ifmg2OmIcc1e099M3eAc7+M0D09LHndtu4YB0fZ10AE=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=CM28fQWfl2jtqKv/4Q00K5fqN1XehGPo+klnsLEdY+l3HE67RQZYkzBqf6GrkQUfr djhTyaAxCW/vH267eQpmpDRK6Px0x/CmTqlYadmRB8vyT2X9uyiv7/Ivcky6dxEE49 O+rzp55tAH/NRfKemZdi/99Qye5kO0nISMZtbgX8= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:09:45 +0300 Message-ID: Date: Wed, 6 Dec 2023 18:09:45 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 02/16] fs/ntfs3: Modified fix directory element type detection Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 07:09:58 -0800 (PST) Unfortunately reparse attribute is used for many purposes (several dozens). It is not possible here to know is this name symlink or not. To get exactly the type of name we should to open inode (read mft). getattr for opened file (fstat) correctly returns symlink. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/dir.c | 30 +++++++++++++++++++++++++-----  1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c index ec0566b322d5..22ede4da0450 100644 --- a/fs/ntfs3/dir.c +++ b/fs/ntfs3/dir.c @@ -309,11 +309,31 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,          return 0;      } -    /* NTFS: symlinks are "dir + reparse" or "file + reparse" */ -    if (fname->dup.fa & FILE_ATTRIBUTE_REPARSE_POINT) -        dt_type = DT_LNK; -    else -        dt_type = (fname->dup.fa & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG; +    /* +     * NTFS: symlinks are "dir + reparse" or "file + reparse" +     * Unfortunately reparse attribute is used for many purposes (several dozens). +     * It is not possible here to know is this name symlink or not. +     * To get exactly the type of name we should to open inode (read mft). +     * getattr for opened file (fstat) correctly returns symlink. +     */ +    dt_type = (fname->dup.fa & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG; + +    /* +     * It is not reliable to detect the type of name using duplicated information +     * stored in parent directory. +     * The only correct way to get the type of name - read MFT record and find ATTR_STD. +     * The code below is not good idea. +     * It does additional locks/reads just to get the type of name. +     * Should we use additional mount option to enable branch below? +     */ +    if ((fname->dup.fa & FILE_ATTRIBUTE_REPARSE_POINT) && +        ino != ni->mi.rno) { +        struct inode *inode = ntfs_iget5(sbi->sb, &e->ref, NULL); +        if (!IS_ERR_OR_NULL(inode)) { +            dt_type = fs_umode_to_dtype(inode->i_mode); +            iput(inode); +        } +    }      return !dir_emit(ctx, (s8 *)name, name_len, ino, dt_type);  } -- 2.34.1