Skip to content

Commit

Permalink
Bugfix: implements counting hardlinks for directories in spfs' fuse (#…
Browse files Browse the repository at this point in the history
…1021)

* Implements nlink counting for directories

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
  • Loading branch information
dcookspi authored May 15, 2024
1 parent 51ada8e commit 6c687b7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/spfs-vfs/src/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ impl Filesystem {
} else {
entry.size
};
let nlink: u32 = if entry.is_dir() {
// 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
1
};

FileAttr {
ino: entry.user_data,
size,
Expand All @@ -183,9 +193,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 6c687b7

Please sign in to comment.