From 00ca9a296df116f9d346fd39ff86fd439edf1992 Mon Sep 17 00:00:00 2001 From: David Gilligan-Cook Date: Wed, 8 May 2024 15:54:35 -0700 Subject: [PATCH 1/2] Implements nlink counting for directories Signed-off-by: David Gilligan-Cook --- crates/spfs-vfs/src/fuse.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/spfs-vfs/src/fuse.rs b/crates/spfs-vfs/src/fuse.rs index f76d11e57..bc0fde969 100644 --- a/crates/spfs-vfs/src/fuse.rs +++ b/crates/spfs-vfs/src/fuse.rs @@ -169,6 +169,15 @@ impl Filesystem { } else { entry.size }; + let nlink: u32 = if entry.is_dir() { + // Directory has 2 hardlinks for . and .. plus one for + // each subdirectory. Symlinks do not count. + (entry.entries.iter().filter(|(_n, e)| e.is_dir()).count() + 2) as u32 + } else { + // Everything else just has itself + 1 + }; + FileAttr { ino: entry.user_data, size, @@ -183,9 +192,7 @@ impl Filesystem { ctime: self.fs_creation_time, crtime: self.fs_creation_time, kind, - // TODO: possibly return directory link count - // for all dirs below it (because of .. entries) - nlink: if entry.is_dir() { 2 } else { 1 }, + nlink, rdev: 0, blksize: Self::BLOCK_SIZE, flags: 0, From 687a6e5776621d23bba73b6acafbe0790925c62f Mon Sep 17 00:00:00 2001 From: David Gilligan-Cook Date: Fri, 10 May 2024 09:47:21 -0700 Subject: [PATCH 2/2] Clarified a comment Signed-off-by: David Gilligan-Cook --- crates/spfs-vfs/src/fuse.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/spfs-vfs/src/fuse.rs b/crates/spfs-vfs/src/fuse.rs index bc0fde969..b15daf455 100644 --- a/crates/spfs-vfs/src/fuse.rs +++ b/crates/spfs-vfs/src/fuse.rs @@ -170,8 +170,9 @@ impl Filesystem { entry.size }; let nlink: u32 = if entry.is_dir() { - // Directory has 2 hardlinks for . and .. plus one for - // each subdirectory. Symlinks do not count. + // Directory has 2 hardlinks, one for . and one for the + // entry in its parent (..), plus one for each + // subdirectory. Symlinks do not count. (entry.entries.iter().filter(|(_n, e)| e.is_dir()).count() + 2) as u32 } else { // Everything else just has itself