From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED70D3EA95 for ; Wed, 6 Dec 2023 15:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="CM28fQWf" 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 Precedence: bulk X-Mailing-List: ntfs3@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) 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