fs/ntfs3: fix directory element type detection
A message that is not in the archive (sent off-list or not yet received): [email protected]
cover fs/ntfs3: fix directory element type detection
I ran into an interesting issue with plocate's updatedb when it was iterating through a Windows NTFS partition. Specifically, it turns out that in at least Windows 10, the directory (from Windows's POV):
C:\Documents and Settings\Default User\Application Data
has a junction to itself. updatedb (in Linux) was segfaulting from what looked to be a stack overflow due to what looked to be infinite traversal of that junction loop. The cause is that while stat() (and associated syscalls) correctly identify the junction as a symlink, readdir() (and associated syscalls) did not, reporting that it was a regular directory instead. I tried a similar setup in my root btrfs partition, and both stat() and readdir() reported the symlinks there as links, so it does look like an issue in ntfs3, or at least it's not consistent with other filesystems.
This patch checks to see if the FILE_ATTRIBUTE_REPARSE_POINT attrinbute is set, and if so, it sets the type of that file or directory to a link while emitting data for getdents64 and related syscalls.
This patch does fix the updatedb issue I was encountering, as apparently updatedb stops traversing once it hits a symlink.
Gabriel Marcano (1):
fs/ntfs3: fix directory element type detection
fs/ntfs3/dir.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
base-commit: 44b4494d5c5971dc8f531c8783d90a637e862880
Signature · 1 line
2.42.0
PATCH 1/1 fs/ntfs3: fix directory element type detection
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.
--- fs/ntfs3/dir.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ntfs3/dir.c +5 -1
@@ -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); }
Signature · 1 line
2.42.0