Re: Link count for directories

Urs Thuermann
2020-08-25T12:29:50Z

Adam Borowski <kilobyte@angband.pl> writes:

> It's just an implementation detail of sysvfs, and a case of
> bug-compatibility. The link count of a directory is always 1 as btrfs,
> ext4, xfs, etc -- none of them support directory hardlinks, unlike sysvfs.

No, allmost all other file systems handle the directory link count in
the traditional way, at least minix, ext2, ext3, ext4, xfs, tmpfs,
devtmpfs, devpts, sysfs, cgroup on Linux do so. And also FreeBSD ufs
and devfs, NetBSD ffs, tmpfs, and kernfs, and OpenBSD ffs and mfs do
that also.

I'd like to check how zfs handles this (on Linux, FreeBSD or Solaris),
but currently have no access to a system using it.

> So the proper value, as documented, is 1. Copying sysvfs behaviour is also
> costly as you need to know the count of contents while statting parent.

No, it's not that costly. Directories start with nlink = 2 and nlinks
is incremented or decremented with each mkdir or rmdir system call.

urs