From patchwork Wed Dec 6 15:09:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 174622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4168749vqy; Wed, 6 Dec 2023 07:10:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7Ee76Zc6bvCVdMb+mb7UkBL+P5EyWQk6fEjW9VIoGl5B/5ZFg+t9eGZ0FhH1fjCweK9dg X-Received: by 2002:a05:6a20:c19e:b0:18f:97c:8254 with SMTP id bg30-20020a056a20c19e00b0018f097c8254mr1090039pzb.94.1701875400586; Wed, 06 Dec 2023 07:10:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701875400; cv=none; d=google.com; s=arc-20160816; b=bIAXZPEBHq4YC/aaqwRMBpxuE0UpJeBZMFRzuuUuJxA6unlgixvKPCPZyj6KfV8n9I JZIsih0JxmSSS4uDo4VSI27jHGbnrKqaFmJQvZ8feeJzOgFgrRk64kFe5En1aIOXlm3l M+VtyuOzBJiNndohbsQNyBztT1J5cYv7R8nN4ES2AD82zXroRkSr0wKL2mQvt/22iMPv bPqmiqBC9/U4ArOpSIBwEnTuH/c6rodKyPyhxOeUow/7MvRprryImJpBedGSwLpp9JhM PI7BEaM8013e2wKXTcAiiQfGrVbk34IkmSSYmweBYURJVm4MlUhP68AHxMIU6GZ4wdGi ORiw== 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 Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id h36-20020a63f924000000b005be1955657esi49418pgi.127.2023.12.06.07.09.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 07:10:00 -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 74C208030E7E; Wed, 6 Dec 2023 07:09:51 -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> 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:51 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784545699663998634 X-GMAIL-MSGID: 1784545699663998634 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(-) +        } +    }      return !dir_emit(ctx, (s8 *)name, name_len, ino, dt_type);  } 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);