fs/ntfs3: Fix directory element type detection
authorGabriel Marcano <gabemarcano@yahoo.com>
Wed, 13 Sep 2023 04:50:32 +0000 (21:50 -0700)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Thu, 28 Sep 2023 12:04:06 +0000 (15:04 +0300)
Calling stat() from userspace correctly identified junctions in an NTFS
partition as symlinks, but using readdir() and iterating through the
directory containing the same junction did not identify the junction
as a symlink.

When emitting directory contents, check FILE_ATTRIBUTE_REPARSE_POINT
attribute to detect junctions and report them as links.

Signed-off-by: Gabriel Marcano <gabemarcano@yahoo.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/dir.c

index 063a665..ec0566b 100644 (file)
@@ -309,7 +309,11 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
                return 0;
        }
 
-       dt_type = (fname->dup.fa & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
+       /* 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;
 
        return !dir_emit(ctx, (s8 *)name, name_len, ino, dt_type);
 }