Skip to content

Commit

Permalink
Implements nlink counting for directories
Browse files Browse the repository at this point in the history
Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
  • Loading branch information
dcookspi committed May 8, 2024
1 parent 51ada8e commit 00ca9a2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/spfs-vfs/src/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 00ca9a2

Please sign in to comment.