public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH 0/1] fs/ntfs3: fix directory element type detection
       [not found] <20230913045032.19651-1-gabemarcano.ref@yahoo.com>
@ 2023-09-13  4:50 ` Gabriel Marcano
  2023-09-13  4:50   ` [PATCH 1/1] " Gabriel Marcano
  0 siblings, 1 reply; 2+ messages in thread
From: Gabriel Marcano @ 2023-09-13  4:50 UTC (permalink / raw)
  To: Konstantin Komarov; +Cc: ntfs3, linux-kernel, Gabriel Marcano

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
-- 
2.42.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] fs/ntfs3: fix directory element type detection
  2023-09-13  4:50 ` [PATCH 0/1] fs/ntfs3: fix directory element type detection Gabriel Marcano
@ 2023-09-13  4:50   ` Gabriel Marcano
  0 siblings, 0 replies; 2+ messages in thread
From: Gabriel Marcano @ 2023-09-13  4:50 UTC (permalink / raw)
  To: Konstantin Komarov; +Cc: ntfs3, linux-kernel, Gabriel Marcano

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>
---
 fs/ntfs3/dir.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c
index 063a6654199b..ec0566b322d5 100644
--- a/fs/ntfs3/dir.c
+++ b/fs/ntfs3/dir.c
@@ -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);
 }
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-13  4:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20230913045032.19651-1-gabemarcano.ref@yahoo.com>
2023-09-13  4:50 ` [PATCH 0/1] fs/ntfs3: fix directory element type detection Gabriel Marcano
2023-09-13  4:50   ` [PATCH 1/1] " Gabriel Marcano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox