Re: Link count for directories

Nikolay Borisov
2020-08-25T12:38:10Z

On 25.08.20 г. 15:24 ч., Urs Thuermann wrote:
> 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.

It's slightly more complicated on btrfs because subvolumes and snapshots
are also directories from the POV of the user but are created in
different code paths. But that's the general idea.

>
> urs
>