Subject: Re: bug#49335: v.8.32 - stat(1) | Symbolic link interpreted as hard link

From: Pádraig Brady <[email-masked]>
Date: Fri, 2 Jul 2021 17:51:47 +0100

tag 49335 notabug
close 49335
stop

On 02/07/2021 17:32, Ricky Tigg wrote:
> Hello, symbolic link counted as hard link. To reproduce:
> 
> $ touch t; ln -sr t l; stat -c '%i %h %n %F' t l
> 4172493 1 t regular empty file
> 4172494 1 l symbolic link
> 
> '%h' reports *1* despite no hard link is involved. Isn't rather *0*
> expected?

1 is expected for any standard file as the names of those files are (hard)linked to an associated inode.
I.e. a hardlink is not a type of file, rather a structure of the file system.
One would only expect 0 for names unlinked from the file system,
which you could demonstrate like:

   f=file.to.delete; touch "$f" && (rm "$f" && stat -L -c '%h' /dev/stdin) < "$f"

The following gives an overview of the various types of links:
https://www.pixelbeat.org/docs/unix_links.html

cheers,
Pádraig