fix(mount): add -posixDirNlink option for correct directory nlink

Add optional POSIX-compliant directory nlink counting
(nlink = 2 + number_of_subdirectories) behind the -posixDirNlink
flag. This requires listing cached directory entries on every stat,
which has a performance cost, so it's off by default.

When disabled (default), directories report nlink=2, which is the
POSIX-compliant baseline for empty directories and a common default
in distributed filesystems.

- Set nlink baseline to 2 for all directories (was 1)
- Add applyDirNlink() gated behind option.PosixDirNlink
- Add -posixDirNlink CLI flag
This commit is contained in:
Chris Lu committed 2026-04-10 14:08:04 -07:00
1 parent cd82a9cb4b
commit 178532e63a
5 files changed
+44 -4

No files matched your search

+1
View File
@@ -354,6 +354,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
DirIdleEvictSec: *option.dirIdleEvictSec,
EnableDistributedLock: option.distributedLock != nil && *option.distributedLock,
WritebackCache: option.writebackCache != nil && *option.writebackCache,
PosixDirNlink: option.posixDirNlink != nil && *option.posixDirNlink,
})
// create mount root